small fixes

This commit is contained in:
Qwann 2016-10-21 18:49:46 +02:00
parent f3180c0b3e
commit 926bb66450
3 changed files with 15 additions and 53 deletions

View file

@ -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)

View file

@ -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,
@ -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

View file

@ -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):