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,
@ -171,8 +171,6 @@ class Equipment(EventSpecificMixin, models.Model):
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',
@ -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
) )