Intranet app
This commit is contained in:
parent
cf3cf1748b
commit
faef1e2caa
12 changed files with 125 additions and 27 deletions
31
intranet/migrations/0001_Add_Intranet_app.py
Normal file
31
intranet/migrations/0001_Add_Intranet_app.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# Generated by Django 2.0.6 on 2018-07-28 11:31
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import intranet.models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('cms', '0009_drop_unneeded_defaults'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='IntranetDoc',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('doc', models.FileField(unique=True, upload_to='intranet')),
|
||||
('published', models.BooleanField(default=True)),
|
||||
('authorization', models.SmallIntegerField(choices=[(3, 'admin'), (0, 'aucun'), (1, 'étudiant'), (2, 'prof')], default=0, verbose_name='autorisation')),
|
||||
('module', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='cms.Module')),
|
||||
],
|
||||
options={
|
||||
'verbose_name': 'Intranet',
|
||||
'verbose_name_plural': 'Intranet',
|
||||
},
|
||||
),
|
||||
]
|
||||
10
intranet/urls.py
Normal file
10
intranet/urls.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
"""eds URL Configuration
|
||||
|
||||
"""
|
||||
from django.urls import path
|
||||
from intranet import views
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path('list/', views.IntranetListView.as_view(), name='intranet-list'),
|
||||
]
|
||||
39
intranet/views.py
Normal file
39
intranet/views.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
from django.conf import settings
|
||||
from django.views.generic import ListView
|
||||
from cms.models import Module
|
||||
from intranet.models import IntranetDoc
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
|
||||
|
||||
class IntranetListView(LoginRequiredMixin, ListView):
|
||||
|
||||
model = IntranetDoc
|
||||
template_name = 'intranet/list.html'
|
||||
login_url = '/login/'
|
||||
redirect_field_name = 'redirecto_to'
|
||||
|
||||
def get_queryset(self):
|
||||
modules = Module.objects.all().order_by('code')
|
||||
groups = self.request.user.groups.values_list('name',flat=True)
|
||||
|
||||
if self.request.user.is_superuser:
|
||||
return IntranetDoc.objects.filter(authorization__in=[1,2,3],
|
||||
published=True)
|
||||
if 'prof' in groups:
|
||||
return IntranetDoc.objects.filter(authorization__in=[1,2],
|
||||
published=True)
|
||||
if 'Student_1_year' in groups or 'Student_2_year' in groups or 'Student_3_year' in groups:
|
||||
modules_selected = []
|
||||
student_access = {'Student_1_year': [m for m in modules if m.sem1 > 0 or m.sem2 > 0],
|
||||
'Student_2_year': [m for m in modules if m.sem3 > 0 or m.sem4 > 0],
|
||||
'Student_3_year': [m for m in modules if m.sem5 > 0 or m.sem6 > 0]
|
||||
}
|
||||
|
||||
|
||||
for group in groups:
|
||||
for mod in student_access[group]: #settings.STUDENT_ACCESS[group]:
|
||||
modules_selected.append(mod.code)
|
||||
return IntranetDoc.objects.filter(module__code__in=modules_selected,
|
||||
authorization=1,
|
||||
published=True)
|
||||
return None
|
||||
Loading…
Add table
Add a link
Reference in a new issue