Add intranet app
This commit is contained in:
parent
c96bd0d0db
commit
9773957baf
11 changed files with 167 additions and 1 deletions
33
intranet/views.py
Normal file
33
intranet/views.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.views.generic import ListView
|
||||
|
||||
from cms.models import Module
|
||||
from intranet.models import IntranetDoc
|
||||
|
||||
|
||||
class IntranetListView(LoginRequiredMixin, ListView):
|
||||
model = IntranetDoc
|
||||
template_name = 'intranet/list.html'
|
||||
login_url = '/login/'
|
||||
|
||||
def get_queryset(self):
|
||||
groups = self.request.user.groups.values_list('name',flat=True)
|
||||
qs = IntranetDoc.objects.filter(published=True)
|
||||
if self.request.user.is_superuser:
|
||||
qs = qs.filter(authorization__in=[1,2,3])
|
||||
if 'prof' in groups:
|
||||
qs = qs.filter(authorization__in=[1,2])
|
||||
if 'Student_1_year' in groups or 'Student_2_year' in groups or 'Student_3_year' in groups:
|
||||
modules = Module.objects.all().order_by('code')
|
||||
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]:
|
||||
modules_selected.append(mod.code)
|
||||
qs = qs.filter(module__code__in=modules_selected, authorization=1)
|
||||
else:
|
||||
return qs.none()
|
||||
Loading…
Add table
Add a link
Reference in a new issue