Skip to content

Commit

Permalink
admin: announcement: make supervisor read-only
Browse files Browse the repository at this point in the history
club execs were getting confused / errors when setting supervisor (not
necessary) when making announcements.
  • Loading branch information
nyiyui committed Sep 27, 2023
1 parent 7a4f5a1 commit 266b365
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def get_readonly_fields(self, request, obj=None):
return ["owner", "supervisors", "execs", "is_active"]

def formfield_for_manytomany(self, db_field, request, **kwargs):
if db_field.name == "supervisors":
if db_field.name == "supervisors" and not request.user.is_superuser:
kwargs["queryset"] = models.User.objects.filter(is_teacher=True).order_by(
"username"
)
Expand Down Expand Up @@ -243,8 +243,8 @@ def get_readonly_fields(self, request, obj=None):
fields = set(all_fields)
fields_matrix = [
[
{"author", "organization", "title", "tags", "is_public"},
{"author", "organization", "title", "tags", "is_public"},
{"author", "organization", "title", "tags", "is_public", "supervisor"},
{"author", "organization", "title", "tags", "is_public", "supervisor"},
{
"author",
"organization",
Expand All @@ -269,8 +269,8 @@ def get_readonly_fields(self, request, obj=None):
},
],
[
{"author", "organization"},
{"author", "organization", "status"},
{"author", "organization", "supervisor"},
{"author", "organization", "status", "supervisor"},
{"author", "organization", "status", "show_after", "supervisor"},
{"author", "organization", "status", "supervisor", "rejection_reason"},
],
Expand Down Expand Up @@ -354,7 +354,7 @@ def formfield_for_foreignkey(self, db_field, request, **kwargs):
.distinct()
.order_by("name")
)
elif db_field.name in {"author", "supervisor"}:
elif db_field.name in {"author", "supervisor"} and not request.user.is_superuser:
orgs = models.Organization.objects.filter(
Q(supervisors=request.user) | Q(execs=request.user)
)
Expand Down

0 comments on commit 266b365

Please sign in to comment.