Skip to content

Commit

Permalink
Merge branch 'staging' into dave/speculate-ludic
Browse files Browse the repository at this point in the history
  • Loading branch information
davepeck committed May 10, 2024
2 parents c6d7fba + a034b32 commit d88ec46
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
49 changes: 49 additions & 0 deletions server/vb/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,52 @@ def queryset(self, request, queryset):
return queryset


class InlineContestEntryAdmin(admin.TabularInline):
"""Inline contest entry admin."""

model = ContestEntry
extra = 0

# These should be READONLY
fields = (
"student",
"created_at_pacific",
"show_winnings_issued",
"amount_won",
"roll",
)
readonly_fields = (
"student",
"created_at_pacific",
"amount_won",
"show_winnings_issued",
"roll",
)
ordering = ("-amount_won", "creation_request_id")

def created_at_pacific(self, obj: ContestEntry) -> str:
"""Return the contest entry's creation time in the Pacific timezone."""
return obj.created_at.astimezone(PACIFIC).strftime("%B %d, %Y @ %I:%M %p")

@admin.display(description="Issued?")
def show_winnings_issued(self, obj: ContestEntry) -> str:
"""Return whether the contest entry's winnings have been issued."""
if obj.has_issued:
return "Yes"
elif obj.is_winner:
return "Not yet"
else:
return ""

def has_delete_permission(self, *args, **kwargs) -> bool:
"""No permission to delete."""
return False

def has_add_permission(self, *args, **kwargs) -> bool:
"""No permission to add."""
return False


class ContestAdmin(admin.ModelAdmin):
"""Contest admin."""

Expand All @@ -263,6 +309,8 @@ class ContestAdmin(admin.ModelAdmin):
)
search_fields = ("school__name", "school__short_name", "school__slug")
list_filter = (StatusListFilter, "school__name")
readonly_fields = ("status", "start_at_pacific", "end_at_pacific")
inlines = [InlineContestEntryAdmin]

@admin.display(description="Start At (Pacific)")
def start_at_pacific(self, obj: Contest) -> str:
Expand Down Expand Up @@ -356,6 +404,7 @@ class ContestEntryAdmin(admin.ModelAdmin):
ContestWinnerListFilter,
ContestWinningsIssuedListFilter,
"contest__school__name",
"contest",
)

@admin.display(description="Winner?", boolean=True)
Expand Down
4 changes: 4 additions & 0 deletions server/vb/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ def anonymized_name(self) -> str:
"""Return the student's anonymized name."""
return f"{self.first_name} {self.last_name[0]}."

def __str__(self) -> str:
"""Return myself as a string."""
return f"{self.name} <{self.email}>"


class EmailValidationLinkManager(models.Manager):
"""A custom manager for the email validation link model."""
Expand Down

0 comments on commit d88ec46

Please sign in to comment.