Compare commits
2 Commits
72e6388c0c
...
03ed9c74b0
| Author | SHA1 | Date | |
|---|---|---|---|
| 03ed9c74b0 | |||
| fb830710f2 |
@@ -52,6 +52,7 @@ INSTALLED_APPS = [
|
|||||||
"theme.apps.ThemeConfig", # Tailwind theme app
|
"theme.apps.ThemeConfig", # Tailwind theme app
|
||||||
"members.apps.MembersConfig",
|
"members.apps.MembersConfig",
|
||||||
"backend.apps.BackendConfig",
|
"backend.apps.BackendConfig",
|
||||||
|
"teams.apps.TeamsConfig",
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
|||||||
0
teams/__init__.py
Normal file
0
teams/__init__.py
Normal file
3
teams/admin.py
Normal file
3
teams/admin.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
||||||
5
teams/apps.py
Normal file
5
teams/apps.py
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class TeamsConfig(AppConfig):
|
||||||
|
name = "teams"
|
||||||
48
teams/migrations/0001_initial.py
Normal file
48
teams/migrations/0001_initial.py
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
# Generated by Django 6.0.3 on 2026-04-18 13:47
|
||||||
|
|
||||||
|
import rules.contrib.models
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = []
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name="Season",
|
||||||
|
fields=[
|
||||||
|
(
|
||||||
|
"id",
|
||||||
|
models.BigAutoField(
|
||||||
|
auto_created=True,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
verbose_name="ID",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("start_date", models.DateField(verbose_name="start date")),
|
||||||
|
("end_date", models.DateField(verbose_name="end date")),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
"verbose_name": "season",
|
||||||
|
"verbose_name_plural": "seasons",
|
||||||
|
"ordering": ["start_date"],
|
||||||
|
"constraints": [
|
||||||
|
models.UniqueConstraint(
|
||||||
|
fields=("start_date", "end_date"),
|
||||||
|
name="season_start_date_end_date_unique",
|
||||||
|
violation_error_message="Start and end date for a given season must be unique",
|
||||||
|
),
|
||||||
|
models.CheckConstraint(
|
||||||
|
condition=models.Q(("start_date__lt", models.F("end_date"))),
|
||||||
|
name="season_start_date_lt_end_date",
|
||||||
|
violation_error_message="Start date must be before end date.",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
bases=(rules.contrib.models.RulesModelMixin, models.Model),
|
||||||
|
),
|
||||||
|
]
|
||||||
0
teams/migrations/__init__.py
Normal file
0
teams/migrations/__init__.py
Normal file
44
teams/models.py
Normal file
44
teams/models.py
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
import datetime
|
||||||
|
|
||||||
|
from django.db import models
|
||||||
|
from django.utils import timezone
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from rules import is_superuser
|
||||||
|
from rules.contrib.models import RulesModel
|
||||||
|
|
||||||
|
|
||||||
|
class Season(RulesModel):
|
||||||
|
start_date = models.DateField(_("start date"))
|
||||||
|
end_date = models.DateField(_("end date"))
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name = _("season")
|
||||||
|
verbose_name_plural = _("seasons")
|
||||||
|
ordering = ["start_date"]
|
||||||
|
rules_permissions = {"add": is_superuser, "view": is_superuser, "change": is_superuser, "delete": is_superuser}
|
||||||
|
constraints = [
|
||||||
|
models.UniqueConstraint(fields=["start_date", "end_date"], name="season_start_date_end_date_unique", violation_error_message=_("Start and end date for a given season must be unique")),
|
||||||
|
models.CheckConstraint(condition=models.Q(start_date__lt=models.F("end_date")), name="season_start_date_lt_end_date", violation_error_message=_("Start date must be before end date.")),
|
||||||
|
]
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return _("Season '{start_date} - '{end_date}").format(start_date=self.start_date.strftime("%y"), end_date=self.end_date.strftime("%y"))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_current(self) -> bool:
|
||||||
|
return self.start_date <= timezone.now().date() <= self.end_date
|
||||||
|
|
||||||
|
@property
|
||||||
|
def date_range(self) -> tuple[datetime.date, datetime.date]:
|
||||||
|
return self.start_date, self.end_date
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def for_date(cls, current_date: datetime.date | None = None, values_only: bool = False) -> "tuple[datetime.date, datetime.date] | Season":
|
||||||
|
if current_date is None:
|
||||||
|
current_date = timezone.now().date()
|
||||||
|
|
||||||
|
season = cls.objects.get(start_date__lte=current_date, end_date__gte=current_date)
|
||||||
|
|
||||||
|
if values_only:
|
||||||
|
return season.date_range
|
||||||
|
return season
|
||||||
3
teams/tests.py
Normal file
3
teams/tests.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
{% if request.user.is_superuser %}
|
{% if request.user.is_superuser %}
|
||||||
<li class="menu-title mt-4">Configuration</li>
|
<li class="menu-title mt-4">Configuration</li>
|
||||||
<li><a href="{% url "backend:configuration" %}" class="menu-item {% if configuration in request.path %}menu-active{% endif %}" data-menu="configuration"><i class="fa-solid fa-screwdriver-wrench"></i> Settings</a></li>
|
<li><a href="{% url "backend:configuration" %}" class="menu-item {% if configuration in request.path %}menu-active{% endif %}" data-menu="configuration">
|
||||||
|
<i class="fa-solid fa-screwdriver-wrench"></i> Settings
|
||||||
|
</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock sidebar %}
|
{% endblock sidebar %}
|
||||||
Reference in New Issue
Block a user