diff --git a/intranet/templatetags/__init__.py b/intranet/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/intranet/templatetags/group_tags.py b/intranet/templatetags/group_tags.py new file mode 100644 index 0000000..e881662 --- /dev/null +++ b/intranet/templatetags/group_tags.py @@ -0,0 +1,9 @@ +from django import template +from django.contrib.auth.models import Group + +register = template.Library() + +@register.filter(name='has_group') +def has_group(user, group_name): + group = Group.objects.get(name=group_name) + return True if group in user.groups.all() else False \ No newline at end of file diff --git a/intranet/urls.py b/intranet/urls.py index a4f6d8f..6ea9f1a 100644 --- a/intranet/urls.py +++ b/intranet/urls.py @@ -3,5 +3,5 @@ from intranet import views urlpatterns = [ - path('list/', views.IntranetListView.as_view(), name='intranet-list'), + path('list//', views.IntranetListView.as_view(), name='intranet-list'), ] diff --git a/intranet/views.py b/intranet/views.py index 65c34ed..f61013a 100644 --- a/intranet/views.py +++ b/intranet/views.py @@ -12,7 +12,7 @@ class IntranetListView(LoginRequiredMixin, ListView): def get_queryset(self): groups = self.request.user.groups.values_list('name',flat=True) - qs = IntranetDoc.objects.filter(published=True) + qs = IntranetDoc.objects.filter(published=True, module=self.kwargs['module']) if self.request.user.is_superuser: qs = qs.filter(authorization__in=[1,2,3]) elif 'prof' in groups: diff --git a/templates/cms/module_detail.html b/templates/cms/module_detail.html index 1b11f3f..5477df0 100644 --- a/templates/cms/module_detail.html +++ b/templates/cms/module_detail.html @@ -87,7 +87,7 @@

Imprimer en PDF -     Documents de cours (connexion requise) +     Documents de cours (connexion requise)

{% endblock %} diff --git a/templates/intranet/list.html b/templates/intranet/list.html index 3b45da7..f6ec478 100644 --- a/templates/intranet/list.html +++ b/templates/intranet/list.html @@ -1,32 +1,42 @@ {% extends "cms/base_site.html" %} -{% load i18n static %} +{% load i18n static group_tags %} {% block extrastyle %} {{ block.super }} - {% endblock %} {% block content %}

Documents de cours

- {% regroup object_list by module as module_list %} - +
+
    +

    Documents Etudiant

    + {% for doc in object_list %} + {% if doc.authorization == 1 %} +
  1. {{ doc.doc.name }}
  2. + {% endif %} + {% empty %} +

    Aucun document disponible.

    + {% endfor %} +
+
+ {% if user|has_group:"prof" or user.is_staff %} +
+
    +

    Documents ENSEIGNANT

    + {% for doc in object_list %} + {% if doc.authorization == 2 %} +
  1. {{ doc.doc.name }}
  2. + {% endif %} + {% empty %} +

    Aucun document disponible.

    + {% endfor %} +
+
+ {% endif %} + {% if user.is_staff %} -
+

Gestion des documents

{% endif %}