On rajoute une abbréviation optionnelle pour les options
This commit is contained in:
parent
875b80b2a6
commit
15f160a0e6
5 changed files with 42 additions and 7 deletions
|
@ -78,8 +78,14 @@ class OptionForm(forms.ModelForm):
|
|||
|
||||
class Meta:
|
||||
model = Option
|
||||
fields = [*Option.text.fields]
|
||||
fields = [*Option.text.fields, "abbreviation"]
|
||||
widgets = {"text_fr": forms.TextInput, "text_en": forms.TextInput}
|
||||
help_texts = {
|
||||
"abbreviation": _(
|
||||
"L'abbréviation est optionnelle et sert à identifier plus facilement les "
|
||||
"différentes options. Elle est affiché sans espaces et en majuscules."
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
class DeleteVoteForm(forms.Form):
|
||||
|
@ -102,7 +108,7 @@ class SelectVoteForm(forms.ModelForm):
|
|||
# We set the option's text as the label for the checkbox
|
||||
instance = kwargs.get("instance", None)
|
||||
if instance is not None:
|
||||
self.fields["selected"].label = instance.text
|
||||
self.fields["selected"].label = str(instance)
|
||||
|
||||
selected = forms.BooleanField(required=False)
|
||||
|
||||
|
@ -118,7 +124,7 @@ class RankVoteForm(forms.ModelForm):
|
|||
# We set the option's text as the label for the rank
|
||||
instance = kwargs.get("instance", None)
|
||||
if instance is not None:
|
||||
self.fields["rank"].label = instance.text
|
||||
self.fields["rank"].label = str(instance)
|
||||
|
||||
rank = forms.IntegerField(required=False)
|
||||
|
||||
|
|
20
elections/migrations/0023_option_abbreviation.py
Normal file
20
elections/migrations/0023_option_abbreviation.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
# Generated by Django 3.2 on 2021-04-16 23:21
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("elections", "0022_auto_20210415_1050"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="option",
|
||||
name="abbreviation",
|
||||
field=models.CharField(
|
||||
blank=True, max_length=8, verbose_name="abbréviation"
|
||||
),
|
||||
),
|
||||
]
|
|
@ -137,6 +137,7 @@ class Option(models.Model):
|
|||
Question, related_name="options", on_delete=models.CASCADE
|
||||
)
|
||||
text = TranslatedFieldWithFallback(models.TextField(_("texte"), blank=False))
|
||||
abbreviation = models.CharField(_("abbréviation"), max_length=8, blank=True)
|
||||
|
||||
winner = models.BooleanField(_("option gagnante"), default=False)
|
||||
voters = models.ManyToManyField(
|
||||
|
@ -148,7 +149,15 @@ class Option(models.Model):
|
|||
# For now, we store the amount of votes received after the election is tallied
|
||||
nb_votes = models.PositiveSmallIntegerField(_("nombre de votes reçus"), default=0)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
# On enlève les espaces et on passe tout en majuscules
|
||||
self.abbreviation = "".join(self.abbreviation.upper().split())
|
||||
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
if self.abbreviation:
|
||||
return self.abbreviation + " - " + self.text
|
||||
return self.text
|
||||
|
||||
class Meta:
|
||||
|
|
|
@ -179,7 +179,7 @@
|
|||
<div class="panel-heading is-size-6">
|
||||
<div class="level">
|
||||
<div class="level-left is-flex-shrink-1">
|
||||
<span>{{ q.text }}</span>
|
||||
<span>{{ q }}</span>
|
||||
</div>
|
||||
|
||||
{% if q in cast_questions %}
|
||||
|
@ -211,7 +211,7 @@
|
|||
</span>
|
||||
{% endif %}
|
||||
|
||||
<span class="ml-2">{{ o.text }}</span>
|
||||
<span class="ml-2">{{ o }}</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
|
|
|
@ -163,7 +163,7 @@
|
|||
<div class="level">
|
||||
<div class="level-left is-flex-shrink-1">
|
||||
<div class="level-item is-flex-shrink-1">
|
||||
<span>{{ q.text }}</span>
|
||||
<span>{{ q }}</span>
|
||||
</div>
|
||||
|
||||
{% if election.start_date > current_time %}
|
||||
|
@ -232,7 +232,7 @@
|
|||
{% endif %}
|
||||
</span>
|
||||
|
||||
<span class="ml-2">{{ o.text }}</span>
|
||||
<span class="ml-2">{{ o }}</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
|
|
Loading…
Reference in a new issue