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 = [ 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): def get_queryset(self):
groups = self.request.user.groups.values_list('name',flat=True) 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: if self.request.user.is_superuser:
qs = qs.filter(authorization__in=[1,2,3]) qs = qs.filter(authorization__in=[1,2,3])
elif 'prof' in groups: elif 'prof' in groups:

View file

@ -87,7 +87,7 @@
</table> </table>
<p> <p>
<a href="{% url 'module-pdf' object.id %}">Imprimer en PDF</a> <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> </p>
</div> </div>
{% endblock %} {% endblock %}

View file

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