Commit 5db71839d31707b05a93f4d741abdae9b538ee0a

Authored by ailsoncgt
2 parents b6a5502c f6197106

Merge

core/templates/guest.html
1 1 {% extends 'base.html' %}
2 2  
  3 +{% load i18n custom_filters %}
  4 +
3 5 {% block breadcrumbs %}
4 6 <div class="col-md-12">
5 7 <form id="searchform" action="{% url 'course:manage' %}" method="get" accept-charset="utf-8">
... ... @@ -32,7 +34,14 @@
32 34 {% for course in courses %}
33 35 <div class="panel panel-info">
34 36 <div class="panel-heading">
35   - <h3 class="panel-title">{{course.name}}</h3>
  37 + <h3 class="panel-title">
  38 + {{course.name}}
  39 + {% if user|show_course_subscribe:course %}
  40 + <div class="pull-right" style="margin-top:-15px">
  41 + <a onclick="subscribe($(this), '{% url 'course:subscribe' course.slug %}' , '{% trans 'Are you sure you want to subscribe to this subject?' %}')" class="btn btn-sm btn-primary btn-raised">{% trans 'Subscribe' %}</a>
  42 + </div>
  43 + {% endif %}
  44 + </h3>
36 45 </div>
37 46  
38 47 <div class="panel-body">
... ...
courses/models.py
... ... @@ -57,6 +57,11 @@ class Course(models.Model):
57 57 def __str__(self):
58 58 return self.name
59 59  
  60 + def show_subscribe(self):
  61 + today = datetime.date.today()
  62 +
  63 + return today >= self.init_register_date and today <= self.end_register_date
  64 +
60 65 class Subject(models.Model):
61 66  
62 67 name = models.CharField(_('Name'), max_length = 100)
... ...
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,24 @@
  1 +from django import template
  2 +from rolepermissions.verifications import has_role
  3 +
  4 +register = template.Library()
  5 +
  6 +@register.filter
  7 +def show_subject_subscribe(user, subject):
  8 + if not user is None:
  9 + if user.is_authenticated:
  10 + if has_role(user, 'student'):
  11 + if not user in subject.students.all() and subject.show_subscribe:
  12 + return True
  13 +
  14 + return False
  15 +
  16 +@register.filter
  17 +def show_course_subscribe(user, course):
  18 + if not user is None:
  19 + if user.is_authenticated:
  20 + if has_role(user, 'student'):
  21 + if not user in course.students.all() and course.show_subscribe:
  22 + return True
  23 +
  24 + return False
0 25 \ No newline at end of file
... ...