Skip to content
Snippets Groups Projects
Commit 0464bd7d authored by florimondmanca's avatar florimondmanca
Browse files

add accepted field on visit participant, update admin, signals, tests, factory, add populatedb test

parent 3790d581
Branches
No related tags found
No related merge requests found
"""Populate the database with fake data.""" """Populate the database with fake data."""
import random import random
import logging
from django.core.management import call_command from django.core.management import call_command
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.db import transaction from django.db import transaction
from django.contrib.auth.models import Group
import showcase_site.models import showcase_site.models
import users.models import users.models
...@@ -127,14 +129,22 @@ class Command(BaseCommand): ...@@ -127,14 +129,22 @@ class Command(BaseCommand):
def add_visit_organizers(self): def add_visit_organizers(self):
tutors = users.models.Tutor.objects.all() tutors = users.models.Tutor.objects.all()
visits_group = Group.objects.get(name=Groups.G_SECTEUR_SORTIES)
def add_to_organizers(visit, user):
if user not in visits_group.user_set.all():
visits_group.user_set.add(user)
visit.organizers_group.user_set.add(user)
for visit in visits.models.Visit.objects.all(): for visit in visits.models.Visit.objects.all():
# add 2 organizers to each visit # add 2 organizers to each visit
for tutor in random.choices(tutors, k=2): for tutor in random.choices(tutors, k=2):
visit.organizers_group.user_set.add(tutor.user) add_to_organizers(visit, tutor.user)
# add known tutor to organizers of first visit # add known tutor to organizers of a visit.
visit = visits.models.Visit.objects.first() # use last visit so to be sure it will have open registrations.
visit = visits.models.Visit.objects.last()
if visit.organizers_group not in self.known_tutor.user.groups.all(): if visit.organizers_group not in self.known_tutor.user.groups.all():
visit.organizers_group.user_set.add(self.known_tutor.user) add_to_organizers(visit, self.known_tutor.user)
@watcher(*affected) @watcher(*affected)
def create(self): def create(self):
......
...@@ -328,3 +328,4 @@ class VisitParticipantFactory(factory.DjangoModelFactory): ...@@ -328,3 +328,4 @@ class VisitParticipantFactory(factory.DjangoModelFactory):
return random.choice(visits_without_participants) return random.choice(visits_without_participants)
present = factory.LazyFunction(lambda: random.choice([None, False, True])) present = factory.LazyFunction(lambda: random.choice([None, False, True]))
accepted = factory.LazyFunction(lambda: random.choice([None, False, True]))
from django.test import TestCase
from django.core.management import call_command
class PopulateDbTest(TestCase):
"""Test the populatedb command."""
# TODO check log outputs
# TODO test --cleanbefore option
# TODO test --clean option
def test_call(self):
"""Call the command to check no error occurs."""
call_command('populatedb', verbosity=0)
...@@ -20,7 +20,11 @@ class VisitParticipantTest(ModelTestCase): ...@@ -20,7 +20,11 @@ class VisitParticipantTest(ModelTestCase):
'present': { 'present': {
'verbose_name': 'présent', 'verbose_name': 'présent',
'null': True, 'null': True,
} },
'accepted': {
'verbose_name': 'dossier validé',
'null': True,
},
} }
model_tests = { model_tests = {
'verbose_name': 'participant à la sortie', 'verbose_name': 'participant à la sortie',
......
...@@ -19,7 +19,7 @@ class UserVisitParticipantInline(VisitParticipantInline): ...@@ -19,7 +19,7 @@ class UserVisitParticipantInline(VisitParticipantInline):
All fields are read-only. All fields are read-only.
""" """
readonly_fields = ('user', 'visit', 'present') readonly_fields = ('user', 'visit', 'accepted', 'present',)
verbose_name = 'Participation aux sorties' verbose_name = 'Participation aux sorties'
verbose_name_plural = 'Participation aux sorties' verbose_name_plural = 'Participation aux sorties'
......
...@@ -55,7 +55,7 @@ class VisitForm(forms.ModelForm): ...@@ -55,7 +55,7 @@ class VisitForm(forms.ModelForm):
self.add_error('deadline', error) self.add_error('deadline', error)
class VisitParticipantInline(admin.TabularInline): class VisitParticipantInline(admin.StackedInline):
"""Inline for VisitParticipant.""" """Inline for VisitParticipant."""
model = Visit.participants.through model = Visit.participants.through
......
...@@ -49,7 +49,15 @@ class VisitParticipant(models.Model): ...@@ -49,7 +49,15 @@ class VisitParticipant(models.Model):
on_delete=models.CASCADE, null=True) on_delete=models.CASCADE, null=True)
visit = models.ForeignKey('Visit', verbose_name='sortie', visit = models.ForeignKey('Visit', verbose_name='sortie',
on_delete=models.CASCADE) on_delete=models.CASCADE)
present = models.NullBooleanField('présent') accepted = models.NullBooleanField(
'dossier validé',
help_text="Cocher si les pièces jointes envoyées sont valides.")
present = models.NullBooleanField(
'présent',
help_text=(
"Une fois la sortie passée, indiquer si le lycéen était présent."
)
)
class Meta: # noqa class Meta: # noqa
verbose_name = 'participant à la sortie' verbose_name = 'participant à la sortie'
......
...@@ -21,6 +21,9 @@ def sync_organizers_group(sender, instance, **kwargs): ...@@ -21,6 +21,9 @@ def sync_organizers_group(sender, instance, **kwargs):
group = Group.objects.create(name=group_name) group = Group.objects.create(name=group_name)
visit.organizers_group = group visit.organizers_group = group
assign_perm('manage_visit', group, visit) assign_perm('manage_visit', group, visit)
# Organizers group can change all visit participants,
# but only those of the visits they manage will be visible.
assign_perm('visits.change_visitparticipant', group)
group.save() group.save()
visit.save() visit.save()
elif visit.organizers_group.name != visit.organizers_group_name: elif visit.organizers_group.name != visit.organizers_group_name:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment