mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-04 10:59:17 +02:00
See #170: fetch channel outbox on discovery/detail
This commit is contained in:
parent
0eeead34a4
commit
7435167361
11 changed files with 297 additions and 28 deletions
|
@ -37,16 +37,22 @@ class CeleryConfig(AppConfig):
|
|||
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS, force=True)
|
||||
|
||||
|
||||
def require_instance(model_or_qs, parameter_name, id_kwarg_name=None):
|
||||
def require_instance(model_or_qs, parameter_name, id_kwarg_name=None, allow_null=False):
|
||||
def decorator(function):
|
||||
@functools.wraps(function)
|
||||
def inner(*args, **kwargs):
|
||||
kw = id_kwarg_name or "_".join([parameter_name, "id"])
|
||||
pk = kwargs.pop(kw)
|
||||
try:
|
||||
instance = model_or_qs.get(pk=pk)
|
||||
except AttributeError:
|
||||
instance = model_or_qs.objects.get(pk=pk)
|
||||
pk = kwargs.pop(kw)
|
||||
except KeyError:
|
||||
if not allow_null:
|
||||
raise
|
||||
instance = None
|
||||
else:
|
||||
try:
|
||||
instance = model_or_qs.get(pk=pk)
|
||||
except AttributeError:
|
||||
instance = model_or_qs.objects.get(pk=pk)
|
||||
kwargs[parameter_name] = instance
|
||||
return function(*args, **kwargs)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue