MAJ : add on_delete + MIDDLEWARE
This commit is contained in:
parent
7c7adab658
commit
b45d7722a7
5 changed files with 44 additions and 33 deletions
|
@ -20,7 +20,10 @@ class Subscription(models.Model):
|
|||
|
||||
|
||||
class UserSubscription(Subscription):
|
||||
user = models.ForeignKey(User)
|
||||
user = models.ForeignKey(
|
||||
User,
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
is_unsub = models.BooleanField(
|
||||
_("désinscription"),
|
||||
default=False
|
||||
|
@ -32,7 +35,10 @@ class UserSubscription(Subscription):
|
|||
|
||||
|
||||
class GroupSubscription(Subscription):
|
||||
group = models.ForeignKey(Group)
|
||||
group = models.ForeignKey(
|
||||
Group,
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("souscription en groupe")
|
||||
|
|
|
@ -7,7 +7,6 @@ from django.db.models import Q
|
|||
|
||||
from .fields import IdField
|
||||
|
||||
from taggit.managers import TaggableManager
|
||||
from datetime import date
|
||||
|
||||
|
||||
|
@ -21,6 +20,7 @@ class EquipmentCategory(models.Model):
|
|||
blank=True,
|
||||
null=True,
|
||||
default=None,
|
||||
on_delete=models.SET_NULL,
|
||||
related_name="children",
|
||||
help_text=_("merci de ne pas faire de référence cyclique"),
|
||||
verbose_name=_("parent"),
|
||||
|
@ -35,7 +35,6 @@ class EquipmentCategory(models.Model):
|
|||
return True
|
||||
current = current.parent
|
||||
|
||||
|
||||
def full_name(self):
|
||||
current = self
|
||||
res = ""
|
||||
|
@ -51,7 +50,6 @@ class EquipmentCategory(models.Model):
|
|||
full_name.short_description = _("Chemin complet")
|
||||
full_name_p = property(full_name)
|
||||
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("catégories")
|
||||
verbose_name_plural = _("catégories")
|
||||
|
@ -67,7 +65,7 @@ class EquipmentCategory(models.Model):
|
|||
if current.parent == self:
|
||||
self.parent = None
|
||||
done = True
|
||||
elif current.parent == None:
|
||||
elif current.parent is None:
|
||||
done = True
|
||||
current = current.parent
|
||||
return super().save(*args, **kwargs)
|
||||
|
@ -76,7 +74,8 @@ class EquipmentCategory(models.Model):
|
|||
class EquipmentQuerySet(models.QuerySet):
|
||||
def in_category(self, cat):
|
||||
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:
|
||||
filtre |= Q(category__id=pk)
|
||||
return self.filter(filtre)
|
||||
|
@ -102,6 +101,7 @@ class Equipment(EventSpecificMixin, models.Model):
|
|||
verbose_name=_("propriétaire"),
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=models.SET_NULL,
|
||||
)
|
||||
category = models.ForeignKey(
|
||||
EquipmentCategory,
|
||||
|
@ -134,9 +134,9 @@ class Equipment(EventSpecificMixin, models.Model):
|
|||
return []
|
||||
res = list(map(lambda x: x+1, range(self.stock)))
|
||||
for lost in self.losts.all():
|
||||
res = [ x
|
||||
for x in res
|
||||
if x not in lost.ids ]
|
||||
res = [x
|
||||
for x in res
|
||||
if x not in lost.ids]
|
||||
# TODO cassé
|
||||
# TODO utilisés
|
||||
return res
|
||||
|
@ -144,9 +144,9 @@ class Equipment(EventSpecificMixin, models.Model):
|
|||
def ids_lost(self):
|
||||
res = []
|
||||
for lost in self.losts.all():
|
||||
res = res + [ x
|
||||
for x in lost.ids
|
||||
if x not in res]
|
||||
res = res + [x
|
||||
for x in lost.ids
|
||||
if x not in res]
|
||||
return res
|
||||
|
||||
def stock_aviable(self):
|
||||
|
@ -162,17 +162,15 @@ class Equipment(EventSpecificMixin, models.Model):
|
|||
full_category.short_description = _("Chemin complet")
|
||||
ids_aviable.short_description = _("disponibles")
|
||||
ids_lost.short_description = _("perdus")
|
||||
stock_aviable.short_description= _("quantité disponible")
|
||||
stock_aviable.short_description = _("quantité disponible")
|
||||
stock_lost.short_description = _("quantité perdue")
|
||||
|
||||
full_category_p= property(full_category)
|
||||
ids_aviable_p= property(ids_aviable)
|
||||
ids_lost_p= property(ids_lost)
|
||||
stock_aviable_p= property(stock_aviable)
|
||||
full_category_p = property(full_category)
|
||||
ids_aviable_p = property(ids_aviable)
|
||||
ids_lost_p = property(ids_lost)
|
||||
stock_aviable_p = property(stock_aviable)
|
||||
stock_lost_p = property(stock_lost)
|
||||
|
||||
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("matériel")
|
||||
verbose_name_plural = _("matériels")
|
||||
|
@ -195,6 +193,7 @@ class EquipmentAttribute(models.Model):
|
|||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class EquipmentAttributeValue(models.Model):
|
||||
equipment = models.ForeignKey(
|
||||
Equipment,
|
||||
|
@ -223,8 +222,15 @@ class EquipmentAttributeValue(models.Model):
|
|||
|
||||
|
||||
class EquipmentAttribution(models.Model):
|
||||
equipment = models.ForeignKey(Equipment, verbose_name=_("matériel"))
|
||||
activity = models.ForeignKey(Activity)
|
||||
equipment = models.ForeignKey(
|
||||
Equipment,
|
||||
verbose_name=_("matériel"),
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
activity = models.ForeignKey(
|
||||
Activity,
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
amount = models.BigIntegerField(_("quantité attribuée"))
|
||||
remarks = models.TextField(
|
||||
_("remarques concernant l'attribution"),
|
||||
|
@ -241,7 +247,8 @@ class EquipmentAttribution(models.Model):
|
|||
self.activity.get_herited('title'))
|
||||
|
||||
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
|
||||
|
||||
super(EquipmentAttribution, self).save(*args, **kwargs)
|
||||
|
|
|
@ -56,7 +56,7 @@ INSTALLED_APPS = [
|
|||
'django.contrib.sites',
|
||||
|
||||
# 'channels',
|
||||
'rest_framework',
|
||||
# 'rest_framework',
|
||||
'bootstrapform',
|
||||
'widget_tweaks',
|
||||
'taggit',
|
||||
|
@ -71,8 +71,7 @@ INSTALLED_APPS = [
|
|||
'allauth_cas',
|
||||
'allauth_ens.providers.clipper',
|
||||
|
||||
|
||||
'api',
|
||||
# 'api',
|
||||
'communication',
|
||||
'equipment',
|
||||
'event',
|
||||
|
@ -80,7 +79,7 @@ INSTALLED_APPS = [
|
|||
'users',
|
||||
]
|
||||
|
||||
MIDDLEWARE_CLASSES = [
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
|
@ -184,7 +183,7 @@ AUTHENTICATION_BACKENDS = (
|
|||
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_IGNORE_REFERER = True
|
||||
CAS_REDIRECT_URL = reverse_lazy('shared:home')
|
||||
|
@ -213,7 +212,5 @@ SOCIALACCOUNT_PROVIDERS = {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
ACCOUNT_ADAPTER = 'shared.allauth_adapter.AccountAdapter'
|
||||
SOCIALACCOUNT_ADAPTER = 'shared.allauth_adapter.SocialAccountAdapter'
|
||||
|
|
|
@ -12,9 +12,9 @@ DEBUG = True
|
|||
|
||||
# Add some debugging tools
|
||||
INSTALLED_APPS += ["debug_toolbar", "debug_panel"] # NOQA
|
||||
MIDDLEWARE_CLASSES = (
|
||||
MIDDLEWARE = (
|
||||
["debug_panel.middleware.DebugPanelMiddleware"]
|
||||
+ MIDDLEWARE_CLASSES # NOQA
|
||||
+ MIDDLEWARE # NOQA
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ class EventSpecificMixin(models.Model):
|
|||
verbose_name=_("évènement"),
|
||||
help_text=_("Si spécifié, l'instance du modèle"
|
||||
"est spécifique à l'évènement en question"),
|
||||
on_delete=models.CASCADE,
|
||||
blank=True,
|
||||
null=True
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue