Commit ebb03c18 authored by Julien Palard's avatar Julien Palard
Browse files

Filter stats to teachers of their courses.

parent a378b09e
......@@ -4,7 +4,9 @@
<h2>Groups</h2>
<ul>
{% for group in object_list %}
{% if group.name != "prof" %}
<li><a href="{% url "stats" group.pk %}">{{ group.name }}</a></li>
{% endif %}
{% endfor %}
</ul>
{% endblock %}
......@@ -164,8 +164,12 @@ class StatsListView(UserPassesTestMixin, ListView):
template_name = "hkis/stats_list.html"
model = Group
def get_queryset(self):
self.queryset = self.request.user.groups.all()
return super().get_queryset()
def test_func(self):
return self.request.user.is_superuser
return self.request.user.groups.filter(name="prof").exists()
class StatsDetailView(UserPassesTestMixin, DetailView):
......@@ -174,8 +178,8 @@ class StatsDetailView(UserPassesTestMixin, DetailView):
def test_func(self):
return (
self.request.user.is_superuser
or self.request.user.groups.filter(name="prof").exists()
self.request.user.groups.filter(name="prof").exists()
and self.get_object() in self.request.user.groups.all()
)
def get_context_data(self, **kwargs):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment