small fixes
This commit is contained in:
parent
f3180c0b3e
commit
926bb66450
3 changed files with 15 additions and 53 deletions
|
@ -35,7 +35,7 @@ class TemporaryEquipment(AbstractEquipment):
|
||||||
Event,
|
Event,
|
||||||
related_name="specific_equipment",
|
related_name="specific_equipment",
|
||||||
help_text=_("Évènement pour lequel le matériel "
|
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:
|
class Meta:
|
||||||
|
@ -54,9 +54,9 @@ class EquipmentAttribution(models.Model):
|
||||||
verbose_name_plural = _("attributions de matériel")
|
verbose_name_plural = _("attributions de matériel")
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.equipment.name +\
|
return "%s (%d) -> %s" % (self.equipment.name,
|
||||||
" (" + self.amout + ") " +\
|
self.amout,
|
||||||
" -> " + self.activity.get_herited('title')
|
self.activity.get_herited('title'))
|
||||||
|
|
||||||
|
|
||||||
class EquipmentRemark(models.Model):
|
class EquipmentRemark(models.Model):
|
||||||
|
@ -74,4 +74,5 @@ class EquipmentRemark(models.Model):
|
||||||
verbose_name_plural = _("remarques sur le matériel")
|
verbose_name_plural = _("remarques sur le matériel")
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.equipment.name + " : " + self.remark
|
return "%s : %s" % (self.equipment.name,
|
||||||
|
self.remark)
|
||||||
|
|
|
@ -1,20 +1,8 @@
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.core.validators import RegexValidator
|
from django.core.validators import RegexValidator
|
||||||
from django.core import exceptions
|
from django.core.exceptions import FieldError
|
||||||
from django.db import models
|
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):
|
class Event(models.Model):
|
||||||
|
@ -26,8 +14,8 @@ class Event(models.Model):
|
||||||
_('Identificateur'),
|
_('Identificateur'),
|
||||||
unique=True,
|
unique=True,
|
||||||
primary_key=True,
|
primary_key=True,
|
||||||
help_text=_("Seulement des lettres, des chiffres ou \
|
help_text=_("Seulement des lettres, des chiffres ou"
|
||||||
les caractères '_' ou '-'."),
|
"les caractères '_' ou '-'."),
|
||||||
)
|
)
|
||||||
created_by = models.ForeignKey(
|
created_by = models.ForeignKey(
|
||||||
User,
|
User,
|
||||||
|
@ -173,7 +161,10 @@ class Activity(ActivityTemplate):
|
||||||
if (attrname == 'parent'
|
if (attrname == 'parent'
|
||||||
or attrname == 'staff'
|
or attrname == 'staff'
|
||||||
or attrname == 'equipment'):
|
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'):
|
elif (attrname == 'place' or attrname == 'tags'):
|
||||||
if attr.exists():
|
if attr.exists():
|
||||||
return attr
|
return attr
|
||||||
|
@ -190,19 +181,3 @@ class Activity(ActivityTemplate):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.get_herited('title')
|
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
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.db.utils import DataError
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
@ -8,7 +7,6 @@ from .models import Event, ActivityTemplate, Activity, Place, \
|
||||||
ActivityTag
|
ActivityTag
|
||||||
|
|
||||||
|
|
||||||
# TODO: héritage de `event` ?
|
|
||||||
class ActivityInheritanceTest(TestCase):
|
class ActivityInheritanceTest(TestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
|
@ -43,21 +41,9 @@ class ActivityInheritanceTest(TestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.template_act = ActivityTemplate.objects.create(
|
self.template_act = ActivityTemplate.objects.create()
|
||||||
# title
|
|
||||||
# is_public
|
|
||||||
# has_perm
|
|
||||||
# min_perm
|
|
||||||
# max_perm
|
|
||||||
# description
|
|
||||||
# remarks
|
|
||||||
# tags
|
|
||||||
# place
|
|
||||||
)
|
|
||||||
self.real_act = Activity.objects.create(
|
self.real_act = Activity.objects.create(
|
||||||
# les mêmes plus :
|
|
||||||
parent=self.template_act,
|
parent=self.template_act,
|
||||||
# staff
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_inherites_title(self):
|
def test_inherites_title(self):
|
||||||
|
|
Loading…
Reference in a new issue