Commit e4fe963c3bf4656f04f90ca95a48d57234d0e9cf

Authored by Felipe Henrique de Almeida Bormann
2 parents b132ec2f 959899f1

fixed conflict of merge

amadeus/static/css/base/amadeus.css
... ... @@ -603,4 +603,12 @@ ul, li {
603 603 .form-group input[type=file] {
604 604 margin-top: 20px;
605 605 height: initial;
  606 +}
  607 +
  608 +.no-subjects i {
  609 + font-size: 50px;
  610 +}
  611 +.no-subjects h4 {
  612 + font-family: Roboto;
  613 + font-weight: normal;
606 614 }
607 615 \ No newline at end of file
... ...
amadeus/static/css/themes/black.css
... ... @@ -267,4 +267,13 @@ a, a:focus, a:hover {
267 267 .filedrag {
268 268 color: #555;
269 269 border: 2px dashed #555;
  270 +}
  271 +
  272 +.footer {
  273 + color: #FFFFFF;
  274 + background: #26A69A;
  275 +}
  276 +
  277 +.no-subjects {
  278 + color: #999999;
270 279 }
271 280 \ No newline at end of file
... ...
amadeus/static/css/themes/green.css
... ... @@ -272,4 +272,8 @@ a, a:focus, a:hover {
272 272 .footer {
273 273 color: #FFFFFF;
274 274 background: #26A69A;
  275 +}
  276 +
  277 +.no-subjects {
  278 + color: #999999;
275 279 }
276 280 \ No newline at end of file
... ...
amadeus/static/css/themes/red.css
... ... @@ -267,4 +267,13 @@ a, a:focus, a:hover {
267 267 .filedrag {
268 268 color: #555;
269 269 border: 2px dashed #555;
  270 +}
  271 +
  272 +.footer {
  273 + color: #FFFFFF;
  274 + background: #26A69A;
  275 +}
  276 +
  277 +.no-subjects {
  278 + color: #999999;
270 279 }
271 280 \ No newline at end of file
... ...
subjects/forms.py
... ... @@ -54,22 +54,32 @@ class CreateSubjectForm(forms.ModelForm):
54 54 if not new_tag in self.instance.tags.all():
55 55 self.instance.tags.add(new_tag)
56 56  
57   - #self.instance.save()
58   -
59 57 return self.instance
60 58  
61   - def clean(self):
62   - cleaned_data = super(CreateSubjectForm, self).clean()
63   - print("este")
64   - if cleaned_data['subscribe_begin'] > cleaned_data['end_date']:
65   - raise forms.ValidationError(_('Subscribe period should be between course time'))
66   - return cleaned_data
  59 + # def clean(self):
  60 + # cleaned_data = super(CreateSubjectForm, self).clean()
  61 + # print("este")
  62 + # if cleaned_data['subscribe_begin'] > cleaned_data['end_date']:
  63 + # self._errors['subscribe_begin'] = [_('Subscribe period should be between course time')]
  64 +
  65 + # return ValueError
  66 +
  67 + # return cleaned_data
  68 +
67 69 def clean_subscribe_begin(self):
68 70 subscribe_begin = self.cleaned_data['subscribe_begin']
  71 + end_date = self.cleaned_data['end_date']
  72 +
69 73 if subscribe_begin < datetime.datetime.today().date():
70   - print("aqui")
71   - self._errors['subscribe_begin'] = _('this date must be today or after')
  74 + self._errors['subscribe_begin'] = [_('this date must be today or after')]
  75 +
72 76 return ValueError
  77 +
  78 + if subscribe_begin > end_date:
  79 + self._errors['subscribe_begin'] = [_('Subscribe period should be between course time')]
  80 +
  81 + return ValueError
  82 +
73 83 return subscribe_begin
74 84  
75 85 class CreateTagForm(forms.ModelForm):
... ...
subjects/models.py
... ... @@ -49,10 +49,10 @@ class Subject(models.Model):
49 49 def __str__(self):
50 50 return self.name
51 51  
52   - def clean(self):
  52 + # def clean(self):
53 53  
54   - if self.subscribe_begin > self.end_date:
55   - raise ValidationError(_('Subscribe period should be between course time'))
  54 + # if self.subscribe_begin > self.end_date:
  55 + # raise ValidationError(_('Subscribe period should be between course time'))
56 56  
57 57  
58 58  
... ...
subjects/templates/subjects/initial.html
... ... @@ -27,14 +27,23 @@
27 27  
28 28 <div class="col-md-12 cards-content">
29 29 <h2 class=" my-subjects-title"><b><i>{% trans "Meus Assuntos" %}</i></b></h2>
30   - <div class="panel-group" id="subject-accordion" role="tablist" aria-multiselectable="true">
31   - {% for subject in subjects %}
32   - {% include "subjects/subject_card.html" with accordion_id="subject-accordion" %}
33   - {% endfor %}
34   - </div>
  30 +
  31 + {% if subjects|length > 0 %}
  32 + <div class="panel-group" id="subject-accordion" role="tablist" aria-multiselectable="true">
  33 + {% for subject in subjects %}
  34 + {% include "subjects/subject_card.html" with accordion_id="subject-accordion" %}
  35 + {% endfor %}
  36 +
  37 + {% pagination request paginator page_obj %}
  38 + </div>
  39 + {% else %}
  40 + <div class="text-center no-subjects">
  41 + <i class="fa fa-graduation-cap"></i>
  42 + <h4>{% trans 'You still do not posses any subject in our platform' %}</h4>
  43 + </div>
  44 + {% endif %}
35 45 </div>
36 46  
37   - {% pagination request paginator page_obj %}
38 47  
39 48 <script type="text/javascript" src="{% static 'js/course.js' %}"></script>
40 49 {% endblock content %}
41 50 \ No newline at end of file
... ...
subjects/templates/subjects/list.html
1 1 {% extends 'categories/home.html' %}
2 2  
3 3 {% load static i18n pagination %}
4   -{% load django_bootstrap_breadcrumbs %}
  4 +{% load django_bootstrap_breadcrumbs subject_counter %}
5 5  
6 6 {% block javascript%}
7 7 {{ block.super }}
... ... @@ -33,11 +33,11 @@
33 33 <div id="core-subjects-options-div">
34 34 <ul class="core-subjects-options">
35 35 {% if all %}
36   - <a href="{% url 'subjects:index' %}"><li >{% trans "My subjects" %}</li></a>
37   - <a href="{% url 'subjects:index' 'all' %}" ><li class="active">{% trans "All subjects" %}</li></a>
  36 + <a href="{% url 'subjects:index' %}"><li >{% trans "My subjects" %} ({{ totals.my_subjects }})</li></a>
  37 + <a href="{% url 'subjects:index' 'all' %}" ><li class="active">{% trans "All subjects" %} ({{ totals.all_subjects }})</li></a>
38 38 {% else %}
39   - <a href="{% url 'subjects:index' %}"><li class="active">{% trans "My subjects" %}</li></a>
40   - <a href="{% url 'subjects:index' 'all' %}" ><li>{% trans "All subjects" %}</li></a>
  39 + <a href="{% url 'subjects:index' %}"><li class="active">{% trans "My subjects" %} ({{ totals.my_subjects }})</li></a>
  40 + <a href="{% url 'subjects:index' 'all' %}" ><li>{% trans "All subjects" %} ({{ totals.all_subjects }})</li></a>
41 41 {% endif %}
42 42  
43 43 </ul>
... ... @@ -45,128 +45,134 @@
45 45  
46 46 <!-- Code for listing categories -->
47 47 <div class="col-md-12 cards-content">
48   - <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
49   - {% for category in categories %}
50   - {% if category.visible %}
51   - <div class="panel panel-info category-panel">
52   - <div class="panel-heading">
53   - <div class="row">
54   - <div class="col-md-12 category-header">
55   - <h4 class="panel-title">
56   - <a class="category-course-link pull-left" data-parent="#accordion" data-toggle="collapse" href="#{{category.slug}}">
57   - <button class="btn btn-default btn-xs text-center cat-selector"><i class="fa fa-angle-right fa-2x" aria-hidden="true"></i></button> {{category.name}}
58   - </a>
59   - </h4>
60   -
61   - <div class="col-md-5 pull-right category-card-items">
62   - {% if request.user.is_staff or user in category.coordinators.all %}
63   - <a href="" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
64   - <i class="fa fa-ellipsis-v" aria-hidden="true"></i>
  48 + {% if categories|length > 0 %}
  49 + <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
  50 + {% for category in categories %}
  51 + {% if category.visible %}
  52 + <div class="panel panel-info category-panel">
  53 + <div class="panel-heading">
  54 + <div class="row">
  55 + <div class="col-md-12 category-header">
  56 + <h4 class="panel-title">
  57 + <a class="category-course-link pull-left" data-parent="#accordion" data-toggle="collapse" href="#{{category.slug}}">
  58 + <button class="btn btn-default btn-xs text-center cat-selector"><i class="fa fa-angle-right fa-2x" aria-hidden="true"></i></button> {{ category.name }} ({{ category|subject_count:user }})
65 59 </a>
66   - <ul class="dropdown-menu pull-right" aria-labelledby="moreActions">
67   - {% if request.user.is_staff %}
68   - <li><a href="{% url 'categories:replicate' category.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i> {% trans 'Replicate' %}</a></li>
69   - {% endif %}
70   - <li><a href="{% url 'categories:update' category.slug %}"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i> {% trans 'Edit' %}</a></li>
71   - <li>
72   - <a href="javascript:delete_course.get('{% url 'categories:delete' category.slug %}?view=index','#category','#modal_course')" aria-hidden="true"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li>
73   - </ul>
74   - {% endif %}
75   - <a href="" ><i class="fa fa-list" aria-hidden="true"></i></a>
76   - <a href=""><i class="fa fa-envelope-o" aria-hidden="true"></i></a>
77   - <a href=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></a>
78   - <a href=""><i class="fa fa-bar-chart" aria-hidden="true"></i></a>
  60 + </h4>
  61 +
  62 + <div class="col-md-5 pull-right category-card-items">
  63 + {% if request.user.is_staff or user in category.coordinators.all %}
  64 + <a href="" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  65 + <i class="fa fa-ellipsis-v" aria-hidden="true"></i>
  66 + </a>
  67 + <ul class="dropdown-menu pull-right" aria-labelledby="moreActions">
  68 + {% if request.user.is_staff %}
  69 + <li><a href="{% url 'categories:replicate' category.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i> {% trans 'Replicate' %}</a></li>
  70 + {% endif %}
  71 + <li><a href="{% url 'categories:update' category.slug %}"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i> {% trans 'Edit' %}</a></li>
  72 + <li>
  73 + <a href="javascript:delete_course.get('{% url 'categories:delete' category.slug %}?view=index','#category','#modal_course')" aria-hidden="true"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li>
  74 + </ul>
  75 + {% endif %}
  76 + <a href="" ><i class="fa fa-list" aria-hidden="true"></i></a>
  77 + <a href=""><i class="fa fa-envelope-o" aria-hidden="true"></i></a>
  78 + <a href=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></a>
  79 + <a href=""><i class="fa fa-bar-chart" aria-hidden="true"></i></a>
  80 + </div>
79 81 </div>
80 82 </div>
81 83 </div>
82   - </div>
83   - <div id="{{category.slug}}" class="panel-collapse panel-body collapse category-panel-content">
84   - <input type="hidden" class="log_url" value="{% url 'categories:view_log' category.id %}" />
85   - <input type="hidden" class="log_id" value="" />
86   - {% if category.coordinators.all|length > 0 %}
87   - <h4><b>{% trans "Coordinator(s) " %}: </b>
88   - {{ category.coordinators.all|join:', ' }}
89   - </h4>
90   - {% else %}
91   - <h4> {% trans "It doesn't possess coordinators" %} </h4>
92   - {% endif %}
93   -
94   - {{category.description|safe}}
95   -
96   - {% if request.user in category.coordinators.all or request.user.is_staff %}
97   - <a href="{% url 'subjects:create' category.slug %}"><button class="create-subject-btn"> {% trans "Create new subject" %} </button></a>
98   - {% endif %}
  84 + <div id="{{category.slug}}" class="panel-collapse panel-body collapse category-panel-content">
  85 + <input type="hidden" class="log_url" value="{% url 'categories:view_log' category.id %}" />
  86 + <input type="hidden" class="log_id" value="" />
  87 + {% if category.coordinators.all|length > 0 %}
  88 + <h4><b>{% trans "Coordinator(s) " %}: </b>
  89 + {{ category.coordinators.all|join:', ' }}
  90 + </h4>
  91 + {% else %}
  92 + <h4> {% trans "It doesn't possess coordinators" %} </h4>
  93 + {% endif %}
  94 +
  95 + {{category.description|safe}}
99 96  
100   - <div class="panel-group subject-group" id="{{ category.slug }}-accordion" role="tablist" aria-multiselectable="true">
101   - {% for subject in category.subject_category.all %}
102   - {% if request.user in subject.students.all or request.user.is_staff or request.user in subject.professor.all or all or request.user in subject.category.coordinators.all %}
103   -
104   - {% include "subjects/subject_card.html" %}
105   - {% endif %}
106   - {% endfor %}
  97 + {% if request.user in category.coordinators.all or request.user.is_staff %}
  98 + <a href="{% url 'subjects:create' category.slug %}"><button class="create-subject-btn"> {% trans "Create new subject" %} </button></a>
  99 + {% endif %}
  100 +
  101 + <div class="panel-group subject-group" id="{{ category.slug }}-accordion" role="tablist" aria-multiselectable="true">
  102 + {% for subject in category.subject_category.all %}
  103 + {% if request.user in subject.students.all or request.user.is_staff or request.user in subject.professor.all or all or request.user in subject.category.coordinators.all %}
  104 + {% include "subjects/subject_card.html" %}
  105 + {% endif %}
  106 + {% endfor %}
  107 + </div>
107 108 </div>
108 109 </div>
109   - </div>
110   - {% elif request.user in category.coordinators.all or request.user.is_staff %}
111   - <div class="panel special-panel">
112   - <div class="panel-heading panel-invisible">
113   - <div class="row">
114   - <div class="col-md-12 category-header">
115   - <h4 class="panel-title">
116   - <a class="category-course-link pull-left" data-parent="#accordion" data-toggle="collapse" href="#{{category.slug}}">
117   - <button class="btn btn-default btn-xs text-center cat-selector"><i class="fa fa-angle-right fa-2x" aria-hidden="true"></i></button> {{category.name}}
118   - </a>
119   - </h4>
120   -
121   - <div class="col-md-5 pull-right category-card-items">
122   - {% if request.user.is_staff or user in category.coordinators.all %}
123   - <a href="" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
124   - <i class="fa fa-ellipsis-v" aria-hidden="true"></i>
  110 + {% elif request.user in category.coordinators.all or request.user.is_staff %}
  111 + <div class="panel special-panel">
  112 + <div class="panel-heading panel-invisible">
  113 + <div class="row">
  114 + <div class="col-md-12 category-header">
  115 + <h4 class="panel-title">
  116 + <a class="category-course-link pull-left" data-parent="#accordion" data-toggle="collapse" href="#{{category.slug}}">
  117 + <button class="btn btn-default btn-xs text-center cat-selector"><i class="fa fa-angle-right fa-2x" aria-hidden="true"></i></button> {{category.name}} ({{ category|subject_count:user }})
125 118 </a>
126   - <ul class="dropdown-menu pull-right" aria-labelledby="moreActions">
127   - {% if request.user.is_staff %}
128   - <li><a href="{% url 'categories:replicate' category.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i> {% trans 'Replicate' %}</a></li>
129   - {% endif %}
130   - <li><a href="{% url 'categories:update' category.slug %}"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i> {% trans 'Edit' %}</a></li>
131   - <li><a href="javascript:delete_course.get('{% url 'categories:delete' category.slug %}?view=index','#category','#modal_course')"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li>
132   - </ul>
133   - {% endif %}
134   - <a href="" ><i class="fa fa-list" aria-hidden="true"></i></a>
135   - <a href=""><i class="fa fa-envelope-o" aria-hidden="true"></i></a>
136   - <a href=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></a>
137   - <a href=""><i class="fa fa-bar-chart" aria-hidden="true"></i></a>
  119 + </h4>
  120 +
  121 + <div class="col-md-5 pull-right category-card-items">
  122 + {% if request.user.is_staff or user in category.coordinators.all %}
  123 + <a href="" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  124 + <i class="fa fa-ellipsis-v" aria-hidden="true"></i>
  125 + </a>
  126 + <ul class="dropdown-menu pull-right" aria-labelledby="moreActions">
  127 + {% if request.user.is_staff %}
  128 + <li><a href="{% url 'categories:replicate' category.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i> {% trans 'Replicate' %}</a></li>
  129 + {% endif %}
  130 + <li><a href="{% url 'categories:update' category.slug %}"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i> {% trans 'Edit' %}</a></li>
  131 + <li><a href="javascript:delete_course.get('{% url 'categories:delete' category.slug %}?view=index','#category','#modal_course')"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li>
  132 + </ul>
  133 + {% endif %}
  134 + <a href="" ><i class="fa fa-list" aria-hidden="true"></i></a>
  135 + <a href=""><i class="fa fa-envelope-o" aria-hidden="true"></i></a>
  136 + <a href=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></a>
  137 + <a href=""><i class="fa fa-bar-chart" aria-hidden="true"></i></a>
  138 + </div>
138 139 </div>
139 140 </div>
140 141 </div>
141   - </div>
142   - <div id="{{category.slug}}" class="panel-collapse panel-body collapse category-panel-content">
143   - <input type="hidden" class="log_url" value="{% url 'categories:view_log' category.id %}" />
144   - <input type="hidden" class="log_id" value="" />
145   - {% if category.coordinators.all|length > 0 %}
146   - <h4><b>{% trans "Coordinator(s) " %}: </b>
147   - {{ category.coordinators.all|join:', ' }}
148   - </h4>
149   - {% else %}
150   - <h4> {% trans "It doesn't possess coordinators" %} </h4>
151   - {% endif %}
152   -
153   - {{category.description|safe}}
154   -
155   - {% if request.user in category.coordinators.all or request.user.is_staff %}
156   - <a href="{% url 'subjects:create' category.slug %}"><button class="create-subject-btn"> {% trans "Create new subject" %} </button></a>
157   - {% endif %}
  142 + <div id="{{category.slug}}" class="panel-collapse panel-body collapse category-panel-content">
  143 + <input type="hidden" class="log_url" value="{% url 'categories:view_log' category.id %}" />
  144 + <input type="hidden" class="log_id" value="" />
  145 + {% if category.coordinators.all|length > 0 %}
  146 + <h4><b>{% trans "Coordinator(s) " %}: </b>
  147 + {{ category.coordinators.all|join:', ' }}
  148 + </h4>
  149 + {% else %}
  150 + <h4> {% trans "It doesn't possess coordinators" %} </h4>
  151 + {% endif %}
  152 +
  153 + {{category.description|safe}}
  154 +
  155 + {% if request.user in category.coordinators.all or request.user.is_staff %}
  156 + <a href="{% url 'subjects:create' category.slug %}"><button class="create-subject-btn"> {% trans "Create new subject" %} </button></a>
  157 + {% endif %}
158 158  
159   - <div class="panel-group subject-group" id="{{ category.slug }}-accordion" role="tablist" aria-multiselectable="true">
160   - {% for subject in category.subject_category.all %}
161   - {% include "subjects/subject_card.html" %}
162   - {% endfor %}
  159 + <div class="panel-group subject-group" id="{{ category.slug }}-accordion" role="tablist" aria-multiselectable="true">
  160 + {% for subject in category.subject_category.all %}
  161 + {% include "subjects/subject_card.html" %}
  162 + {% endfor %}
  163 + </div>
163 164 </div>
164 165 </div>
165   - </div>
166   - {% endif %}
167   - {% endfor %}
168   - {% pagination request paginator page_obj %}
169   - </div>
  166 + {% endif %}
  167 + {% endfor %}
  168 + {% pagination request paginator page_obj %}
  169 + </div>
  170 + {% else %}
  171 + <div class="text-center no-subjects">
  172 + <i class="fa fa-graduation-cap"></i>
  173 + <h4>{% trans 'You still do not posses any subject in our platform' %}</h4>
  174 + </div>
  175 + {% endif %}
170 176 </div>
171 177 <div id="modal_course">
172 178 </div>
... ...
subjects/templates/subjects/subject_card.html
... ... @@ -33,7 +33,7 @@
33 33 <div class="row">
34 34 <div class="col-md-6">
35 35 {% if subject.professor.all|length > 0 %}
36   - <h4><b>{% trans "Professors(s) " %}: </b>
  36 + <h4><b>{% trans "Professor(s) " %}: </b>
37 37 {{ subject.professor.all|join:', ' }}
38 38 </h4>
39 39 {% else %}
... ... @@ -94,7 +94,7 @@
94 94 <div class="row">
95 95 <div class="col-md-6">
96 96 {% if subject.professor.all|length > 0 %}
97   - <h4><b>{% trans "Professors(s) " %}: </b>
  97 + <h4><b>{% trans "Professor(s) " %}: </b>
98 98 {{ subject.professor.all|join:', ' }}
99 99 </h4>
100 100 {% else %}
... ... @@ -113,7 +113,7 @@
113 113 {% if show_buttons %}
114 114  
115 115 {% if request.user in subject.students.all or request.user in subject.professor.all or request.user.is_staff or request.user in subject.category.coordinators.all %}
116   - <a href="{% url 'subjects:view' subject.slug %}" class="access-subject btn btn-primary btn-raised"> {% trans "Access Subject" %}</a>
  116 + <a href="{% url 'subjects:view' subject.slug %}" class="btn btn-success btn-raised"> {% trans "Access Subject" %}</a>
117 117 {% else %}
118 118 <a href="#" class="subscribe-subject btn btn-primary btn-raised"> {% trans "Subscribe to Subject" %}</a>
119 119 {% endif %}
... ...
subjects/templatetags/__init__.py 0 → 100644
subjects/templatetags/subject_counter.py 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +from django import template
  2 +
  3 +register = template.Library()
  4 +
  5 +@register.filter(name = 'subject_count')
  6 +def subject_count(category, user):
  7 + total = 0
  8 +
  9 + for subject in category.subject_category.all():
  10 + if user in subject.students.all() or user in subject.professor.all() or user in subject.category.coordinators.all():
  11 + total += 1
  12 +
  13 + return total
0 14 \ No newline at end of file
... ...
subjects/utils.py
... ... @@ -12,4 +12,17 @@ def has_professor_profile(user, category):
12 12 if user in subject.professor.all():
13 13 return True
14 14  
15   - return False
16 15 \ No newline at end of file
  16 + return False
  17 +
  18 +def count_subjects(categories, user, all_subs = True):
  19 + total = 0
  20 +
  21 + for category in categories:
  22 + if not all_subs:
  23 + for subject in category.subject_category.all():
  24 + if user in subject.students.all() or user in subject.professor.all() or user in subject.category.coordinators.all():
  25 + total += 1
  26 + else:
  27 + total += category.subject_category.count()
  28 +
  29 + return total
17 30 \ No newline at end of file
... ...
subjects/views.py
... ... @@ -26,7 +26,7 @@ import time
26 26 import datetime
27 27 from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
28 28 from .forms import CreateSubjectForm
29   -from .utils import has_student_profile, has_professor_profile
  29 +from .utils import has_student_profile, has_professor_profile, count_subjects
30 30 from users.models import User
31 31  
32 32  
... ... @@ -42,12 +42,11 @@ class HomeView(LoginRequiredMixin, ListView):
42 42 subjects = Subject.objects.all().order_by("name")
43 43 else:
44 44  
  45 +
45 46 pk = self.request.user.pk
46 47  
47 48 subjects = Subject.objects.filter(students__pk=pk) | Subject.objects.filter(professor__pk=pk) | Subject.objects.filter(category__coordinators__pk=pk)
48 49  
49   -
50   -
51 50  
52 51 return subjects
53 52  
... ... @@ -63,6 +62,7 @@ class HomeView(LoginRequiredMixin, ListView):
63 62  
64 63  
65 64 class IndexView(LoginRequiredMixin, ListView):
  65 + totals = {}
66 66  
67 67 login_url = reverse_lazy("users:login")
68 68 redirect_field_name = 'next'
... ... @@ -73,13 +73,18 @@ class IndexView(LoginRequiredMixin, ListView):
73 73 def get_queryset(self):
74 74 categories = Category.objects.all().order_by('name')
75 75  
  76 + self.totals['all_subjects'] = count_subjects(categories, self.request.user)
  77 + self.totals['my_subjects'] = self.totals['all_subjects']
  78 +
76 79 if not self.request.user.is_staff:
77   - if not self.kwargs.get('option'):
78   - categories = Category.objects.all().order_by('name')
  80 + my_categories = [category for category in categories if self.request.user in category.coordinators.all() \
  81 + or has_professor_profile(self.request.user, category) or has_student_profile(self.request.user, category)]
  82 + #So I remove all categories that doesn't have the possibility for the user to be on
  83 +
  84 + self.totals['my_subjects'] = count_subjects(my_categories, self.request.user, False)
79 85  
80   - categories = [category for category in categories if self.request.user in category.coordinators.all() \
81   - or has_professor_profile(self.request.user, category) or has_student_profile(self.request.user, category)]
82   - #So I remove all categories that doesn't have the possibility for the user to be on
  86 + if not self.kwargs.get('option'):
  87 + categories = my_categories
83 88  
84 89 return categories
85 90  
... ... @@ -104,6 +109,7 @@ class IndexView(LoginRequiredMixin, ListView):
104 109 context['title'] = _('My Subjects')
105 110  
106 111 context['show_buttons'] = True #So it shows subscribe and access buttons
  112 + context['totals'] = self.totals
107 113  
108 114 if self.kwargs.get('option'):
109 115 context['all'] = True
... ... @@ -135,7 +141,7 @@ class SubjectCreateView(CreateView):
135 141 initial['name'] = subject.name
136 142 initial['visible'] = subject.visible
137 143 initial['professor'] = subject.professor.all()
138   - initial['tags'] = subject.tags.all()
  144 + initial['tags'] = ", ".join(subject.tags.all().values_list("name", flat = True))
139 145 initial['init_date'] = subject.init_date
140 146 initial['end_date'] = subject.end_date
141 147 initial['students'] = subject.students.all()
... ...