stream()   B
last analyzed

Complexity

Conditions 6

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 6
c 2
b 0
f 0
dl 0
loc 27
rs 8.2986

1 Method

Rating   Name   Duplication   Size   Complexity  
A wrapped() 0 11 5
1
from functools import wraps
2
3
4
def stream(func):
5
    """
6
    Stream decorator to be applied to methods of an ``ActionManager`` subclass
7
8
    Syntax::
9
10
        from actstream.decorators import stream
11
        from actstream.managers import ActionManager
12
13
        class MyManager(ActionManager):
14
            @stream
15
            def foobar(self, ...):
16
                ...
17
18
    """
19
    @wraps(func)
20
    def wrapped(manager, *args, **kwargs):
21
        offset, limit = kwargs.pop('_offset', None), kwargs.pop('_limit', None)
22
        qs = func(manager, *args, **kwargs)
23
        if isinstance(qs, dict):
24
            qs = manager.public(**qs)
25
        elif isinstance(qs, (list, tuple)):
26
            qs = manager.public(*qs)
27
        if offset or limit:
28
            qs = qs[offset:limit]
29
        return qs.fetch_generic_relations()
30
    return wrapped
31