Commit b19157cdf721099dff3c65ae02d2e56c749f77f1
Exists in
master
and in
3 other branches
fixed conflict on view
Showing
14 changed files
with
224 additions
and
275 deletions
Show diff stats
amadeus/static/css/base/amadeus.css
@@ -60,31 +60,51 @@ | @@ -60,31 +60,51 @@ | ||
60 | /* category app starts */ | 60 | /* category app starts */ |
61 | 61 | ||
62 | .panel-invisible{ | 62 | .panel-invisible{ |
63 | - background-color: #BDBDBD; | 63 | + background-color: #BDBDBD; |
64 | +} | ||
65 | + | ||
66 | +.category-panel > .panel-heading { | ||
67 | + background-color: #0277BD !important; | ||
68 | +} | ||
69 | +.category-panel > .panel-heading, .subject-panel > .panel-heading, .special-panel > .panel-heading { | ||
70 | + padding: 2px 0px; | ||
71 | +} | ||
72 | + | ||
73 | +.subject-panel > .panel-heading { | ||
74 | + background-color: #039BE5 !important; | ||
75 | +} | ||
76 | + | ||
77 | +.subject-group { | ||
78 | + margin-left: 20px; | ||
64 | } | 79 | } |
65 | 80 | ||
66 | .category-header > h4{ | 81 | .category-header > h4{ |
67 | - float:left; | ||
68 | - margin-top: 0.5%; | 82 | + float:left; |
83 | + margin-top: 5px; | ||
84 | + margin-bottom: 2px; | ||
69 | } | 85 | } |
70 | 86 | ||
87 | +.category-header > h4 > a:focus { | ||
88 | + text-decoration: none; | ||
89 | +} | ||
71 | 90 | ||
91 | +.category-card-items { | ||
92 | + padding-right: 0px; | ||
93 | +} | ||
72 | .category-card-items i{ | 94 | .category-card-items i{ |
73 | font-size: 25px !important; | 95 | font-size: 25px !important; |
74 | - margin-right: 5%; | ||
75 | - margin-top: 1%; | 96 | + margin-right: 10px; |
97 | + margin-top: 6px; | ||
76 | } | 98 | } |
99 | + | ||
77 | .category-header i{ | 100 | .category-header i{ |
78 | color: white; | 101 | color: white; |
79 | - | ||
80 | font-size: 20px; | 102 | font-size: 20px; |
81 | float: right; | 103 | float: right; |
82 | - | ||
83 | - | ||
84 | } | 104 | } |
85 | 105 | ||
86 | .category-header i:hover{ | 106 | .category-header i:hover{ |
87 | - color: #90CAF9; | 107 | + color: #90CAF9; |
88 | } | 108 | } |
89 | 109 | ||
90 | 110 | ||
@@ -94,6 +114,7 @@ | @@ -94,6 +114,7 @@ | ||
94 | 114 | ||
95 | .cat-selector { | 115 | .cat-selector { |
96 | margin: 0; | 116 | margin: 0; |
117 | + top: -2px; | ||
97 | } | 118 | } |
98 | 119 | ||
99 | #create-category{ | 120 | #create-category{ |
@@ -118,8 +139,8 @@ | @@ -118,8 +139,8 @@ | ||
118 | 139 | ||
119 | #core-subjects-options-div{ | 140 | #core-subjects-options-div{ |
120 | width: 100%; | 141 | width: 100%; |
121 | - margin-bottom: 2%; | ||
122 | - height: 30px; | 142 | + margin-bottom: 10px; |
143 | + height: 50px; | ||
123 | } | 144 | } |
124 | 145 | ||
125 | .core-subjects-options li{ | 146 | .core-subjects-options li{ |
amadeus/templates/base.html
@@ -70,7 +70,7 @@ | @@ -70,7 +70,7 @@ | ||
70 | <span class="icon-bar"></span> | 70 | <span class="icon-bar"></span> |
71 | <span class="icon-bar"></span> | 71 | <span class="icon-bar"></span> |
72 | </button> | 72 | </button> |
73 | - <a class="navbar-brand" href="{% url 'categories:index' %}"> | 73 | + <a class="navbar-brand" href="{% url 'subjects:home' %}"> |
74 | <img class="logo pull-left" src="{% static 'img/topo-amadeus-white.png' %}" alt="Logo" /> | 74 | <img class="logo pull-left" src="{% static 'img/topo-amadeus-white.png' %}" alt="Logo" /> |
75 | <span class="pull-right project_name">Projeto Amadeus</span> | 75 | <span class="pull-right project_name">Projeto Amadeus</span> |
76 | </a> | 76 | </a> |
amadeus/templates/pagination.html
1 | -<div class="row-fluid"> | ||
2 | - <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12 text-center"> | ||
3 | - <ul class="pagination"> | ||
4 | - {% for page_number in paginator.page_range %} | ||
5 | - <li{% if page_obj.number == page_number %} class="active"{% endif %}> | ||
6 | - <a href="?page={{ page_number }}{{ getvars }}">{{ page_number }}</a> | ||
7 | - </li> | ||
8 | - {% endfor %} | ||
9 | - </ul> | 1 | +{% if paginator.count > 0 %} |
2 | + <div class="row-fluid"> | ||
3 | + <div class="col-md-12 col-lg-12 col-sm-12 col-xs-12 text-center"> | ||
4 | + <ul class="pagination"> | ||
5 | + {% for page_number in paginator.page_range %} | ||
6 | + <li{% if page_obj.number == page_number %} class="active"{% endif %}> | ||
7 | + <a href="?page={{ page_number }}{{ getvars }}">{{ page_number }}</a> | ||
8 | + </li> | ||
9 | + {% endfor %} | ||
10 | + </ul> | ||
11 | + </div> | ||
10 | </div> | 12 | </div> |
11 | -</div> | ||
12 | \ No newline at end of file | 13 | \ No newline at end of file |
14 | +{% endif %} | ||
13 | \ No newline at end of file | 15 | \ No newline at end of file |
categories/templates/categories/list.html
1 | {% extends 'categories/home.html' %} | 1 | {% extends 'categories/home.html' %} |
2 | 2 | ||
3 | -{% load static i18n permission_tags %} | 3 | +{% load static i18n pagination %} |
4 | {% load django_bootstrap_breadcrumbs %} | 4 | {% load django_bootstrap_breadcrumbs %} |
5 | 5 | ||
6 | {% block javascript%} | 6 | {% block javascript%} |
@@ -38,24 +38,22 @@ | @@ -38,24 +38,22 @@ | ||
38 | <div class="col-md-12 cards-content"> | 38 | <div class="col-md-12 cards-content"> |
39 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> | 39 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> |
40 | {% for category in categories %} | 40 | {% for category in categories %} |
41 | - {% if category.visible %} | ||
42 | - | ||
43 | - | ||
44 | - <div class="panel panel-info"> | ||
45 | - <div class="panel-heading"> | ||
46 | - <div class="row"> | ||
47 | - <div class="col-md-12 category-header"> | ||
48 | - <h4 class="panel-title"> | ||
49 | - <a class="category-course-link pull-left" data-parent="#accordion" data-toggle="collapse" href="#{{category.slug}}"> | ||
50 | - <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}} | ||
51 | - </a> | ||
52 | - </h4> | ||
53 | - {% if user.is_staff or user in category.coordinators.all %} | ||
54 | - <div class=" divMoreActions"> | ||
55 | - <div class="btn-group"> | ||
56 | - <button class="btn btn-default btn-sm dropdown-toggle" type="button" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | ||
57 | - <i class="fa fa-ellipsis-v fa-2x" aria-hidden="true"></i> | ||
58 | - </button> | 41 | + {% if category.visible %} |
42 | + <div class="panel panel-info category-panel"> | ||
43 | + <div class="panel-heading"> | ||
44 | + <div class="row"> | ||
45 | + <div class="col-md-12 category-header"> | ||
46 | + <h4 class="panel-title"> | ||
47 | + <a class="category-course-link pull-left" data-parent="#accordion" data-toggle="collapse" href="#{{category.slug}}"> | ||
48 | + <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}} | ||
49 | + </a> | ||
50 | + </h4> | ||
51 | + | ||
52 | + <div class="col-md-5 pull-right category-card-items"> | ||
53 | + {% if user.is_staff or user in category.coordinators.all %} | ||
54 | + <a href="" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | ||
55 | + <i class="fa fa-ellipsis-v" aria-hidden="true"></i> | ||
56 | + </a> | ||
59 | <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> | 57 | <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> |
60 | {% if user.is_staff %} | 58 | {% if user.is_staff %} |
61 | <li><a href="{% url 'categories:replicate' category.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>{% trans 'Replicate' %}</a></li> | 59 | <li><a href="{% url 'categories:replicate' category.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>{% trans 'Replicate' %}</a></li> |
@@ -63,79 +61,56 @@ | @@ -63,79 +61,56 @@ | ||
63 | <li><a href="{% url 'categories:update' category.slug %}"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> | 61 | <li><a href="{% url 'categories:update' category.slug %}"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> |
64 | <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> | 62 | <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> |
65 | </ul> | 63 | </ul> |
66 | - </div> | ||
67 | - </div> | ||
68 | - {% else %} | ||
69 | - <div class=" divMoreActions"> | ||
70 | - </div> | ||
71 | - {% endif %} | ||
72 | - | ||
73 | - <div class="col-md-5 pull-right category-card-items"> | 64 | + {% endif %} |
74 | <a href="" ><i class="fa fa-list" aria-hidden="true"></i></a> | 65 | <a href="" ><i class="fa fa-list" aria-hidden="true"></i></a> |
75 | <a href=""><i class="fa fa-envelope-o" aria-hidden="true"></i></a> | 66 | <a href=""><i class="fa fa-envelope-o" aria-hidden="true"></i></a> |
76 | <a href=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></a> | 67 | <a href=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></a> |
77 | <a href=""><i class="fa fa-bar-chart" aria-hidden="true"></i></a> | 68 | <a href=""><i class="fa fa-bar-chart" aria-hidden="true"></i></a> |
78 | </div> | 69 | </div> |
79 | - | 70 | + </div> |
80 | </div> | 71 | </div> |
81 | </div> | 72 | </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 user in category.coordinators.all %} | ||
97 | - <a href="{% url 'subjects:create' category.slug %}"><button class="create-subject-btn"> {% trans "Create new subject" %} </button></a> | ||
98 | - {% endif %} | ||
99 | - <div class="panel-group" id="subject-accordion" role="tablist" aria-multiselectable="true"> | ||
100 | - {% for subject in category.subjects %} | ||
101 | - {% include "subjects/subject_card.html" %} | ||
102 | - {% endfor %} | ||
103 | - </div> | ||
104 | - | ||
105 | - | ||
106 | - </div> | 73 | + <div id="{{category.slug}}" class="panel-collapse panel-body collapse category-panel-content"> |
74 | + <input type="hidden" class="log_url" value="{% url 'categories:view_log' category.id %}" /> | ||
75 | + <input type="hidden" class="log_id" value="" /> | ||
76 | + | ||
77 | + {% if category.coordinators.all|length > 0 %} | ||
78 | + <h4><b>{% trans "Coordinator(s) " %}: </b> | ||
79 | + {{ category.coordinators.all|join:', ' }} | ||
80 | + </h4> | ||
81 | + {% else %} | ||
82 | + <h4> {% trans "It doesn't possess coordinators" %} </h4> | ||
83 | + {% endif %} | ||
84 | + | ||
85 | + {{category.description|safe}} | ||
86 | + | ||
87 | + {% if user in category.coordinators.all %} | ||
88 | + <a href="{% url 'subjects:create' category.slug %}"><button class="create-subject-btn"> {% trans "Create new subject" %} </button></a> | ||
89 | + {% endif %} | ||
107 | 90 | ||
108 | - | ||
109 | - | ||
110 | - | ||
111 | - {% comment %} | ||
112 | - <div id="{{category.slug}}" class="panel-collapse collapse"> | ||
113 | - {% for subject in subjects %} | ||
114 | - {% include "categories/category_card.html" %} | ||
115 | - {% endfor %} | 91 | + <div class="panel-group subject-group" id="{{ category.slug }}-accordion" role="tablist" aria-multiselectable="true"> |
92 | + {% for subject in category.subject_category.all %} | ||
93 | + {% include "subjects/subject_card.html" %} | ||
94 | + {% endfor %} | ||
95 | + </div> | ||
116 | </div> | 96 | </div> |
117 | - {% endcomment %} | ||
118 | - </div> | ||
119 | - | 97 | + </div> |
120 | {% elif request.user in category.coordinators.all or request.user.is_staff %} | 98 | {% elif request.user in category.coordinators.all or request.user.is_staff %} |
99 | + <div class="panel panel-invisible special-panel"> | ||
100 | + <div class="panel-heading"> | ||
101 | + <div class="row"> | ||
102 | + <div class="col-md-12 category-header"> | ||
103 | + <h4 class="panel-title"> | ||
104 | + <a class="category-course-link pull-left" data-parent="#accordion" data-toggle="collapse" href="#{{category.slug}}"> | ||
105 | + <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}} | ||
106 | + </a> | ||
107 | + </h4> | ||
121 | 108 | ||
122 | - | ||
123 | - | ||
124 | - <div class="panel panel-invisible"> | ||
125 | - <div class="panel-heading"> | ||
126 | - <div class="row"> | ||
127 | - <div class="col-md-12 category-header"> | ||
128 | - <h4 class="panel-title"> | ||
129 | - <a class="category-course-link pull-left" data-parent="#accordion" data-toggle="collapse" href="#{{category.slug}}"> | ||
130 | - <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}} | ||
131 | - </a> | ||
132 | - </h4> | ||
133 | - {% if user.is_staff or user in category.coordinators.all %} | ||
134 | - <div class=" divMoreActions"> | ||
135 | - <div class="btn-group"> | ||
136 | - <button class="btn btn-default btn-sm dropdown-toggle" type="button" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | ||
137 | - <i class="fa fa-ellipsis-v fa-2x" aria-hidden="true"></i> | ||
138 | - </button> | 109 | + <div class="col-md-5 pull-right category-card-items"> |
110 | + {% if user.is_staff or user in category.coordinators.all %} | ||
111 | + <a href="" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | ||
112 | + <i class="fa fa-ellipsis-v" aria-hidden="true"></i> | ||
113 | + </a> | ||
139 | <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> | 114 | <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> |
140 | {% if user.is_staff %} | 115 | {% if user.is_staff %} |
141 | <li><a href="{% url 'categories:replicate' category.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>{% trans 'Replicate' %}</a></li> | 116 | <li><a href="{% url 'categories:replicate' category.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>{% trans 'Replicate' %}</a></li> |
@@ -143,62 +118,43 @@ | @@ -143,62 +118,43 @@ | ||
143 | <li><a href="{% url 'categories:update' category.slug %}"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> | 118 | <li><a href="{% url 'categories:update' category.slug %}"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> |
144 | <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> | 119 | <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> |
145 | </ul> | 120 | </ul> |
146 | - </div> | ||
147 | - </div> | ||
148 | - {% else %} | ||
149 | - <div class=" divMoreActions"> | ||
150 | - </div> | ||
151 | - {% endif %} | ||
152 | - | ||
153 | - <div class="col-md-5 pull-right category-card-items"> | 121 | + {% endif %} |
154 | <a href="" ><i class="fa fa-list" aria-hidden="true"></i></a> | 122 | <a href="" ><i class="fa fa-list" aria-hidden="true"></i></a> |
155 | <a href=""><i class="fa fa-envelope-o" aria-hidden="true"></i></a> | 123 | <a href=""><i class="fa fa-envelope-o" aria-hidden="true"></i></a> |
156 | <a href=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></a> | 124 | <a href=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></a> |
157 | <a href=""><i class="fa fa-bar-chart" aria-hidden="true"></i></a> | 125 | <a href=""><i class="fa fa-bar-chart" aria-hidden="true"></i></a> |
158 | </div> | 126 | </div> |
159 | - | 127 | + </div> |
160 | </div> | 128 | </div> |
161 | </div> | 129 | </div> |
162 | - </div> | ||
163 | - <div id="{{category.slug}}" class="panel-collapse panel-body collapse category-panel-content"> | ||
164 | - <input type="hidden" class="log_url" value="{% url 'categories:view_log' category.id %}" /> | ||
165 | - <input type="hidden" class="log_id" value="" /> | ||
166 | - {% if category.coordinators.all|length > 0 %} | ||
167 | - <h4><b>{% trans "Coordinator(s) " %}: </b> | ||
168 | - {{ category.coordinators.all|join:', ' }} | ||
169 | - </h4> | ||
170 | - {% else %} | ||
171 | - <h4> {% trans "It doesn't possess coordinators" %} </h4> | ||
172 | - {% endif %} | ||
173 | - | ||
174 | - {{category.description|safe}} | ||
175 | - | ||
176 | - {% if user in category.coordinators.all %} | ||
177 | - <a href="{% url 'subjects:create' category.slug %}"><button class="create-subject-btn"> {% trans "Create new subject" %} </button></a> | ||
178 | - {% endif %} | ||
179 | - <div class="panel-group" id="subject-accordion" role="tablist" aria-multiselectable="true"> | ||
180 | - {% for subject in category.subjects %} | ||
181 | - {% include "subjects/subject_card.html" %} | ||
182 | - {% endfor %} | 130 | + <div id="{{category.slug}}" class="panel-collapse panel-body collapse category-panel-content"> |
131 | + <input type="hidden" class="log_url" value="{% url 'categories:view_log' category.id %}" /> | ||
132 | + <input type="hidden" class="log_id" value="" /> | ||
133 | + | ||
134 | + {% if category.coordinators.all|length > 0 %} | ||
135 | + <h4><b>{% trans "Coordinator(s) " %}: </b> | ||
136 | + {{ category.coordinators.all|join:', ' }} | ||
137 | + </h4> | ||
138 | + {% else %} | ||
139 | + <h4> {% trans "It doesn't possess coordinators" %} </h4> | ||
140 | + {% endif %} | ||
141 | + | ||
142 | + {{category.description|safe}} | ||
143 | + | ||
144 | + {% if user in category.coordinators.all %} | ||
145 | + <a href="{% url 'subjects:create' category.slug %}"><button class="create-subject-btn"> {% trans "Create new subject" %} </button></a> | ||
146 | + {% endif %} | ||
147 | + | ||
148 | + <div class="panel-group subject-group" id="{{ category.slug }}-accordion" role="tablist" aria-multiselectable="true"> | ||
149 | + {% for subject in category.subject_category.all %} | ||
150 | + {% include "subjects/subject_card.html" %} | ||
151 | + {% endfor %} | ||
152 | + </div> | ||
183 | </div> | 153 | </div> |
184 | - | ||
185 | - | ||
186 | </div> | 154 | </div> |
187 | - | ||
188 | - | ||
189 | - | ||
190 | - | ||
191 | - {% comment %} | ||
192 | - <div id="{{category.slug}}" class="panel-collapse collapse"> | ||
193 | - {% for subject in subjects %} | ||
194 | - {% include "categories/category_card.html" %} | ||
195 | - {% endfor %} | ||
196 | - </div> | ||
197 | - {% endcomment %} | ||
198 | - </div> | ||
199 | - | ||
200 | {% endif %} | 155 | {% endif %} |
201 | {% endfor %} | 156 | {% endfor %} |
157 | + {% pagination request paginator page_obj %} | ||
202 | </div> | 158 | </div> |
203 | </div> | 159 | </div> |
204 | <div id="modal_course"> | 160 | <div id="modal_course"> |
categories/views.py
@@ -31,11 +31,11 @@ class IndexView(views.SuperuserRequiredMixin, LoginRequiredMixin, ListView): | @@ -31,11 +31,11 @@ class IndexView(views.SuperuserRequiredMixin, LoginRequiredMixin, ListView): | ||
31 | queryset = Category.objects.all() | 31 | queryset = Category.objects.all() |
32 | template_name = 'categories/list.html' | 32 | template_name = 'categories/list.html' |
33 | context_object_name = 'categories' | 33 | context_object_name = 'categories' |
34 | + paginate_by = 10 | ||
34 | 35 | ||
35 | def get_queryset(self): | 36 | def get_queryset(self): |
36 | result = super(IndexView, self).get_queryset() | 37 | result = super(IndexView, self).get_queryset() |
37 | 38 | ||
38 | - | ||
39 | return result | 39 | return result |
40 | 40 | ||
41 | def render_to_response(self, context, **response_kwargs): | 41 | def render_to_response(self, context, **response_kwargs): |
log/admin.py
@@ -3,7 +3,7 @@ from django.contrib import admin | @@ -3,7 +3,7 @@ from django.contrib import admin | ||
3 | from .models import Log | 3 | from .models import Log |
4 | 4 | ||
5 | class LogAdmin(admin.ModelAdmin): | 5 | class LogAdmin(admin.ModelAdmin): |
6 | - list_display = ['datetime', 'user', 'action', 'resource', 'context'] | 6 | + list_display = ['datetime', 'user', 'user_email', 'action', 'resource', 'context'] |
7 | search_fields = ['user', 'action', 'resource'] | 7 | search_fields = ['user', 'action', 'resource'] |
8 | 8 | ||
9 | admin.site.register(Log, LogAdmin) | 9 | admin.site.register(Log, LogAdmin) |
10 | \ No newline at end of file | 10 | \ No newline at end of file |
log/decorators.py
@@ -16,7 +16,9 @@ def log_decorator(log_component = '', log_action = '', log_resource = ''): | @@ -16,7 +16,9 @@ def log_decorator(log_component = '', log_action = '', log_resource = ''): | ||
16 | if request.user.is_authenticated: | 16 | if request.user.is_authenticated: |
17 | 17 | ||
18 | log = Log() | 18 | log = Log() |
19 | - log.user = request.user | 19 | + log.user = str(request.user) |
20 | + log.user_id = request.user.id | ||
21 | + log.user_email = request.user.email | ||
20 | log.component = log_component | 22 | log.component = log_component |
21 | log.context = request.log_context | 23 | log.context = request.log_context |
22 | log.action = log_action | 24 | log.action = log_action |
@@ -41,7 +43,9 @@ def log_decorator_ajax(log_component = '', log_action = '', log_resource = ''): | @@ -41,7 +43,9 @@ def log_decorator_ajax(log_component = '', log_action = '', log_resource = ''): | ||
41 | if request.user.is_authenticated: | 43 | if request.user.is_authenticated: |
42 | 44 | ||
43 | log = Log() | 45 | log = Log() |
44 | - log.user = request.user | 46 | + log.user = str(request.user) |
47 | + log.user_id = request.user.id | ||
48 | + log.user_email = request.user.email | ||
45 | log.component = log_component | 49 | log.component = log_component |
46 | log.context = "" | 50 | log.context = "" |
47 | log.action = log_action | 51 | log.action = log_action |
log/migrations/0001_initial.py
1 | # -*- coding: utf-8 -*- | 1 | # -*- coding: utf-8 -*- |
2 | -# Generated by Django 1.10 on 2016-12-29 20:07 | 2 | +# Generated by Django 1.10 on 2017-01-04 21:26 |
3 | from __future__ import unicode_literals | 3 | from __future__ import unicode_literals |
4 | 4 | ||
5 | -from django.conf import settings | ||
6 | import django.contrib.postgres.fields.jsonb | 5 | import django.contrib.postgres.fields.jsonb |
7 | from django.db import migrations, models | 6 | from django.db import migrations, models |
8 | -import django.db.models.deletion | ||
9 | 7 | ||
10 | 8 | ||
11 | class Migration(migrations.Migration): | 9 | class Migration(migrations.Migration): |
@@ -13,7 +11,6 @@ class Migration(migrations.Migration): | @@ -13,7 +11,6 @@ class Migration(migrations.Migration): | ||
13 | initial = True | 11 | initial = True |
14 | 12 | ||
15 | dependencies = [ | 13 | dependencies = [ |
16 | - migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
17 | ] | 14 | ] |
18 | 15 | ||
19 | operations = [ | 16 | operations = [ |
@@ -25,12 +22,14 @@ class Migration(migrations.Migration): | @@ -25,12 +22,14 @@ class Migration(migrations.Migration): | ||
25 | ('context', django.contrib.postgres.fields.jsonb.JSONField(blank=True, verbose_name='Context')), | 22 | ('context', django.contrib.postgres.fields.jsonb.JSONField(blank=True, verbose_name='Context')), |
26 | ('action', models.TextField(verbose_name='Action')), | 23 | ('action', models.TextField(verbose_name='Action')), |
27 | ('resource', models.TextField(verbose_name='Resource')), | 24 | ('resource', models.TextField(verbose_name='Resource')), |
25 | + ('user', models.CharField(max_length=100, verbose_name='Actor')), | ||
26 | + ('user_id', models.IntegerField(verbose_name='Actor id')), | ||
27 | + ('user_email', models.EmailField(max_length=254, verbose_name='Actor Mail')), | ||
28 | ('datetime', models.DateTimeField(auto_now_add=True, verbose_name='Date and Time of action')), | 28 | ('datetime', models.DateTimeField(auto_now_add=True, verbose_name='Date and Time of action')), |
29 | - ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='Actor')), | ||
30 | ], | 29 | ], |
31 | options={ | 30 | options={ |
32 | - 'verbose_name_plural': 'Logs', | ||
33 | 'verbose_name': 'Log', | 31 | 'verbose_name': 'Log', |
32 | + 'verbose_name_plural': 'Logs', | ||
34 | }, | 33 | }, |
35 | ), | 34 | ), |
36 | ] | 35 | ] |
log/mixins.py
@@ -12,7 +12,9 @@ class LogMixin(object): | @@ -12,7 +12,9 @@ class LogMixin(object): | ||
12 | 12 | ||
13 | def createLog(self, actor = None, component = '', log_action = '', log_resource = '', context = {}): | 13 | def createLog(self, actor = None, component = '', log_action = '', log_resource = '', context = {}): |
14 | log = Log() | 14 | log = Log() |
15 | - log.user = actor | 15 | + log.user = str(actor) |
16 | + log.user_id = actor.id | ||
17 | + log.user_email = actor.email | ||
16 | log.context = context | 18 | log.context = context |
17 | log.component = component | 19 | log.component = component |
18 | log.action = log_action | 20 | log.action = log_action |
log/models.py
@@ -9,7 +9,9 @@ class Log(models.Model): | @@ -9,7 +9,9 @@ class Log(models.Model): | ||
9 | context = JSONField(_('Context'), blank = True) | 9 | context = JSONField(_('Context'), blank = True) |
10 | action = models.TextField(_('Action')) | 10 | action = models.TextField(_('Action')) |
11 | resource = models.TextField(_('Resource')) | 11 | resource = models.TextField(_('Resource')) |
12 | - user = models.ForeignKey(User, verbose_name = _('Actor')) | 12 | + user = models.CharField(_('Actor'), max_length = 100) |
13 | + user_id = models.IntegerField(_('Actor id')) | ||
14 | + user_email = models.EmailField(_('Actor Mail')) | ||
13 | datetime = models.DateTimeField(_("Date and Time of action"), auto_now_add = True) | 15 | datetime = models.DateTimeField(_("Date and Time of action"), auto_now_add = True) |
14 | 16 | ||
15 | class Meta: | 17 | class Meta: |
subjects/templates/subjects/initial.html
1 | {% extends "categories/home.html" %} | 1 | {% extends "categories/home.html" %} |
2 | 2 | ||
3 | +{% load pagination %} | ||
4 | + | ||
3 | {% block content %} | 5 | {% block content %} |
4 | 6 | ||
5 | <div id="" class="col-md-12"> | 7 | <div id="" class="col-md-12"> |
6 | <div class="users-cloud"> | 8 | <div class="users-cloud"> |
7 | - <ul class=" users-cloud"> | ||
8 | - {% for user in users %} | ||
9 | - <li>{{user.social_name}}</li> | ||
10 | - {% endfor %} | ||
11 | - </ul> | 9 | + <ul class=" users-cloud"> |
10 | + {% for user in users %} | ||
11 | + <li>{{user.social_name}}</li> | ||
12 | + {% endfor %} | ||
13 | + </ul> | ||
12 | </div> | 14 | </div> |
13 | </div> | 15 | </div> |
16 | + | ||
14 | <div class="col-md-12 cards-content"> | 17 | <div class="col-md-12 cards-content"> |
15 | <div class="panel-group" id="subject-accordion" role="tablist" aria-multiselectable="true"> | 18 | <div class="panel-group" id="subject-accordion" role="tablist" aria-multiselectable="true"> |
16 | - {% for subject in subjects %} | ||
17 | - {% include "subjects/subject_card.html" %} | ||
18 | - {% endfor %} | 19 | + {% for subject in subjects %} |
20 | + {% include "subjects/subject_card.html" with accordion_id="subject-accordion" %} | ||
21 | + {% endfor %} | ||
19 | </div> | 22 | </div> |
20 | </div> | 23 | </div> |
21 | 24 | ||
22 | - | ||
23 | - <div class="pagination"> | ||
24 | - <span class="page-links"> | ||
25 | - {% if subjects.has_previous %} | ||
26 | - <a href="?page={{ subjects.previous_page_number }}">previous</a> | ||
27 | - {% endif %} | ||
28 | - <span class="page-current"> | ||
29 | - Page {{ subjects.number }} of {{ subjects.paginator.num_pages }}. | ||
30 | - </span> | ||
31 | - {% if subjects.has_next %} | ||
32 | - <a href="?page={{ subjects.next_page_number }}">next</a> | ||
33 | - {% endif %} | ||
34 | - </span> | ||
35 | - </div> | 25 | + {% pagination request paginator page_obj %} |
36 | 26 | ||
37 | {% endblock content %} | 27 | {% endblock content %} |
38 | \ No newline at end of file | 28 | \ No newline at end of file |
subjects/templates/subjects/list.html
1 | {% extends 'categories/home.html' %} | 1 | {% extends 'categories/home.html' %} |
2 | 2 | ||
3 | -{% load static i18n permission_tags %} | 3 | +{% load static i18n pagination %} |
4 | {% load django_bootstrap_breadcrumbs %} | 4 | {% load django_bootstrap_breadcrumbs %} |
5 | 5 | ||
6 | {% block javascript%} | 6 | {% block javascript%} |
@@ -42,7 +42,7 @@ | @@ -42,7 +42,7 @@ | ||
42 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> | 42 | <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> |
43 | {% for category in categories %} | 43 | {% for category in categories %} |
44 | {% if category.visible %} | 44 | {% if category.visible %} |
45 | - <div class="panel panel-info"> | 45 | + <div class="panel panel-info category-panel"> |
46 | <div class="panel-heading"> | 46 | <div class="panel-heading"> |
47 | <div class="row"> | 47 | <div class="row"> |
48 | <div class="col-md-12 category-header"> | 48 | <div class="col-md-12 category-header"> |
@@ -51,27 +51,20 @@ | @@ -51,27 +51,20 @@ | ||
51 | <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}} | 51 | <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}} |
52 | </a> | 52 | </a> |
53 | </h4> | 53 | </h4> |
54 | - {% if user.is_staff or user in category.coordinators.all %} | ||
55 | - <div class=" divMoreActions"> | ||
56 | - <div class="btn-group"> | ||
57 | - <button class="btn btn-default btn-sm dropdown-toggle" type="button" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | ||
58 | - <i class="fa fa-ellipsis-v fa-2x" aria-hidden="true"></i> | ||
59 | - </button> | ||
60 | - <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> | ||
61 | - {% if user.is_staff %} | ||
62 | - <li><a href="{% url 'categories:replicate' category.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>{% trans 'Replicate' %}</a></li> | ||
63 | - {% endif %} | ||
64 | - <li><a href="{% url 'categories:update' category.slug %}"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> | ||
65 | - <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> | ||
66 | - </ul> | ||
67 | - </div> | ||
68 | - </div> | ||
69 | - {% else %} | ||
70 | - <div class=" divMoreActions"> | ||
71 | - </div> | ||
72 | - {% endif %} | ||
73 | 54 | ||
74 | <div class="col-md-5 pull-right category-card-items"> | 55 | <div class="col-md-5 pull-right category-card-items"> |
56 | + {% if user.is_staff or user in category.coordinators.all %} | ||
57 | + <a href="" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | ||
58 | + <i class="fa fa-ellipsis-v" aria-hidden="true"></i> | ||
59 | + </a> | ||
60 | + <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> | ||
61 | + {% if user.is_staff %} | ||
62 | + <li><a href="{% url 'categories:replicate' category.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>{% trans 'Replicate' %}</a></li> | ||
63 | + {% endif %} | ||
64 | + <li><a href="{% url 'categories:update' category.slug %}"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> | ||
65 | + <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> | ||
66 | + </ul> | ||
67 | + {% endif %} | ||
75 | <a href="" ><i class="fa fa-list" aria-hidden="true"></i></a> | 68 | <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> | 69 | <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> | 70 | <a href=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></a> |
@@ -97,7 +90,7 @@ | @@ -97,7 +90,7 @@ | ||
97 | <a href="{% url 'subjects:create' category.slug %}"><button class="create-subject-btn"> {% trans "Create new subject" %} </button></a> | 90 | <a href="{% url 'subjects:create' category.slug %}"><button class="create-subject-btn"> {% trans "Create new subject" %} </button></a> |
98 | {% endif %} | 91 | {% endif %} |
99 | 92 | ||
100 | - <div class="panel-group" id="{{ category.slug }}-accordion" role="tablist" aria-multiselectable="true"> | 93 | + <div class="panel-group subject-group" id="{{ category.slug }}-accordion" role="tablist" aria-multiselectable="true"> |
101 | {% for subject in category.subject_category.all %} | 94 | {% for subject in category.subject_category.all %} |
102 | {% include "subjects/subject_card.html" %} | 95 | {% include "subjects/subject_card.html" %} |
103 | {% endfor %} | 96 | {% endfor %} |
@@ -105,7 +98,7 @@ | @@ -105,7 +98,7 @@ | ||
105 | </div> | 98 | </div> |
106 | </div> | 99 | </div> |
107 | {% elif request.user in category.coordinators.all %} | 100 | {% elif request.user in category.coordinators.all %} |
108 | - <div class="panel panel-danger"> | 101 | + <div class="panel panel-danger special-panel"> |
109 | <div class="panel-heading"> | 102 | <div class="panel-heading"> |
110 | <div class="row"> | 103 | <div class="row"> |
111 | <div class="col-md-12 category-header"> | 104 | <div class="col-md-12 category-header"> |
@@ -114,27 +107,20 @@ | @@ -114,27 +107,20 @@ | ||
114 | <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}} | 107 | <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}} |
115 | </a> | 108 | </a> |
116 | </h4> | 109 | </h4> |
117 | - {% if user.is_staff or user in category.coordinators.all %} | ||
118 | - <div class=" divMoreActions"> | ||
119 | - <div class="btn-group"> | ||
120 | - <button class="btn btn-default btn-sm dropdown-toggle" type="button" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | ||
121 | - <i class="fa fa-ellipsis-v fa-2x" aria-hidden="true"></i> | ||
122 | - </button> | ||
123 | - <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> | ||
124 | - {% if user.is_staff %} | ||
125 | - <li><a href="{% url 'categories:replicate' category.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>{% trans 'Replicate' %}</a></li> | ||
126 | - {% endif %} | ||
127 | - <li><a href="{% url 'categories:update' category.slug %}"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> | ||
128 | - <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> | ||
129 | - </ul> | ||
130 | - </div> | ||
131 | - </div> | ||
132 | - {% else %} | ||
133 | - <div class=" divMoreActions"> | ||
134 | - </div> | ||
135 | - {% endif %} | ||
136 | 110 | ||
137 | <div class="col-md-5 pull-right category-card-items"> | 111 | <div class="col-md-5 pull-right category-card-items"> |
112 | + {% if user.is_staff or user in category.coordinators.all %} | ||
113 | + <a href="" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | ||
114 | + <i class="fa fa-ellipsis-v" aria-hidden="true"></i> | ||
115 | + </a> | ||
116 | + <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> | ||
117 | + {% if user.is_staff %} | ||
118 | + <li><a href="{% url 'categories:replicate' category.slug %}"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>{% trans 'Replicate' %}</a></li> | ||
119 | + {% endif %} | ||
120 | + <li><a href="{% url 'categories:update' category.slug %}"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> | ||
121 | + <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> | ||
122 | + </ul> | ||
123 | + {% endif %} | ||
138 | <a href="" ><i class="fa fa-list" aria-hidden="true"></i></a> | 124 | <a href="" ><i class="fa fa-list" aria-hidden="true"></i></a> |
139 | <a href=""><i class="fa fa-envelope-o" aria-hidden="true"></i></a> | 125 | <a href=""><i class="fa fa-envelope-o" aria-hidden="true"></i></a> |
140 | <a href=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></a> | 126 | <a href=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></a> |
@@ -160,7 +146,7 @@ | @@ -160,7 +146,7 @@ | ||
160 | <a href="{% url 'subjects:create' category.slug %}"><button class="create-subject-btn"> {% trans "Create new subject" %} </button></a> | 146 | <a href="{% url 'subjects:create' category.slug %}"><button class="create-subject-btn"> {% trans "Create new subject" %} </button></a> |
161 | {% endif %} | 147 | {% endif %} |
162 | 148 | ||
163 | - <div class="panel-group" id="{{ category.slug }}-accordion" role="tablist" aria-multiselectable="true"> | 149 | + <div class="panel-group subject-group" id="{{ category.slug }}-accordion" role="tablist" aria-multiselectable="true"> |
164 | {% for subject in category.subject_category.all %} | 150 | {% for subject in category.subject_category.all %} |
165 | {% include "subjects/subject_card.html" %} | 151 | {% include "subjects/subject_card.html" %} |
166 | {% endfor %} | 152 | {% endfor %} |
@@ -169,6 +155,7 @@ | @@ -169,6 +155,7 @@ | ||
169 | </div> | 155 | </div> |
170 | {% endif %} | 156 | {% endif %} |
171 | {% endfor %} | 157 | {% endfor %} |
158 | + {% pagination request paginator page_obj %} | ||
172 | </div> | 159 | </div> |
173 | </div> | 160 | </div> |
174 | <div id="modal_course"> | 161 | <div id="modal_course"> |
subjects/templates/subjects/subject_card.html
1 | {% load static i18n permission_tags %} | 1 | {% load static i18n permission_tags %} |
2 | 2 | ||
3 | -<div class="panel panel-info"> | 3 | +<div class="panel panel-info subject-panel"> |
4 | <div class="panel-heading"> | 4 | <div class="panel-heading"> |
5 | <div class="row"> | 5 | <div class="row"> |
6 | <div class="col-md-12 category-header"> | 6 | <div class="col-md-12 category-header"> |
7 | <h4 class="panel-title"> | 7 | <h4 class="panel-title"> |
8 | - <a class="category-course-link pull-left" data-parent="#{{ subject.category.slug }}-accordion" data-toggle="collapse" href="#{{subject.slug}}"> | 8 | + <a class="category-course-link pull-left" data-parent="#{% if accordion_id %}{{ accordion_id }}{% else %}{{ subject.category.slug }}-accordion{% endif %}" data-toggle="collapse" href="#{{subject.slug}}"> |
9 | <button class="btn btn-default btn-xs text-center cat-selector"><i class="fa fa-angle-right fa-2x" aria-hidden="true"></i></button> {{subject.name}} | 9 | <button class="btn btn-default btn-xs text-center cat-selector"><i class="fa fa-angle-right fa-2x" aria-hidden="true"></i></button> {{subject.name}} |
10 | </a> | 10 | </a> |
11 | </h4> | 11 | </h4> |
12 | - {% if request.user in subject.professor.all or request.user in category.coordinators.all %} | ||
13 | - <div class="divMoreActions" > | ||
14 | - <div class="btn-group"> | ||
15 | - <button class="btn btn-default btn-sm dropdown-toggle" type="button" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | ||
16 | - <i class="fa fa-ellipsis-v fa-2x" aria-hidden="true"></i> | ||
17 | - </button> | ||
18 | - <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> | ||
19 | - <li><a href="#"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>{% trans 'Replicate' %}</a></li> | ||
20 | - <li><a href="#"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> | ||
21 | - <li><a href="#"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li> | ||
22 | - </ul> | ||
23 | - </div> | ||
24 | - </div> | ||
25 | - {% endif %} | 12 | + |
26 | <div class="col-md-5 pull-right category-card-items"> | 13 | <div class="col-md-5 pull-right category-card-items"> |
14 | + {% if request.user in subject.professor.all or request.user in category.coordinators.all %} | ||
15 | + <a href="" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | ||
16 | + <i class="fa fa-ellipsis-v" aria-hidden="true"></i> | ||
17 | + </a> | ||
18 | + <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> | ||
19 | + <li><a href="#"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i>{% trans 'Replicate' %}</a></li> | ||
20 | + <li><a href="#"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i>{% trans 'Edit' %}</a></li> | ||
21 | + <li><a href="#"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li> | ||
22 | + </ul> | ||
23 | + {% endif %} | ||
27 | <a href="" ><i class="fa fa-list" aria-hidden="true"></i></a> | 24 | <a href="" ><i class="fa fa-list" aria-hidden="true"></i></a> |
28 | <a href=""><i class="fa fa-envelope-o" aria-hidden="true"></i></a> | 25 | <a href=""><i class="fa fa-envelope-o" aria-hidden="true"></i></a> |
29 | <a href=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></a> | 26 | <a href=""><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></a> |
subjects/views.py
@@ -32,30 +32,26 @@ class HomeView(LoginRequiredMixin, ListView): | @@ -32,30 +32,26 @@ class HomeView(LoginRequiredMixin, ListView): | ||
32 | redirect_field_name = 'next' | 32 | redirect_field_name = 'next' |
33 | queryset = Subject.objects.all() | 33 | queryset = Subject.objects.all() |
34 | template_name = 'subjects/initial.html' | 34 | template_name = 'subjects/initial.html' |
35 | - | 35 | + context_object_name = 'subjects' |
36 | + paginate_by = 10 | ||
36 | 37 | ||
37 | - def get_context_data(self, **kwargs): | ||
38 | - context = super(HomeView, self).get_context_data(**kwargs) | 38 | + def get_queryset(self): |
39 | if self.request.user.is_staff: | 39 | if self.request.user.is_staff: |
40 | subjects = Subject.objects.all() | 40 | subjects = Subject.objects.all() |
41 | else: | 41 | else: |
42 | subjects = Subject.objects.all() | 42 | subjects = Subject.objects.all() |
43 | subjects = [subject for subject in subjects if self.request.user in subject.students.all() or self.request.user in subject.professor.all()] | 43 | subjects = [subject for subject in subjects if self.request.user in subject.students.all() or self.request.user in subject.professor.all()] |
44 | + | ||
44 | 45 | ||
45 | paginator = Paginator(subjects, 10) | 46 | paginator = Paginator(subjects, 10) |
46 | 47 | ||
47 | - page = self.request.GET.get('page') | ||
48 | - try: | ||
49 | - subjects = paginator.page(page) | ||
50 | - except PageNotAnInteger: | ||
51 | - # If page is not an integer, deliver first page. | ||
52 | - subjects = paginator.page(1) | ||
53 | 48 | ||
54 | - except EmptyPage: | ||
55 | - # If page is out of range (e.g. 9999), deliver last page of results. | ||
56 | - subjects = paginator.page(paginator.num_pages) | 49 | + return subjects |
57 | 50 | ||
58 | - context['subjects'] = subjects | 51 | + def get_context_data(self, **kwargs): |
52 | + context = super(HomeView, self).get_context_data(**kwargs) | ||
53 | + context['title'] = _('Home') | ||
54 | + | ||
59 | #bringing users | 55 | #bringing users |
60 | users = User.objects.all() | 56 | users = User.objects.all() |
61 | context['users'] = users | 57 | context['users'] = users |
@@ -69,11 +65,22 @@ class IndexView(LoginRequiredMixin, ListView): | @@ -69,11 +65,22 @@ class IndexView(LoginRequiredMixin, ListView): | ||
69 | queryset = Category.objects.all() | 65 | queryset = Category.objects.all() |
70 | template_name = 'subjects/list.html' | 66 | template_name = 'subjects/list.html' |
71 | context_object_name = 'categories' | 67 | context_object_name = 'categories' |
72 | - | 68 | + paginate_by = 10 |
73 | 69 | ||
74 | def get_queryset(self): | 70 | def get_queryset(self): |
75 | - result = super(IndexView, self).get_queryset() | ||
76 | - return result | 71 | + categories = Category.objects.all().order_by('name') |
72 | + | ||
73 | + if not self.request.user.is_staff: | ||
74 | + if not self.kwargs.get('option'): | ||
75 | + categories = Category.objects.filter(visible=True) | ||
76 | + | ||
77 | + for category in categories: | ||
78 | + category.subjects = Subject.objects.filter(category= category) | ||
79 | + | ||
80 | + categories = [category for category in categories if category.subjects.count() > 0 or self.request.user in category.coordinators.all()] | ||
81 | + #So I remove all categories that doesn't have the possibility for the user to be on | ||
82 | + | ||
83 | + return categories | ||
77 | 84 | ||
78 | def render_to_response(self, context, **response_kwargs): | 85 | def render_to_response(self, context, **response_kwargs): |
79 | if self.request.user.is_staff: | 86 | if self.request.user.is_staff: |
@@ -81,8 +88,6 @@ class IndexView(LoginRequiredMixin, ListView): | @@ -81,8 +88,6 @@ class IndexView(LoginRequiredMixin, ListView): | ||
81 | else: | 88 | else: |
82 | context['page_template'] = "categories/home_teacher_student.html" | 89 | context['page_template'] = "categories/home_teacher_student.html" |
83 | 90 | ||
84 | - | ||
85 | - | ||
86 | if self.request.is_ajax(): | 91 | if self.request.is_ajax(): |
87 | if self.request.user.is_staff: | 92 | if self.request.user.is_staff: |
88 | self.template_name = "categories/home_admin_content.html" | 93 | self.template_name = "categories/home_admin_content.html" |
@@ -101,22 +106,6 @@ class IndexView(LoginRequiredMixin, ListView): | @@ -101,22 +106,6 @@ class IndexView(LoginRequiredMixin, ListView): | ||
101 | context['all'] = True | 106 | context['all'] = True |
102 | context['title'] = _('All Subjects') | 107 | context['title'] = _('All Subjects') |
103 | 108 | ||
104 | - if self.request.user.is_staff: | ||
105 | - categories = self.get_queryset().order_by('name') | ||
106 | - else: | ||
107 | - if self.kwargs.get('option'): | ||
108 | - categories = self.get_queryset().order_by('name') | ||
109 | - for category in categories: | ||
110 | - category.subjects = Subject.objects.filter(category= category) | ||
111 | - else: | ||
112 | - categories = self.get_queryset().filter(visible=True) | ||
113 | - for category in categories: | ||
114 | - category.subjects = Subject.objects.filter(category= category) | ||
115 | - | ||
116 | - categories = [category for category in categories if category.subjects.count() > 0 or self.request.user in category.coordinators.all()] | ||
117 | - #So I remove all categories that doesn't have the possibility for the user to be on | ||
118 | - | ||
119 | - context['categories'] = categories | ||
120 | context['subjects_menu_active'] = 'subjects_menu_active' | 109 | context['subjects_menu_active'] = 'subjects_menu_active' |
121 | 110 | ||
122 | return context | 111 | return context |