Intranet app
This commit is contained in:
parent
faef1e2caa
commit
9454d8de46
13 changed files with 820 additions and 1 deletions
0
intranet/__init__.py
Normal file
0
intranet/__init__.py
Normal file
32
intranet/admin.py
Normal file
32
intranet/admin.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
|
||||
import os
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib import admin
|
||||
|
||||
from intranet.models import IntranetDoc
|
||||
|
||||
# Register your models here.
|
||||
|
||||
|
||||
class IntranetDocAdmin(admin.ModelAdmin):
|
||||
|
||||
list_display = ('__str__', 'module', 'authorization')
|
||||
|
||||
def save_model(self, request, obj, form, change):
|
||||
searched_file = 'intranet/{0}'.format(form.cleaned_data['doc'])
|
||||
try:
|
||||
doc = IntranetDoc.objects.get(doc=searched_file)
|
||||
form.save()
|
||||
# Override previous file
|
||||
filename = os.path.join(settings.MEDIA_ROOT, searched_file)
|
||||
file = request.FILES['doc']
|
||||
with open(filename, 'wb+') as destination:
|
||||
for chunk in file.chunks():
|
||||
destination.write(chunk)
|
||||
|
||||
except IntranetDoc.DoesNotExist:
|
||||
super(IntranetDocAdmin, self).save_model(request, obj, form, change)
|
||||
|
||||
|
||||
admin.site.register(IntranetDoc, IntranetDocAdmin)
|
||||
5
intranet/apps.py
Normal file
5
intranet/apps.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class IntranetConfig(AppConfig):
|
||||
name = 'intranet'
|
||||
0
intranet/migrations/__init__.py
Normal file
0
intranet/migrations/__init__.py
Normal file
36
intranet/models.py
Normal file
36
intranet/models.py
Normal 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)
|
||||
|
||||
|
||||
3
intranet/tests.py
Normal file
3
intranet/tests.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
Loading…
Add table
Add a link
Reference in a new issue