Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
GitHub Actions committed Dec 2, 2023
1 parent ea491b8 commit c4ffea2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
32 changes: 15 additions & 17 deletions core/management/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
from core import models

GROUPS_PERMISSIONS = {
'Problem Setters': {
models.QrCode: ['add', 'change', 'delete'],
models.Hint: ['add', 'change', 'delete', 'view'],
models.LogicPuzzleHint: ['view'],
"Problem Setters": {
models.QrCode: ["add", "change", "delete"],
models.Hint: ["add", "change", "delete", "view"],
models.LogicPuzzleHint: ["view"],
},
'Logic Puzzle Setters': {
models.QrCode: ['view'],
models.Hint: ['view'],
models.LogicPuzzleHint: ['add', 'change', 'delete', 'view'],
"Logic Puzzle Setters": {
models.QrCode: ["view"],
models.Hint: ["view"],
models.LogicPuzzleHint: ["add", "change", "delete", "view"],
},
}


class Command(BaseCommand):
def __init__(self, *args, **kwargs):
super(Command, self).__init__(*args, **kwargs)
Expand All @@ -25,27 +26,24 @@ def __init__(self, *args, **kwargs):
def handle(self, *args, **options):
# Loop groups
for group_name in GROUPS_PERMISSIONS:

# Get or create group
group, created = Group.objects.get_or_create(name=group_name)

# Loop models in group
for model_cls in GROUPS_PERMISSIONS[group_name]:

# Loop permissions in group/model
for perm_index, perm_name in \
enumerate(GROUPS_PERMISSIONS[group_name][model_cls]):

for perm_index, perm_name in enumerate(
GROUPS_PERMISSIONS[group_name][model_cls]
):
# Generate permission name as Django would generate it
codename = perm_name + "_" + model_cls._meta.model_name

try:
# Find permission object and add to group
perm = Permission.objects.get(codename=codename)
group.permissions.add(perm)
self.stdout.write("Adding "
+ codename
+ " to group "
+ group.__str__())
self.stdout.write(
"Adding " + codename + " to group " + group.__str__()
)
except Permission.DoesNotExist:
self.stdout.write(codename + " not found")
7 changes: 6 additions & 1 deletion core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ class QrCode(models.Model):
help_text="Location of the QR code. Be specific—it's internal",
)
notes = models.TextField(help_text="Internal notes", blank=True)
key = models.CharField(max_length=64, unique=True, default=generate_hint_key, help_text="Key to access the hint, used in the QR code ")
key = models.CharField(
max_length=64,
unique=True,
default=generate_hint_key,
help_text="Key to access the hint, used in the QR code ",
)
image_url = models.URLField(
help_text="A URL to an image of where the QR code is located (try imgur)",
blank=True,
Expand Down

0 comments on commit c4ffea2

Please sign in to comment.