| Conditions | 6 |
| Total Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | from functools import wraps |
||
| 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 |