Skip to content

Commit bed0e8e

Browse files
committed
add enrollment type
1 parent ed98f96 commit bed0e8e

File tree

6 files changed

+394
-5
lines changed

6 files changed

+394
-5
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ check:
1010
make isort style types test
1111
run:
1212
cd landing_page; DEBUG=1 python manage.py runserver
13+
shell:
14+
cd landing_page; DEBUG=1 python manage.py shell
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 4.2.4 on 2023-09-08 13:49
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('mainpage', '0042_enrollment_platim_url'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='enrollment',
15+
name='type',
16+
field=models.CharField(blank=True, choices=[('BASE', 'BASE'), ('ADVANCED', 'ADVANCED')], max_length=10, null=True),
17+
),
18+
]

landing_page/mainpage/models.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import enum
2+
13
from django.db import models
24
from django.utils.timezone import now
35

@@ -55,10 +57,20 @@ def __str__(self) -> str:
5557
)
5658

5759

60+
class EnrollmentType(enum.StrEnum):
61+
BASE = "BASE"
62+
ADVANCED = "ADVANCED"
63+
64+
@classmethod
65+
def get_choices(cls) -> list[tuple[str, str]]:
66+
return [(v, v) for v in cls]
67+
68+
5869
class Enrollment(models.Model):
5970
timepad_event_id = models.CharField(max_length=64, null=True, blank=True)
6071
platim_url = models.CharField(max_length=254, null=True, blank=True)
6172

73+
type = models.CharField(max_length=10, choices=EnrollmentType.get_choices(), null=True, blank=True)
6274
start_date = models.DateField()
6375
end_date = models.DateField()
6476
end_registration_date = models.DateField()
@@ -68,8 +80,11 @@ class Enrollment(models.Model):
6880
late_price_date_from = models.DateField()
6981

7082
@staticmethod
71-
def get_enrollment_with_active_registration() -> "Enrollment | None":
72-
return Enrollment.objects.filter(end_registration_date__gte=now()).first()
83+
def get_enrollment_with_active_registration(enrollment_type: EnrollmentType) -> "Enrollment | None":
84+
return Enrollment.objects.filter(
85+
type=enrollment_type,
86+
end_registration_date__gte=now(),
87+
).first()
7388

7489
def __str__(self) -> str:
75-
return f"Enrollment ({self.start_date} - {self.end_date})"
90+
return f"{self.type.capitalize()} enrollment ({self.start_date} - {self.end_date})"

0 commit comments

Comments
 (0)