From 926bb664506aa598301162cb3ffa337865a5f69f Mon Sep 17 00:00:00 2001 From: Qwann Date: Fri, 21 Oct 2016 18:49:46 +0200 Subject: [PATCH] small fixes --- equipment/models.py | 11 ++++++----- event/models.py | 41 ++++++++--------------------------------- event/tests.py | 16 +--------------- 3 files changed, 15 insertions(+), 53 deletions(-) diff --git a/equipment/models.py b/equipment/models.py index d662367..e93cbd3 100644 --- a/equipment/models.py +++ b/equipment/models.py @@ -35,7 +35,7 @@ class TemporaryEquipment(AbstractEquipment): Event, related_name="specific_equipment", help_text=_("Évènement pour lequel le matériel " - "a été loué ou empreinté ou apporté"), + "a été loué ou emprunté ou apporté"), ) class Meta: @@ -54,9 +54,9 @@ class EquipmentAttribution(models.Model): verbose_name_plural = _("attributions de matériel") def __str__(self): - return self.equipment.name +\ - " (" + self.amout + ") " +\ - " -> " + self.activity.get_herited('title') + return "%s (%d) -> %s" % (self.equipment.name, + self.amout, + self.activity.get_herited('title')) class EquipmentRemark(models.Model): @@ -74,4 +74,5 @@ class EquipmentRemark(models.Model): verbose_name_plural = _("remarques sur le matériel") def __str__(self): - return self.equipment.name + " : " + self.remark + return "%s : %s" % (self.equipment.name, + self.remark) diff --git a/event/models.py b/event/models.py index d7d8ba9..9605070 100644 --- a/event/models.py +++ b/event/models.py @@ -1,20 +1,8 @@ from django.contrib.auth.models import User from django.utils.translation import ugettext_lazy as _ from django.core.validators import RegexValidator -from django.core import exceptions +from django.core.exceptions import FieldError from django.db import models -from re import search as re_search - - -def validate_color(value): - def is_hex_color(s): - return re_search(r'^#(?:[0-9a-fA-F]{3}){1,2}$', s) - if not is_hex_color(value): - raise exceptions.ValidationError( - _("%(value)s n'est pas une couleur"), - code='invalid_choice', - params={'value': value}, - ) class Event(models.Model): @@ -26,8 +14,8 @@ class Event(models.Model): _('Identificateur'), unique=True, primary_key=True, - help_text=_("Seulement des lettres, des chiffres ou \ - les caractères '_' ou '-'."), + help_text=_("Seulement des lettres, des chiffres ou" + "les caractères '_' ou '-'."), ) created_by = models.ForeignKey( User, @@ -79,7 +67,7 @@ class ActivityTag(models.Model): color_regex = RegexValidator( regex=r'^#(?:[0-9a-fA-F]{3}){1,2}$', message="La chaîne de caractère rentrée n'est pas" - "une couleur en hexadécimal.", + "une couleur en hexadécimal.", ) color = models.CharField( _('Couleur'), @@ -173,7 +161,10 @@ class Activity(ActivityTemplate): if (attrname == 'parent' or attrname == 'staff' or attrname == 'equipment'): - return attr + raise FieldError( + _("%(attrname)s n'est pas un champ héritable"), + params={'attrname': attrname}, + ) elif (attrname == 'place' or attrname == 'tags'): if attr.exists(): return attr @@ -190,19 +181,3 @@ class Activity(ActivityTemplate): def __str__(self): return self.get_herited('title') - - # Si le champ de l'activité n'est pas spécifié - # alors on va chercher celui de self.parent - # def __getattribute__(self, attrname): - # attr = super(Activity, self).__getattribute__(attrname) - # if (attrname == 'parent' - # or attrname == 'staff' - # or attrname == 'equipment'): - # return attr - # elif attr is None: - # return self.parent.__getattribute__(attrname) - # else: - # return attr - - # def __setattr__(self, name, value): - # self.__dict__[name] = value diff --git a/event/tests.py b/event/tests.py index 813aa3b..e634b82 100644 --- a/event/tests.py +++ b/event/tests.py @@ -1,6 +1,5 @@ from django.contrib.auth.models import User from django.core.exceptions import ValidationError -from django.db.utils import DataError from django.test import TestCase from datetime import timedelta from django.utils import timezone @@ -8,7 +7,6 @@ from .models import Event, ActivityTemplate, Activity, Place, \ ActivityTag -# TODO: héritage de `event` ? class ActivityInheritanceTest(TestCase): @classmethod def setUpTestData(cls): @@ -43,21 +41,9 @@ class ActivityInheritanceTest(TestCase): ) def setUp(self): - self.template_act = ActivityTemplate.objects.create( - # title - # is_public - # has_perm - # min_perm - # max_perm - # description - # remarks - # tags - # place - ) + self.template_act = ActivityTemplate.objects.create() self.real_act = Activity.objects.create( - # les mêmes plus : parent=self.template_act, - # staff ) def test_inherites_title(self):