Files
winget.pro/winget/util.py
T
Michael Herrmann 7c65fe26fa Add Installer#scope
2022-09-22 17:33:23 +02:00

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