Commit 2623502b7b7d25c288353bffbfa68019510b5244

Authored by Zambom
1 parent 526896a8

Subject subscribe tag filter [Issue: #195]

courses/templates/course/view.html
1 1 {% extends 'home.html' %}
2 2  
3   -{% load static i18n permission_tags %}
  3 +{% load static i18n permission_tags custom_filters %}
4 4 {% load django_bootstrap_breadcrumbs %}
5 5  
6 6 {% block style %}
... ... @@ -217,7 +217,7 @@
217 217 </div>
218 218 {% endif %}
219 219  
220   - {% if user|has_role:'student' and not user in subject.students.all and subject.show_subscribe %}
  220 + {% if user|show_subject_subscribe:subject %}
221 221 <div class="col-xs-3 col-md-2">
222 222 <a onclick="subscribe($(this), '{% url 'course:subscribe_subject' subject.slug %}' , '{% trans 'Are you sure you want to subscribe to this subject?' %}')" class="btn btn-sm btn-primary btn-raised">{% trans 'Subscribe' %}</a>
223 223 </div>
... ... @@ -269,7 +269,7 @@
269 269 </div>
270 270 </div>
271 271 {% endif %}
272   - {% if user|has_role:'student' and not user in subject.students and subject.show_subscribe %}
  272 + {% if user|show_subject_subscribe:subject %}
273 273 <div class="col-xs-3 col-md-2">
274 274 <a onclick="subscribe($(this), '{% url 'course:subscribe_subject' subject.slug %}' , '{% trans 'Are you sure you want to subscribe to this subject?' %}')" class="btn btn-sm btn-primary btn-raised">{% trans 'Subscribe' %}</a>
275 275 </div>
... ...
courses/templatetags/custom_filters.py 0 → 100644
... ... @@ -0,0 +1,15 @@
  1 +from django import template
  2 +from rolepermissions.verifications import has_role
  3 +import datetime
  4 +
  5 +register = template.Library()
  6 +
  7 +@register.filter
  8 +def show_subject_subscribe(user, subject):
  9 + if not user is None:
  10 + if user.is_authenticated:
  11 + if has_role(user, 'student'):
  12 + if not user in subject.students.all() and subject.show_subscribe:
  13 + return True
  14 +
  15 + return False
0 16 \ No newline at end of file
... ...