Merge branch 'models' of git.eleves.ens.fr:cof-geek/GestionEvenementiel into models

This commit is contained in:
Qwann 2016-10-17 19:40:37 +02:00
commit 895ae3df55
6 changed files with 86 additions and 3 deletions

5
equipment/apps.py Normal file
View file

@ -0,0 +1,5 @@
from django.apps import AppConfig
class EquipmentConfig(AppConfig):
name = 'equipment'

View file

77
equipment/models.py Normal file
View file

@ -0,0 +1,77 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _
from event.models import Event, Activity
class AbstractEquipment(models.Model):
name = models.CharField(
_("Nom du matériel"),
max_length=200,
)
stock = models.PositiveSmallIntegerField(_("Quantité disponible"))
description = models.TextField(_("Description"))
activities = models.ManyToManyField(
Activity,
related_name="equipment",
through="EquipmentAttribution",
)
class Meta:
verbose_name = _("matériel abstrait")
verbose_name_plural = _("matériels abstraits")
def __str__(self):
return self.name
class Equipment(AbstractEquipment):
class Meta:
verbose_name = _("matériel permanent")
verbose_name_plural = _("matériels permanents")
class TemporaryEquipment(AbstractEquipment):
event = models.ForeignKey(
Event,
related_name="specific_equipment",
help_text=_("Évènement pour lequel le matériel "
"a été loué ou empreinté ou apporté"),
)
class Meta:
verbose_name = _("matériel temporaire")
verbose_name_plural = _("matériels temporaires")
class EquipmentAttribution(models.Model):
equipment = models.ForeignKey(AbstractEquipment)
activity = models.ForeignKey(Activity)
amount = models.PositiveSmallIntegerField(_("Quantité attribuée"))
remarks = models.TextField("Remarques concernant l'attribution")
class Meta:
verbose_name = _("attribution de matériel")
verbose_name_plural = _("attributions de matériel")
def __str__(self):
return self.equipment.name +\
" (" + self.amout + ") " +\
" -> " + self.activity.get_herited('title')
class EquipmentRemark(models.Model):
remark = models.TextField("Remarque sur le matériel")
equipment = models.ForeignKey(
AbstractEquipment,
related_name="remarks",
help_text=_("Matériel concerné par la remarque"),
)
is_broken = models.BooleanField()
is_lost = models.BooleanField()
class Meta:
verbose_name = _("remarque sur matériel")
verbose_name_plural = _("remarques sur le matériel")
def __str__(self):
return self.equipment.name + " : " + self.remark

View file

@ -31,6 +31,7 @@ ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'equipment.apps.EquipmentConfig',
'event.apps.EventConfig',
'django.contrib.admin',
'django.contrib.auth',
@ -132,6 +133,7 @@ USE_TZ = True
STATIC_URL = '/static/'
def show_toolbar(request):
"""
On ne veut pas la vérification de INTERNAL_IPS faite par la debug-toolbar

View file

View file

@ -164,13 +164,12 @@ class Activity(ActivityTemplate):
related_name="in_perm_activities",
blank=True,
)
# equipement = models.ManyToManyField(Equipement)
def get_herited(self, attrname):
attr = super(Activity, self).__getattribute__(attrname)
if (attrname == 'parent'
or attrname == 'staff'
or attrname == 'equipement'):
or attrname == 'equipment'):
return attr
elif (attrname == 'place' or attrname == 'tags'):
if attr.exists():
@ -195,7 +194,7 @@ class Activity(ActivityTemplate):
# attr = super(Activity, self).__getattribute__(attrname)
# if (attrname == 'parent'
# or attrname == 'staff'
# or attrname == 'equipement'):
# or attrname == 'equipment'):
# return attr
# elif attr is None:
# return self.parent.__getattribute__(attrname)