Preparation for APIfication

This commit is contained in:
Kumi 2020-06-03 18:23:00 +02:00
parent 5faa1e403a
commit 55d1a4e79f
3 changed files with 39 additions and 12 deletions

View file

@ -1,9 +1,10 @@
from core.models.files import *
from core.models.profiles import *
from core.models.auth import *
from core.models.local import *
from core.models.cron import *
from core.models.products import *
from core.models.billable import *
from core.models.services import *
from core.models.invoices import *
from core.models.files import BaseFile, ImageField, File, FileAssociation
from core.models.profiles import ClientGroup, Profile, ClientProfile, AdminProfile
from core.models.auth import LoginSession, PWResetToken, LoginLog, IPLimit
from core.models.local import Currency, TaxPolicy, TaxRule
from core.models.cron import CronLog
from core.models.products import ProductGroup, Product, ProductPlan, ProductPlanItem
from core.models.billable import CycleChoices, Billable
from core.models.services import Service, ServicePlan, ServicePlanItem
from core.models.invoices import Invoice, InvoiceItem
from core.models.api import APIKey

21
core/models/api.py Normal file
View file

@ -0,0 +1,21 @@
from django.db.models import Model, UUIDField, ForeignKey, CASCADE, TextField
from core.models.profiles import AdminProfile
import uuid
class APIKey(Model):
key = UUIDField(default=uuid.uuid4)
admin = ForeignKey(AdminProfile, on_delete=CASCADE)
permission_string = TextField(blank=True, default=[])
@property
def permissions(self):
return self.permission_string.split(",")
@permissions.setter
def permissions(self, permissions):
if isinstance(permissions, str):
self.permission_string = permissions
else:
self.permission_string = ",".join(permissions)

View file

@ -4,11 +4,16 @@ from django.conf import settings
from django.urls import path
URLPATTERNS = []
APIPATTERNS = []
for module in settings.EXPEPHALON_MODULES:
try:
mou = importlib.import_module(f"{module}.urls")
for url, action, name in mou.ADMIN_URLS:
URLPATTERNS.append(path(f'admin/modules/{module}/{url}', action, name=f"{module}_{name}"))
except (AttributeError, ModuleNotFoundError):
if "ADMIN_URLS" in mou.__dict__.keys():
for url, action, name in mou.ADMIN_URLS:
URLPATTERNS.append(path(f'admin/modules/{module}/{url}', action, name=f"{module}_{name}"))
if "API_URLS" in mou.__dict__.keys():
for url, action, name in mou.API_URLS:
URLPATTERNS.append(path(f"api/modules/{module}/{url}", action, name=f"api_{module}_{name}"))
except ModuleNotFoundError:
pass