mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2024-12-05 02:06:52 +00:00
Create phase model to store the calendar
This commit is contained in:
parent
95fd8a066f
commit
bbeada74c7
61
apps/participation/migrations/0006_phase.py
Normal file
61
apps/participation/migrations/0006_phase.py
Normal file
@ -0,0 +1,61 @@
|
||||
# Generated by Django 3.1.1 on 2020-10-20 10:39
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
def register_phases(apps, schema_editor):
|
||||
"""
|
||||
Import the different phases of the action
|
||||
"""
|
||||
Phase = apps.get_model("participation", "phase")
|
||||
Phase.objects.get_or_create(
|
||||
phase_number=1,
|
||||
description="Soumission des vidéos",
|
||||
)
|
||||
Phase.objects.get_or_create(
|
||||
phase_number=2,
|
||||
description="Phase de questions",
|
||||
)
|
||||
Phase.objects.get_or_create(
|
||||
phase_number=3,
|
||||
description="Phase d'échanges entre les équipes",
|
||||
)
|
||||
Phase.objects.get_or_create(
|
||||
phase_number=4,
|
||||
description="Soumission de la vidéo de synthèse de l'échange",
|
||||
)
|
||||
|
||||
|
||||
def reverse_phase_registering(apps, schema_editor):
|
||||
"""
|
||||
Drop all phases in order to unapply this migration.
|
||||
"""
|
||||
Phase = apps.get_model("participation", "phase")
|
||||
Phase.objects.all().delete()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('participation', '0005_participation_valid'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Phase',
|
||||
fields=[
|
||||
('phase_number', models.AutoField(primary_key=True, serialize=False, unique=True, verbose_name='phase number')),
|
||||
('description', models.CharField(max_length=255, verbose_name="phase description")),
|
||||
('start', models.DateTimeField(default=django.utils.timezone.now, verbose_name='start date of the given phase')),
|
||||
('end', models.DateTimeField(default=django.utils.timezone.now, verbose_name='end date of the given phase')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'phase',
|
||||
'verbose_name_plural': 'phases',
|
||||
},
|
||||
),
|
||||
migrations.RunPython(
|
||||
register_phases,
|
||||
reverse_phase_registering,
|
||||
),
|
||||
]
|
@ -6,6 +6,7 @@ from django.core.validators import RegexValidator
|
||||
from django.db import models
|
||||
from django.db.models import Index
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils import timezone
|
||||
from django.utils.crypto import get_random_string
|
||||
from django.utils.text import format_lazy
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
@ -168,3 +169,34 @@ class Video(models.Model):
|
||||
class Meta:
|
||||
verbose_name = _("video")
|
||||
verbose_name_plural = _("videos")
|
||||
|
||||
|
||||
class Phase(models.Model):
|
||||
phase_number = models.AutoField(
|
||||
primary_key=True,
|
||||
unique=True,
|
||||
verbose_name=_("phase number"),
|
||||
)
|
||||
|
||||
description = models.CharField(
|
||||
max_length=255,
|
||||
verbose_name=_("phase description"),
|
||||
)
|
||||
|
||||
start = models.DateTimeField(
|
||||
verbose_name=_("start date of the given phase"),
|
||||
default=timezone.now,
|
||||
)
|
||||
|
||||
end = models.DateTimeField(
|
||||
verbose_name=_("end date of the given phase"),
|
||||
default=timezone.now,
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return _("Phase {phase_number:d} starts on {start:%Y-%m-%d %H:%M:} and ends on {end:%Y-%m-%d %H:%M}")\
|
||||
.format(phase_number=self.phase_number, start=self.start, end=self.end)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("phase")
|
||||
verbose_name_plural = _("phases")
|
||||
|
Loading…
Reference in New Issue
Block a user