MAJ : add on_delete + MIDDLEWARE

This commit is contained in:
Qwann 2018-08-27 00:02:33 +02:00
parent 7c7adab658
commit b45d7722a7
5 changed files with 44 additions and 33 deletions

View file

@ -20,7 +20,10 @@ class Subscription(models.Model):
class UserSubscription(Subscription): class UserSubscription(Subscription):
user = models.ForeignKey(User) user = models.ForeignKey(
User,
on_delete=models.CASCADE,
)
is_unsub = models.BooleanField( is_unsub = models.BooleanField(
_("désinscription"), _("désinscription"),
default=False default=False
@ -32,7 +35,10 @@ class UserSubscription(Subscription):
class GroupSubscription(Subscription): class GroupSubscription(Subscription):
group = models.ForeignKey(Group) group = models.ForeignKey(
Group,
on_delete=models.CASCADE,
)
class Meta: class Meta:
verbose_name = _("souscription en groupe") verbose_name = _("souscription en groupe")

View file

@ -7,7 +7,6 @@ from django.db.models import Q
from .fields import IdField from .fields import IdField
from taggit.managers import TaggableManager
from datetime import date from datetime import date
@ -21,6 +20,7 @@ class EquipmentCategory(models.Model):
blank=True, blank=True,
null=True, null=True,
default=None, default=None,
on_delete=models.SET_NULL,
related_name="children", related_name="children",
help_text=_("merci de ne pas faire de référence cyclique"), help_text=_("merci de ne pas faire de référence cyclique"),
verbose_name=_("parent"), verbose_name=_("parent"),
@ -35,7 +35,6 @@ class EquipmentCategory(models.Model):
return True return True
current = current.parent current = current.parent
def full_name(self): def full_name(self):
current = self current = self
res = "" res = ""
@ -51,7 +50,6 @@ class EquipmentCategory(models.Model):
full_name.short_description = _("Chemin complet") full_name.short_description = _("Chemin complet")
full_name_p = property(full_name) full_name_p = property(full_name)
class Meta: class Meta:
verbose_name = _("catégories") verbose_name = _("catégories")
verbose_name_plural = _("catégories") verbose_name_plural = _("catégories")
@ -67,7 +65,7 @@ class EquipmentCategory(models.Model):
if current.parent == self: if current.parent == self:
self.parent = None self.parent = None
done = True done = True
elif current.parent == None: elif current.parent is None:
done = True done = True
current = current.parent current = current.parent
return super().save(*args, **kwargs) return super().save(*args, **kwargs)
@ -76,7 +74,8 @@ class EquipmentCategory(models.Model):
class EquipmentQuerySet(models.QuerySet): class EquipmentQuerySet(models.QuerySet):
def in_category(self, cat): def in_category(self, cat):
filtre = Q(id__lt=0) filtre = Q(id__lt=0)
childs_id = [ c.id for c in EquipmentCategory.objects.all() if c.has_parent(cat) ] childs_id = [c.id for c in EquipmentCategory.objects.all()
if c.has_parent(cat)]
for pk in childs_id: for pk in childs_id:
filtre |= Q(category__id=pk) filtre |= Q(category__id=pk)
return self.filter(filtre) return self.filter(filtre)
@ -102,6 +101,7 @@ class Equipment(EventSpecificMixin, models.Model):
verbose_name=_("propriétaire"), verbose_name=_("propriétaire"),
blank=True, blank=True,
null=True, null=True,
on_delete=models.SET_NULL,
) )
category = models.ForeignKey( category = models.ForeignKey(
EquipmentCategory, EquipmentCategory,
@ -134,9 +134,9 @@ class Equipment(EventSpecificMixin, models.Model):
return [] return []
res = list(map(lambda x: x+1, range(self.stock))) res = list(map(lambda x: x+1, range(self.stock)))
for lost in self.losts.all(): for lost in self.losts.all():
res = [ x res = [x
for x in res for x in res
if x not in lost.ids ] if x not in lost.ids]
# TODO cassé # TODO cassé
# TODO utilisés # TODO utilisés
return res return res
@ -144,7 +144,7 @@ class Equipment(EventSpecificMixin, models.Model):
def ids_lost(self): def ids_lost(self):
res = [] res = []
for lost in self.losts.all(): for lost in self.losts.all():
res = res + [ x res = res + [x
for x in lost.ids for x in lost.ids
if x not in res] if x not in res]
return res return res
@ -162,17 +162,15 @@ class Equipment(EventSpecificMixin, models.Model):
full_category.short_description = _("Chemin complet") full_category.short_description = _("Chemin complet")
ids_aviable.short_description = _("disponibles") ids_aviable.short_description = _("disponibles")
ids_lost.short_description = _("perdus") ids_lost.short_description = _("perdus")
stock_aviable.short_description= _("quantité disponible") stock_aviable.short_description = _("quantité disponible")
stock_lost.short_description = _("quantité perdue") stock_lost.short_description = _("quantité perdue")
full_category_p= property(full_category) full_category_p = property(full_category)
ids_aviable_p= property(ids_aviable) ids_aviable_p = property(ids_aviable)
ids_lost_p= property(ids_lost) ids_lost_p = property(ids_lost)
stock_aviable_p= property(stock_aviable) stock_aviable_p = property(stock_aviable)
stock_lost_p = property(stock_lost) stock_lost_p = property(stock_lost)
class Meta: class Meta:
verbose_name = _("matériel") verbose_name = _("matériel")
verbose_name_plural = _("matériels") verbose_name_plural = _("matériels")
@ -195,6 +193,7 @@ class EquipmentAttribute(models.Model):
def __str__(self): def __str__(self):
return self.name return self.name
class EquipmentAttributeValue(models.Model): class EquipmentAttributeValue(models.Model):
equipment = models.ForeignKey( equipment = models.ForeignKey(
Equipment, Equipment,
@ -223,8 +222,15 @@ class EquipmentAttributeValue(models.Model):
class EquipmentAttribution(models.Model): class EquipmentAttribution(models.Model):
equipment = models.ForeignKey(Equipment, verbose_name=_("matériel")) equipment = models.ForeignKey(
activity = models.ForeignKey(Activity) Equipment,
verbose_name=_("matériel"),
on_delete=models.CASCADE,
)
activity = models.ForeignKey(
Activity,
on_delete=models.CASCADE,
)
amount = models.BigIntegerField(_("quantité attribuée")) amount = models.BigIntegerField(_("quantité attribuée"))
remarks = models.TextField( remarks = models.TextField(
_("remarques concernant l'attribution"), _("remarques concernant l'attribution"),
@ -241,7 +247,8 @@ class EquipmentAttribution(models.Model):
self.activity.get_herited('title')) self.activity.get_herited('title'))
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
if self.equipment.event and self.equipment.event != self.activity.event: if (self.equipment.event
and self.equipment.event != self.activity.event):
raise ValidationError raise ValidationError
super(EquipmentAttribution, self).save(*args, **kwargs) super(EquipmentAttribution, self).save(*args, **kwargs)

View file

@ -56,7 +56,7 @@ INSTALLED_APPS = [
'django.contrib.sites', 'django.contrib.sites',
# 'channels', # 'channels',
'rest_framework', # 'rest_framework',
'bootstrapform', 'bootstrapform',
'widget_tweaks', 'widget_tweaks',
'taggit', 'taggit',
@ -71,8 +71,7 @@ INSTALLED_APPS = [
'allauth_cas', 'allauth_cas',
'allauth_ens.providers.clipper', 'allauth_ens.providers.clipper',
# 'api',
'api',
'communication', 'communication',
'equipment', 'equipment',
'event', 'event',
@ -80,7 +79,7 @@ INSTALLED_APPS = [
'users', 'users',
] ]
MIDDLEWARE_CLASSES = [ MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware', 'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
@ -184,7 +183,7 @@ AUTHENTICATION_BACKENDS = (
SITE_ID = 1 SITE_ID = 1
CAS_SERVER_URL = "https://cas.eleves.ens.fr/" #SPI CAS CAS_SERVER_URL = "https://cas.eleves.ens.fr/" # SPI CAS
CAS_VERIFY_URL = "https://cas.eleves.ens.fr/" CAS_VERIFY_URL = "https://cas.eleves.ens.fr/"
CAS_IGNORE_REFERER = True CAS_IGNORE_REFERER = True
CAS_REDIRECT_URL = reverse_lazy('shared:home') CAS_REDIRECT_URL = reverse_lazy('shared:home')
@ -213,7 +212,5 @@ SOCIALACCOUNT_PROVIDERS = {
} }
ACCOUNT_ADAPTER = 'shared.allauth_adapter.AccountAdapter' ACCOUNT_ADAPTER = 'shared.allauth_adapter.AccountAdapter'
SOCIALACCOUNT_ADAPTER = 'shared.allauth_adapter.SocialAccountAdapter' SOCIALACCOUNT_ADAPTER = 'shared.allauth_adapter.SocialAccountAdapter'

View file

@ -12,9 +12,9 @@ DEBUG = True
# Add some debugging tools # Add some debugging tools
INSTALLED_APPS += ["debug_toolbar", "debug_panel"] # NOQA INSTALLED_APPS += ["debug_toolbar", "debug_panel"] # NOQA
MIDDLEWARE_CLASSES = ( MIDDLEWARE = (
["debug_panel.middleware.DebugPanelMiddleware"] ["debug_panel.middleware.DebugPanelMiddleware"]
+ MIDDLEWARE_CLASSES # NOQA + MIDDLEWARE # NOQA
) )

View file

@ -11,6 +11,7 @@ class EventSpecificMixin(models.Model):
verbose_name=_("évènement"), verbose_name=_("évènement"),
help_text=_("Si spécifié, l'instance du modèle" help_text=_("Si spécifié, l'instance du modèle"
"est spécifique à l'évènement en question"), "est spécifique à l'évènement en question"),
on_delete=models.CASCADE,
blank=True, blank=True,
null=True null=True
) )