This commit is contained in:
alazo 2018-09-01 10:31:54 +00:00 committed by GitHub
commit 56e22b5305
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 22 deletions

View file

View file

@ -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

View file

@ -3,5 +3,5 @@ from intranet import views
urlpatterns = [
path('list/', views.IntranetListView.as_view(), name='intranet-list'),
path('list/<int:module>/', views.IntranetListView.as_view(), name='intranet-list'),
]

View file

@ -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:

View file

@ -87,7 +87,7 @@
</table>
<p>
<a href="{% url 'module-pdf' object.id %}">Imprimer en PDF</a>
&nbsp;&nbsp; &nbsp;<a href="{% url 'intranet-list' %}">Documents de cours (connexion requise)</a>
&nbsp;&nbsp; &nbsp;<a href="{% url 'intranet-list' object.id %}">Documents de cours (connexion requise)</a>
</p>
</div>
{% endblock %}

View file

@ -1,32 +1,42 @@
{% extends "cms/base_site.html" %}
{% load i18n static %}
{% load i18n static group_tags %}
{% block extrastyle %}
{{ block.super }}
<style type="text/css">
ul li {float: none;}
</style>
{% endblock %}
{% block content %}
<div id="content-main">
<h1>Documents de cours</h1>
{% regroup object_list by module as module_list %}
<ul>
{% for module in module_list %}
<li><h3>{{ module.grouper }}</h3>
<div style="float:left; widht:500px">
<ol>
{% for doc in module.list %}
<li><a href="{{ doc.doc.url }}">{{ doc.doc.name }} ({{ doc.get_authorization_display }})</a></li>
<h3>Documents Etudiant</h3>
{% for doc in object_list %}
{% if doc.authorization == 1 %}
<li><a href="{{ doc.doc.url }}">{{ doc.doc.name }}</a></li>
{% endif %}
{% empty %}
<p><i>Aucun document disponible.</i></p>
{% endfor %}
</ol>
</li>
</div>
{% if user|has_group:"prof" or user.is_staff %}
<div style="margin-left:600px; width:500px">
<ol>
<h3>Documents ENSEIGNANT</h3>
{% for doc in object_list %}
{% if doc.authorization == 2 %}
<li><a href="{{ doc.doc.url }}">{{ doc.doc.name }}</a></li>
{% endif %}
{% empty %}
<p><i>Désolé, aucun document disponible pour le moment.</i></p>
<p><i>Aucun document disponible.</i></p>
{% endfor %}
</ul>
</ol>
</div>
{% endif %}
{% if user.is_staff %}
<hr>
<hr style="margin-top:100px">
<p><a href="{% url 'admin:intranet_intranetdoc_changelist' %}">Gestion des documents</a></p>
{% endif %}
</div>