Skip to content

Commit

Permalink
Show current contest details only.
Browse files Browse the repository at this point in the history
  • Loading branch information
davepeck committed Apr 2, 2024
1 parent 6c07541 commit 7a80bbc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions server/vb/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.0.3 on 2024-04-02 20:54
# Generated by Django 5.0.3 on 2024-04-02 21:24

import django.core.validators
import django.db.models.deletion
Expand Down Expand Up @@ -43,7 +43,7 @@ class Migration(migrations.Migration):
('slug', models.SlugField(max_length=255, unique=True)),
('start_at', models.DateTimeField()),
('end_at', models.DateTimeField()),
('description', models.TextField(default='{{ school.short_name }} students: check your voter registration for a 1 in 10 chance to win a $25 Amazon gift card.', help_text="A description of the contest. Can use {{ school.name }} to insert the school's name, etc.")),
('template', models.TextField(default='{{ school.short_name }} students: check your voter registration for a 1 in 10 chance to win a $25 Amazon gift card.', help_text="A description of the contest. Can use {{ school.name }} to insert the school's name, etc.")),
('school', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='contests', to='vb.school')),
],
),
Expand Down
10 changes: 8 additions & 2 deletions server/vb/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import typing as t

from django.db import models
from django.template import Context, Template
from django.utils.timezone import now as django_now

from server.utils.contrast import HEX_COLOR_VALIDATOR, get_text_color
Expand Down Expand Up @@ -110,10 +111,10 @@ class Contest(models.Model):
slug = models.SlugField(max_length=255, blank=False, unique=True)
start_at = models.DateTimeField(blank=False)
end_at = models.DateTimeField(blank=False)
description = models.TextField(
template = models.TextField(
blank=False,
help_text="A description of the contest. Can use {{ school.name }} to insert the school's name, etc.", # noqa
default="{{ school.short_name }} students: check your voter registration for a 1 in 10 chance to win a $25 Amazon gift card.",
default="{{ school.short_name }} students: check your voter registration for a 1 in 10 chance to win a $25 Amazon gift card.", # noqa
)

# For now, we assume that each contest is associated with a single school.
Expand Down Expand Up @@ -146,6 +147,11 @@ def seconds_until_end(self, when: datetime.datetime | None = None) -> float:
when = when or django_now()
return (self.end_at - when).total_seconds()

def description(self):
"""Render the contest template."""
context = {"school": self.school, "contest": self}
return Template(self.template).render(Context(context))

def __str__(self):
"""Return the contest model's string representation."""
return f"Contest: {self.name} for {self.school.name}"
Expand Down
8 changes: 5 additions & 3 deletions server/vb/templates/school.dhtml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@
<img src="{{ school.logo.url }}"
alt="{{ school.short_name }} {{ school.mascot }} logo" />
<h2>Welcome to the Voter Bowl</h2>
<p>
{{ school.short_name }} students: check your voter registration status for a 1 in 10 chance to win a $25 Amazon gift card.
</p>
{% if current_contest %}
<p>{{ current_contest.description }}</p>
{% else %}
<p>There is no contest at this time. TODO: show something useful in this state?</p>
{% endif %}
<div class="button-holder">
{% include "components/button.dhtml" with text="Check my voter status" bg_color=school.logo.action_color color=school.logo.action_text_color %}
</div>
Expand Down

0 comments on commit 7a80bbc

Please sign in to comment.