From 2c7366fdf6eb56819d653f2b112eb296bc735f84 Mon Sep 17 00:00:00 2001 From: hadleyking Date: Thu, 14 Mar 2024 11:57:36 -0400 Subject: [PATCH] Added files for Prefix model Changes to be committed: new file: prefix/__init__.py new file: prefix/admin.py new file: prefix/apis.py new file: prefix/apps.py new file: prefix/migrations/__init__.py new file: prefix/models.py new file: prefix/selectors.py new file: prefix/services.py new file: prefix/urls.py --- prefix/__init__.py | 0 prefix/admin.py | 7 +++++++ prefix/apis.py | 0 prefix/apps.py | 0 prefix/migrations/__init__.py | 0 prefix/models.py | 18 ++++++++++++++++++ prefix/selectors.py | 7 +++++++ prefix/services.py | 0 prefix/urls.py | 7 +++++++ 9 files changed, 39 insertions(+) create mode 100644 prefix/__init__.py create mode 100644 prefix/admin.py create mode 100644 prefix/apis.py create mode 100644 prefix/apps.py create mode 100644 prefix/migrations/__init__.py create mode 100644 prefix/models.py create mode 100644 prefix/selectors.py create mode 100644 prefix/services.py create mode 100644 prefix/urls.py diff --git a/prefix/__init__.py b/prefix/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prefix/admin.py b/prefix/admin.py new file mode 100644 index 00000000..14176112 --- /dev/null +++ b/prefix/admin.py @@ -0,0 +1,7 @@ +"""Prefix Admin Pannel +""" + +from django.contrib import admin +from prefix.models import Prefix + +admin.site.register(Prefix) \ No newline at end of file diff --git a/prefix/apis.py b/prefix/apis.py new file mode 100644 index 00000000..e69de29b diff --git a/prefix/apps.py b/prefix/apps.py new file mode 100644 index 00000000..e69de29b diff --git a/prefix/migrations/__init__.py b/prefix/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/prefix/models.py b/prefix/models.py new file mode 100644 index 00000000..c40dd5af --- /dev/null +++ b/prefix/models.py @@ -0,0 +1,18 @@ +from django.db import models +from django.contrib.auth.models import Group, User +from django.utils import timezone + +class Prefix(models.Model): + """ + """ + + prefix = models.CharField(primary_key=True, max_length=5) + certifying_key = models.TextField(blank=True, null=True) + created = models.DateTimeField(default=timezone.now, blank=True, null=True) + description = models.TextField(blank=True, null=True) + owner = models.ForeignKey(User, on_delete=models.CASCADE, to_field="username") + authorized_groups = models.ManyToManyField(Group, blank=True, related_name='authorized_prefix') + + def __str__(self): + """String for representing the BCO model (in Admin site etc.).""" + return f"{self.prefix}" \ No newline at end of file diff --git a/prefix/selectors.py b/prefix/selectors.py new file mode 100644 index 00000000..07c0d64c --- /dev/null +++ b/prefix/selectors.py @@ -0,0 +1,7 @@ + + +def is_accessible_by(self, user): + """If no authorized_groups are specified, it's accessible by everyone""" + if self.authorized_users.exists(): + return self.authorized_users.filter(id=user.id).exists() + return True \ No newline at end of file diff --git a/prefix/services.py b/prefix/services.py new file mode 100644 index 00000000..e69de29b diff --git a/prefix/urls.py b/prefix/urls.py new file mode 100644 index 00000000..14176112 --- /dev/null +++ b/prefix/urls.py @@ -0,0 +1,7 @@ +"""Prefix Admin Pannel +""" + +from django.contrib import admin +from prefix.models import Prefix + +admin.site.register(Prefix) \ No newline at end of file