From 2623502b7b7d25c288353bffbfa68019510b5244 Mon Sep 17 00:00:00 2001 From: Zambom Date: Fri, 21 Oct 2016 07:48:20 -0300 Subject: [PATCH] Subject subscribe tag filter [Issue: #195] --- courses/templates/course/view.html | 6 +++--- courses/templatetags/custom_filters.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 courses/templatetags/custom_filters.py diff --git a/courses/templates/course/view.html b/courses/templates/course/view.html index cb3e92d..d5519a1 100644 --- a/courses/templates/course/view.html +++ b/courses/templates/course/view.html @@ -1,6 +1,6 @@ {% extends 'home.html' %} -{% load static i18n permission_tags %} +{% load static i18n permission_tags custom_filters %} {% load django_bootstrap_breadcrumbs %} {% block style %} @@ -217,7 +217,7 @@ {% endif %} - {% if user|has_role:'student' and not user in subject.students.all and subject.show_subscribe %} + {% if user|show_subject_subscribe:subject %}
{% trans 'Subscribe' %}
@@ -269,7 +269,7 @@ {% endif %} - {% if user|has_role:'student' and not user in subject.students and subject.show_subscribe %} + {% if user|show_subject_subscribe:subject %}
{% trans 'Subscribe' %}
diff --git a/courses/templatetags/custom_filters.py b/courses/templatetags/custom_filters.py new file mode 100644 index 0000000..65661fd --- /dev/null +++ b/courses/templatetags/custom_filters.py @@ -0,0 +1,15 @@ +from django import template +from rolepermissions.verifications import has_role +import datetime + +register = template.Library() + +@register.filter +def show_subject_subscribe(user, subject): + if not user is None: + if user.is_authenticated: + if has_role(user, 'student'): + if not user in subject.students.all() and subject.show_subscribe: + return True + + return False \ No newline at end of file -- libgit2 0.21.2