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

This commit is contained in:
Ludovic Stephan 2017-07-21 17:02:21 +02:00
commit 6ece994f1c
5 changed files with 46 additions and 24 deletions

View file

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.3 on 2017-07-18 17:05
# Generated by Django 1.11.3 on 2017-07-21 14:20
from __future__ import unicode_literals
from django.conf import settings
@ -12,9 +12,9 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
('contenttypes', '0002_remove_content_type_name'),
('auth', '0008_alter_user_username_max_length'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('contenttypes', '0002_remove_content_type_name'),
]
operations = [

View file

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.3 on 2017-07-18 17:05
# Generated by Django 1.11.3 on 2017-07-21 14:20
from __future__ import unicode_literals
from django.db import migrations, models
@ -24,8 +24,8 @@ class Migration(migrations.Migration):
('description', models.TextField(verbose_name='description')),
],
options={
'verbose_name_plural': 'matériels permanents',
'verbose_name': 'matériel permanent',
'verbose_name': 'matériel',
'verbose_name_plural': 'matériels',
},
),
migrations.CreateModel(
@ -38,8 +38,8 @@ class Migration(migrations.Migration):
('equipment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='equipment.Equipment')),
],
options={
'verbose_name_plural': 'attributions de matériel',
'verbose_name': 'attribution de matériel',
'verbose_name_plural': 'attributions de matériel',
},
),
migrations.CreateModel(
@ -53,8 +53,8 @@ class Migration(migrations.Migration):
('equipment', models.ForeignKey(help_text='Matériel concerné par la remarque', on_delete=django.db.models.deletion.CASCADE, related_name='remarks', to='equipment.Equipment')),
],
options={
'verbose_name_plural': 'remarques sur le matériel',
'verbose_name': 'remarque sur matériel',
'verbose_name_plural': 'remarques sur le matériel',
},
),
migrations.AddField(
@ -65,6 +65,6 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='equipment',
name='event',
field=models.ForeignKey(blank=True, help_text="Si spécifié, l'instance du modèleest spécifique à l'évènement en question", null=True, on_delete=django.db.models.deletion.CASCADE, to='event.Event', verbose_name='évènement'),
field=models.ForeignKey(blank=True, help_text="Si spécifié, l'instance du modèle est spécifique à l'évènement en question", null=True, on_delete=django.db.models.deletion.CASCADE, to='event.Event', verbose_name='évènement'),
),
]

View file

@ -1,7 +1,7 @@
from django.db import models
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _
from event.models import Activity
from shared.models import EventSpecificMixin
from event.models import Activity, EventSpecificMixin
class Equipment(EventSpecificMixin, models.Model):
@ -18,8 +18,8 @@ class Equipment(EventSpecificMixin, models.Model):
)
class Meta:
verbose_name = _("matériel permanent")
verbose_name_plural = _("matériels permanents")
verbose_name = _("matériel")
verbose_name_plural = _("matériels")
def __str__(self):
return self.name
@ -40,6 +40,12 @@ class EquipmentAttribution(models.Model):
self.amout,
self.activity.get_herited('title'))
def save(self, *args, **kwargs):
if self.equipment.event and self.equipment.event != self.activity.event:
raise ValidationError
super(EquipmentAttribution, self).save(*args, **kwargs)
class EquipmentRemark(models.Model):
remark = models.TextField(_("remarque sur le matériel"))

View file

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.3 on 2017-07-18 17:05
# Generated by Django 1.11.3 on 2017-07-21 14:20
from __future__ import unicode_literals
from django.conf import settings
@ -32,8 +32,8 @@ class Migration(migrations.Migration):
('end', models.DateTimeField(verbose_name='heure de fin')),
],
options={
'verbose_name_plural': 'activités',
'verbose_name': 'activité',
'verbose_name_plural': 'activités',
},
),
migrations.CreateModel(
@ -45,8 +45,8 @@ class Migration(migrations.Migration):
('color', models.CharField(help_text='Rentrer une couleur en hexadécimal', max_length=7, validators=[django.core.validators.RegexValidator(message="La chaîne de caractère rentrée n'est pas une couleur en hexadécimal.", regex='^#(?:[0-9a-fA-F]{3}){1,2}$')], verbose_name='couleur')),
],
options={
'verbose_name_plural': 'tags',
'verbose_name': 'tag',
'verbose_name_plural': 'tags',
},
),
migrations.CreateModel(
@ -62,8 +62,8 @@ class Migration(migrations.Migration):
('remarks', models.TextField(blank=True, help_text='Visible uniquement par les organisateurs', null=True, verbose_name='remarques')),
],
options={
'verbose_name_plural': 'templates activité',
'verbose_name': 'template activité',
'verbose_name_plural': 'templates activité',
},
),
migrations.CreateModel(
@ -79,8 +79,8 @@ class Migration(migrations.Migration):
('created_by', models.ForeignKey(editable=False, on_delete=django.db.models.deletion.CASCADE, related_name='created_events', to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name_plural': 'évènements',
'verbose_name': 'évènement',
'verbose_name_plural': 'évènements',
},
),
migrations.CreateModel(
@ -89,11 +89,11 @@ class Migration(migrations.Migration):
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200, verbose_name='nom du lieu')),
('description', models.TextField(blank=True)),
('event', models.ForeignKey(blank=True, help_text="Si spécifié, l'instance du modèleest spécifique à l'évènement en question", null=True, on_delete=django.db.models.deletion.CASCADE, to='event.Event', verbose_name='évènement')),
('event', models.ForeignKey(blank=True, help_text="Si spécifié, l'instance du modèle est spécifique à l'évènement en question", null=True, on_delete=django.db.models.deletion.CASCADE, to='event.Event', verbose_name='évènement')),
],
options={
'verbose_name_plural': 'lieux',
'verbose_name': 'lieu',
'verbose_name_plural': 'lieux',
},
),
migrations.AddField(
@ -114,7 +114,7 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='activitytag',
name='event',
field=models.ForeignKey(blank=True, help_text="Si spécifié, l'instance du modèleest spécifique à l'évènement en question", null=True, on_delete=django.db.models.deletion.CASCADE, to='event.Event', verbose_name='évènement'),
field=models.ForeignKey(blank=True, help_text="Si spécifié, l'instance du modèle est spécifique à l'évènement en question", null=True, on_delete=django.db.models.deletion.CASCADE, to='event.Event', verbose_name='évènement'),
),
migrations.AddField(
model_name='activity',

View file

@ -4,7 +4,6 @@ from django.core.validators import RegexValidator
from django.core.exceptions import FieldError
from django.db import models
from communication.models import SubscriptionMixin
from shared.models import EventSpecificMixin
class Event(SubscriptionMixin, models.Model):
@ -39,6 +38,23 @@ class Event(SubscriptionMixin, models.Model):
return self.title
class EventSpecificMixin(models.Model):
"""Mixin allowing for event-specific models instances
or not (depending on whether the event field is null)"""
event = models.ForeignKey(
'event.Event',
verbose_name=_("évènement"),
help_text=_("Si spécifié, l'instance du modèle "
"est spécifique à l'évènement en question"),
blank=True,
null=True
)
class Meta:
abstract = True
class Place(EventSpecificMixin, models.Model):
name = models.CharField(
_("nom du lieu"),
@ -162,7 +178,7 @@ class Activity(AbstractActivityTemplate):
inherited_fields = [f.name for f in ActivityTemplate._meta.get_fields()]
m2m_fields = [f.name for f in ActivityTemplate._meta.get_fields()
if f.many_to_many]
attr = super(Activity, self).__getattribute__(attrname)
attr = getattr(self, attrname)
if attrname not in inherited_fields:
raise FieldError(
_("%(attrname)s n'est pas un champ héritable"),
@ -172,9 +188,9 @@ class Activity(AbstractActivityTemplate):
if attr.exists():
return attr
else:
return self.parent.__getattribute__(attrname)
return getattr(self.parent, attrname)
elif attr is None:
return self.parent.__getattribute__(attrname)
return getattr(self.parent, attrname)
else:
return attr