Intranet app

This commit is contained in:
alazo 2018-07-29 11:40:40 +02:00
parent faef1e2caa
commit 9454d8de46
13 changed files with 820 additions and 1 deletions

36
intranet/models.py Normal file
View file

@ -0,0 +1,36 @@
from django.contrib.auth.models import User
from django.db import models
from django.db.models.signals import pre_delete
from django.dispatch import receiver
from cms.models import Module
# Create your models here.
class IntranetDoc(models.Model):
AUTHORIZATION_CHOICES = {
(0, 'aucun'),
(1, 'étudiant'),
(2, 'prof'),
(3, 'admin')
}
doc = models.FileField(upload_to='intranet', unique=True)
module = models.ForeignKey(Module, null=False, on_delete=models.PROTECT)
published = models.BooleanField(default=True, blank=False)
authorization = models.SmallIntegerField("autorisation", choices=AUTHORIZATION_CHOICES, default=0)
class Meta:
verbose_name = 'Intranet'
verbose_name_plural = 'Intranet'
def __str__(self):
return self.doc.name
@receiver(pre_delete, sender=IntranetDoc)
def remove_file(**kwargs):
instance = kwargs.get('instance')
instance.doc.delete(save=False)