Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix various bugs related to marks #3211

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion apps/authentication/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,36 @@
Position,
SpecialPosition,
)
from apps.marks.models import MarkDelay, MarkUser, Suspended, Suspension, user_sanctions


class MarkUserInline(admin.TabularInline):
model = MarkUser
extra = 0
fields = ("mark",)
readonly_fields = ("mark",)

verbose_name = _("Prikk")
verbose_name_plural = _("Prikker")


class SuspensionInline(admin.TabularInline):
model = Suspension
extra = 0
show_change_link = True
fields = ("title", "created_time", "expiration_date")
readonly_fields = ("title", "created_time", "expiration_date")

verbose_name = _("Suspensjon")
verbose_name_plural = _("Suspensjoner")


class OnlineUserAdmin(UserAdmin, VersionAdmin):
model = OnlineUser
inlines = (
MarkUserInline,
SuspensionInline,
)
list_display = [
"username",
"first_name",
Expand Down Expand Up @@ -62,10 +88,32 @@
)
},
),
(
_("Sanksjoner"),
{
"fields": ("current_total_sanctions",),
},
),
)
filter_horizontal = ("groups", "user_permissions")
search_fields = ("first_name", "last_name", "username", "ntnu_username")
readonly_fields = ("mark_rules_accepted", "auth0_subject")
readonly_fields = (
"mark_rules_accepted",
"auth0_subject",
"current_total_sanctions",
)

def current_total_sanctions(self, instance: OnlineUser):
match user_sanctions(instance):
case Suspended():
return "Suspendert"
case MarkDelay(delay):
return _("Forsinket påmelding med %s") % delay
case None:
return "-"

Check warning on line 113 in apps/authentication/admin.py

View check run for this annotation

Codecov / codecov/patch

apps/authentication/admin.py#L107-L113

Added lines #L107 - L113 were not covered by tests

current_total_sanctions.str = True
current_total_sanctions.short_description = "Nåværende sanksjoner"

def is_member(self, instance: OnlineUser):
return instance.is_member
Expand All @@ -77,6 +125,13 @@

mark_rules_accepted.boolean = True

def get_queryset(self, *args, **kwargs):
return (

Check warning on line 129 in apps/authentication/admin.py

View check run for this annotation

Codecov / codecov/patch

apps/authentication/admin.py#L129

Added line #L129 was not covered by tests
super()
.get_queryset(*args, **kwargs)
.prefetch_related("marks", "suspension_set")
)


admin.site.register(OnlineUser, OnlineUserAdmin)

Expand Down
16 changes: 15 additions & 1 deletion apps/marks/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,21 @@ class MarkUserInline(admin.TabularInline):
@admin.register(Mark)
class MarkAdmin(VersionAdmin):
inlines = (MarkUserInline,)
list_display = ["__str__", "category", "added_date", "weight"]
fields = [
"title",
"added_date",
"cause",
"weight",
"description",
"expiration_date",
"ruleset",
]

list_display = ["__str__", "category", "cause", "added_date", "weight"]
readonly_fields = (
"expiration_date",
"ruleset",
)
search_fields = ("title",)

def save_model(self, request, obj, form, change):
Expand Down
Empty file removed apps/marks/dashboard/__init__.py
Empty file.
9 changes: 0 additions & 9 deletions apps/marks/dashboard/forms.py

This file was deleted.

11 changes: 0 additions & 11 deletions apps/marks/dashboard/urls.py

This file was deleted.

243 changes: 0 additions & 243 deletions apps/marks/dashboard/views.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

def migrate_mark_category(apps, schema_editor):
Mark = apps.get_model("marks", "Mark")
marks = Mark.objects.iterator(chunk_size=50)
marks = list(Mark.objects.iterator(chunk_size=50))
for m in marks:
for title, cause in [
("Manglende oppmøte", MarkClass.Cause.NO_ATTENDANCE),
Expand Down
Loading