diff --git a/event/models.py b/event/models.py index 9b0b42d..ec68e13 100644 --- a/event/models.py +++ b/event/models.py @@ -30,7 +30,7 @@ class Event(models.Model): ) created_by = models.ForeignKey( User, - related_name=_("created_events"), + related_name="created_events", editable=False, ) creation_date = models.DateTimeField( @@ -45,6 +45,9 @@ class Event(models.Model): verbose_name = _("Évènement") verbose_name_plural = _("Évènements") + def __str__(self): + return self.title + class Place(models.Model): name = models.CharField( @@ -57,6 +60,9 @@ class Place(models.Model): verbose_name = _("Lieu") verbose_name_plural = _("Lieux") + def __str__(self): + return self.name + class ActivityTag(models.Model): name = models.CharField( @@ -76,6 +82,9 @@ class ActivityTag(models.Model): verbose_name = _("Tag") verbose_name_plural = _("Tags") + def __str__(self): + return self.name + class ActivityTemplate(models.Model): title = models.CharField( @@ -114,13 +123,13 @@ class ActivityTemplate(models.Model): ) tags = models.ManyToManyField( ActivityTag, - related_name=_("activities"), + related_name="activities", blank=True, null=True, ) place = models.ManyToManyField( Place, - related_name=_("activities"), + related_name="activities", blank=True, null=True, ) @@ -129,15 +138,18 @@ class ActivityTemplate(models.Model): verbose_name = _("Template activité") verbose_name_plural = _("Templates activité") + def __str__(self): + return self.title + class Activity(ActivityTemplate): parent = models.ForeignKey( ActivityTemplate, - related_name=_("children"), + related_name="children", ) staff = models.ManyToManyField( User, - related_name=_("in_perm_activities"), + related_name="in_perm_activities", blank=True, ) # TODO : Utiliser db_constraint ou through @@ -147,12 +159,15 @@ class Activity(ActivityTemplate): verbose_name = _("Activité") verbose_name_plural = _("Activités") + # Si le champ de l'activité n'est pas spécifié + # alors on va chercher celui de self.parent def __getattr__(self, attrname): + attr = super(Activity, self).__getattr__(attrname) if (attrname == 'parent' - or attrname == 'staff' + or attrname == 'staff' or attrname == 'equipement'): - return super(Activity, self).__getattr__(attrname) - elif attrname is None: - return self.parent.attrname + return attr + elif attr is None: + return self.parent.__getattr__(attrname) else: - return attrname + return attr diff --git a/event/tests.py b/event/tests.py index ceaa19c..4aebeaf 100644 --- a/event/tests.py +++ b/event/tests.py @@ -1,8 +1,8 @@ from django.contrib.auth.models import User from django.test import TestCase -from datetime import datetime +from datetime import timedelta from django.utils import timezone -from .models import Event +from .models import Event, ActivityTemplate, Activity, Place class ActivityInheritanceTest(TestCase): @@ -18,10 +18,33 @@ class ActivityInheritanceTest(TestCase): title='La Nuit 2042', slug='nuit42', created_by=cls.erkan, - creation_date=datetime.now(), - descrition="La nuit c'est lol", + creation_date=timezone.now(), + description="La nuit c'est lol", beginning_date=timezone.now() - + datetime.timedelta(days=30), + + timedelta(days=30), ending_date=timezone.now() - + datetime.timedelta(days=31), + + timedelta(days=31), ) + cls.loge = Place.objects.create(name="Loge 45") + cls.permtemp = ActivityTemplate.objects.create( + title="Permanence loge", + # is_public non spécifié + has_perm=False, + description="Les perms c'est lol", + # remark non spécifié + ) + cls.permtemp.place.add(cls.loge) + cls.perm = Activity.objects.create( + parent=cls.permtemp, + # title non spécifié + is_public=True, + # has_perm non spécifié + # description non spécifiée + remarks="lol", + ) + + def test_event_name(self): + self.assertEqual(self.event.title, 'La Nuit 2042') + self.assertEqual(self.loge.name, 'Loge 45') + self.assertEqual(self.permtemp.title, 'Permanence loge') + self.assertEqual(self.permtemp.place.name, 'Loge 45')