Events are configurable
This commit mostly reproduces the structure of gestioncof's events, renames some stuff and adds a generic export view.
This commit is contained in:
parent
6e9dc03bc7
commit
d5e9d09044
4 changed files with 407 additions and 14 deletions
|
@ -16,7 +16,9 @@ class Event(models.Model):
|
|||
)
|
||||
registration_open = models.BooleanField(_("inscriptions ouvertes"), default=True)
|
||||
old = models.BooleanField(_("archiver (événement fini)"), default=False)
|
||||
subscribers = models.ManyToManyField(User, verbose_name=_("inscrit⋅e⋅s"))
|
||||
subscribers = models.ManyToManyField(
|
||||
User, through="Registration", verbose_name=_("inscrit⋅e⋅s")
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("événement")
|
||||
|
@ -26,8 +28,91 @@ class Event(models.Model):
|
|||
return self.title
|
||||
|
||||
|
||||
# TODO: gérer les options (EventOption & EventOptionChoice de gestioncof)
|
||||
# par exemple: "option végé au Mega (oui / non)"
|
||||
class Option(models.Model):
|
||||
"""Event options to be selected by participants at registration.
|
||||
|
||||
# TODO: gérer les champs commentaires (EventCommentField & EventCommentChoice)
|
||||
# par exemple: "champ "allergies / régime particulier" au Mega
|
||||
The possible choices are instances of `OptionChoice` (see below). A typical example
|
||||
is when the participants have the choice between different meal types (e.g. vegan /
|
||||
vegetarian / no pork / with meat). In this case, the "meal type" is an `Option` and
|
||||
the three alternatives are `OptionChoice`s.
|
||||
"""
|
||||
|
||||
event = models.ForeignKey(Event, on_delete=models.CASCADE, related_name="options")
|
||||
name = models.CharField(_("option d'événement"), max_length=200)
|
||||
multi_choices = models.BooleanField(_("choix multiples"), default=False)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("option d'événement")
|
||||
verbose_name_plural = _("options d'événement")
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class OptionChoice(models.Model):
|
||||
"""A possible choice for an event option (see Option)."""
|
||||
|
||||
option = models.ForeignKey(Option, on_delete=models.CASCADE, related_name="choices")
|
||||
choice = models.CharField(_("choix"), max_length=200)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("choix d'option d'événement")
|
||||
verbose_name_plural = _("choix d'option d'événement")
|
||||
|
||||
def __str__(self):
|
||||
return self.choice
|
||||
|
||||
|
||||
class ExtraField(models.Model):
|
||||
"""Extra event field, for event creators.
|
||||
|
||||
Extra text field that can be added by event creators to the event registration form.
|
||||
Typical examples are "remarks" fields (of type LONGTEXT) or more specific questions
|
||||
such as "emergency contact".
|
||||
"""
|
||||
|
||||
LONGTEXT = "longtext"
|
||||
SHORTTEXT = "shorttext"
|
||||
|
||||
FIELD_TYPE = [
|
||||
(SHORTTEXT, _("texte court (une ligne)")),
|
||||
(LONGTEXT, _("texte long (plusieurs lignes)")),
|
||||
]
|
||||
|
||||
event = models.ForeignKey(
|
||||
Event, on_delete=models.CASCADE, related_name="extra_fields"
|
||||
)
|
||||
name = models.CharField(_("champ d'événement supplémentaire"), max_length=200)
|
||||
field_type = models.CharField(_("type de champ"), max_length=9, choices=FIELD_TYPE)
|
||||
|
||||
|
||||
class ExtraFieldContent(models.Model):
|
||||
field = models.ForeignKey(ExtraField, on_delete=models.CASCADE)
|
||||
registration = models.ForeignKey(
|
||||
"Registration", on_delete=models.CASCADE, related_name="extra_info"
|
||||
)
|
||||
content = models.TextField(_("contenu du champ"))
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("contenu d'un champ événement supplémentaire")
|
||||
verbose_name_plural = _("contenus d'un champ événement supplémentaire")
|
||||
|
||||
def __str__(self):
|
||||
max_length = 50
|
||||
if len(self.content) > max_length:
|
||||
return self.content[: max_length - 1] + "…"
|
||||
else:
|
||||
return self.content
|
||||
|
||||
|
||||
class Registration(models.Model):
|
||||
event = models.ForeignKey(Event, on_delete=models.CASCADE)
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
options_choices = models.ManyToManyField(OptionChoice)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("inscription à un événement")
|
||||
verbose_name_plural = _("inscriptions à un événement")
|
||||
|
||||
def __str__(self):
|
||||
return "inscription de {} à {}".format(self.user, self.event)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue