mirror of
https://github.com/omaha-consulting/winget.pro.git
synced 2026-10-24 21:02:23 +00:00
42 lines
959 B
Python
42 lines
959 B
Python
import json
|
|
from functools import wraps
|
|
|
|
from django.db.models import CharField
|
|
from django.http import JsonResponse
|
|
from django.shortcuts import get_object_or_404
|
|
|
|
from tenants.models import Tenant
|
|
|
|
|
|
def CharFieldFromChoices(*choices, **kwargs):
|
|
return CharField(
|
|
choices=[(c, c) for c in choices], max_length=max(map(len, choices)),
|
|
**kwargs
|
|
)
|
|
|
|
|
|
def parse_jsonrequest(func):
|
|
@wraps(func)
|
|
def inner(request, *args, **kwargs):
|
|
data = json.loads(request.body)
|
|
return func(request, data, *args, **kwargs)
|
|
|
|
return inner
|
|
|
|
|
|
def load_tenant(func):
|
|
@wraps(func)
|
|
def inner(request, tenant_uuid, *args, **kwargs):
|
|
tenant = get_object_or_404(Tenant, uuid=tenant_uuid)
|
|
return func(request, tenant, *args, **kwargs)
|
|
|
|
return inner
|
|
|
|
|
|
def return_jsonresponse(func):
|
|
@wraps(func)
|
|
def inner(*args, **kwargs):
|
|
return JsonResponse({'Data': func(*args, **kwargs)})
|
|
|
|
return inner
|