Commit a16369f8f361433ed330b26c816452345d94d734
1 parent
30fcb26f
Exists in
master
and in
5 other branches
courses pagination #176
Showing
4 changed files
with
74 additions
and
170 deletions
Show diff stats
courses/templates/course/index.html
@@ -66,40 +66,32 @@ | @@ -66,40 +66,32 @@ | ||
66 | {% endif %} | 66 | {% endif %} |
67 | 67 | ||
68 | <div class="col-md-12"> | 68 | <div class="col-md-12"> |
69 | - <div class="input-group"> | ||
70 | - <div class="form-group is-empty"><input type="search" class="form-control" placeholder="Search Courses"></div> | ||
71 | - <span class="input-group-btn input-group-sm"> | ||
72 | - <button type="button" class="btn btn-fab btn-fab-mini"> | ||
73 | - <i class="material-icons">search</i> | ||
74 | - </button> | ||
75 | - </span> | ||
76 | - </div> | 69 | + <form id="searchform" action="{% url 'course:manage' %}" method="get" accept-charset="utf-8"> |
70 | + <div class="input-group"> | ||
71 | + <div class="form-group is-empty"> | ||
72 | + <input type="search" class="form-control" placeholder="Search Courses" name="q" id="searchbox"></div> | ||
73 | + <span class="input-group-btn input-group-sm"> | ||
74 | + <button type="button" class="btn btn-fab btn-fab-mini"> | ||
75 | + <i class="material-icons">search</i> | ||
76 | + </button> | ||
77 | + </span> | ||
78 | + </div> | ||
79 | + </form> | ||
77 | </div> | 80 | </div> |
78 | <div class="col-md-12"> | 81 | <div class="col-md-12"> |
79 | - {% if user|has_role:'professor, system_admin' %} | ||
80 | - <div class="btn-group btn-group-justified btn-group-raised"> | ||
81 | - <a href="?category=all" class="btn btn-raised btn-info">Todos</a> | ||
82 | - {% for category_course in categorys_courses_professor %} | ||
83 | - <a href="?category={{category_course.name}}" class="btn btn-raised btn-primary">{{category_course.name}}</a> | ||
84 | - {% endfor %} | ||
85 | - </div> | ||
86 | - {% else%} | ||
87 | - <div class="btn-group btn-group-justified btn-group-raised"> | ||
88 | - <a href="?category=all" class="btn btn-raised btn-info">Todos</a> | ||
89 | - {% for category_course in categorys_courses %} | ||
90 | - <a href="?category={{category_course.name}}" class="btn btn-raised btn-primary">{{category_course.name}}</a> | ||
91 | - {% endfor %} | ||
92 | - </div> | ||
93 | - {% endif %} | 82 | + <div class="btn-group btn-group-justified btn-group-raised"> |
83 | + <a href="?category=all" class="btn btn-raised btn-info">Todos</a> | ||
84 | + {% for category_course in categorys_courses %} | ||
85 | + <a href="?category={{category_course.name}}" class="btn btn-raised btn-primary">{{category_course.name}}</a> | ||
86 | + {% endfor %} | ||
87 | + </div> | ||
94 | </div> | 88 | </div> |
95 | 89 | ||
96 | </fieldset> | 90 | </fieldset> |
97 | -{% if user|has_role:'professor, system_admin' %} | ||
98 | <div class="col-md-12"> | 91 | <div class="col-md-12"> |
99 | {% if courses|length > 0 %} | 92 | {% if courses|length > 0 %} |
100 | {% if request.GET.category == 'all' or none or request.GET.category == '' %} | 93 | {% if request.GET.category == 'all' or none or request.GET.category == '' %} |
101 | - {% for course in courses_teacher %} | ||
102 | - <!-- Put your content here! --> | 94 | + {% for course in list_courses %} |
103 | <div class="panel-group ui-accordion ui-widget ui-helper-reset ui-sortable" id="accordion" role="tablist" aria-multiselectable="false"> | 95 | <div class="panel-group ui-accordion ui-widget ui-helper-reset ui-sortable" id="accordion" role="tablist" aria-multiselectable="false"> |
104 | <div class="group"> | 96 | <div class="group"> |
105 | <div class="panel panel-info"> | 97 | <div class="panel panel-info"> |
@@ -112,12 +104,6 @@ | @@ -112,12 +104,6 @@ | ||
112 | </div> | 104 | </div> |
113 | <div class="col-xs-4 col-md-3" id="divMoreActions"> | 105 | <div class="col-xs-4 col-md-3" id="divMoreActions"> |
114 | <div class="btn-group"> | 106 | <div class="btn-group"> |
115 | - <button type="button" class="btn btn-default btn-sm eye" data-toggle="tooltip" data-placement="bottom" title="Visible"> | ||
116 | - <i class="fa fa-eye fa-2x" aria-hidden="true"></i> | ||
117 | - </button> | ||
118 | - | ||
119 | - </div> | ||
120 | - <div class="btn-group"> | ||
121 | <button class="btn btn-default btn-sm dropdown-toggle" type="button" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | 107 | <button class="btn btn-default btn-sm dropdown-toggle" type="button" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> |
122 | <i class="fa fa-ellipsis-v fa-2x" aria-hidden="true"></i> | 108 | <i class="fa fa-ellipsis-v fa-2x" aria-hidden="true"></i> |
123 | </button> | 109 | </button> |
@@ -148,7 +134,7 @@ | @@ -148,7 +134,7 @@ | ||
148 | </div> | 134 | </div> |
149 | {% endfor %} | 135 | {% endfor %} |
150 | {% else %} | 136 | {% else %} |
151 | - {% for course in courses_teacher %} | 137 | + {% for course in courses_category %} |
152 | {% if course.category.name == request.GET.category %} | 138 | {% if course.category.name == request.GET.category %} |
153 | <!-- Put your content here! --> | 139 | <!-- Put your content here! --> |
154 | <div class="panel-group ui-accordion ui-widget ui-helper-reset ui-sortable" id="accordion" role="tablist" aria-multiselectable="false"> | 140 | <div class="panel-group ui-accordion ui-widget ui-helper-reset ui-sortable" id="accordion" role="tablist" aria-multiselectable="false"> |
@@ -221,125 +207,28 @@ | @@ -221,125 +207,28 @@ | ||
221 | </div> | 207 | </div> |
222 | </div> | 208 | </div> |
223 | </div> | 209 | </div> |
224 | - </div> | ||
225 | </div> | 210 | </div> |
226 | </div> | 211 | </div> |
227 | -{% else %} | ||
228 | - {% if courses|length > 0 %} | ||
229 | - {% if request.GET.category == 'all' or none or request.GET.category == '' %} | ||
230 | - {% for course in courses_student %} | ||
231 | - <div class="col-md-12"> | ||
232 | - <div class="panel panel-info"> | ||
233 | - <!--{% if course.image %} | ||
234 | - <img src="{{ course.image_url }}" class="img-responsive" /> | ||
235 | - {% else %} | ||
236 | - <img src="" class="img-responsive" /> | ||
237 | - {% endif %} --> | ||
238 | - <div class="panel-heading"> | ||
239 | - <div class="row"> | ||
240 | - <div class="col-md-9"> | ||
241 | - <h3 class="panel-title">{{course.name}}</h3> | ||
242 | - </div> | ||
243 | - <div class="col-md-3"> | ||
244 | - <span class="label label-info">{{ course.category }}</span> | ||
245 | - <span class="label label-warning">{{ course.max_students }} {% trans 'students tops' %}</span> | ||
246 | - </div> | ||
247 | - </div> | ||
248 | - </div> | ||
249 | - <div class="panel-body"> | ||
250 | - <p><b>Course Name: </b>{{ course.name }}</p> | ||
251 | - <p><b>Duration (in semesters): </b>09</p> | ||
252 | - <p><b>Coordinator: </b>{{course.professors}}</p> | ||
253 | - <p> | ||
254 | - <b>Description:</b> | ||
255 | - <i> | ||
256 | - {% if couse.description %} | ||
257 | - {{course.description|linebreaks}} | ||
258 | - {% else %} | ||
259 | - {% trans 'No description' %} | ||
260 | - {% endif %} | ||
261 | - </i> | ||
262 | - </p> | ||
263 | - | ||
264 | - <!--{% if user|has_role:'professor, system_admin' %} | ||
265 | - <a href="{% url 'course:update' course.slug %}" class="btn btn-sm btn-primary"> | ||
266 | - <span class="glyphicon glyphicon-edit"></span> | ||
267 | - </a> | ||
268 | - <a href="{% url 'course:delete' course.slug %}" class="btn btn-sm btn-danger"> | ||
269 | - <span class="glyphicon glyphicon-trash"></span> | ||
270 | - </a> | ||
271 | - {% endif %}--> | ||
272 | - | ||
273 | - <a href="{% url 'course:view' course.slug %}" class="btn btn-raised btn-default center-block">View Course</a> | ||
274 | - </div> | ||
275 | - </div> | ||
276 | - </div> | ||
277 | - {% endfor %} | ||
278 | - {% else %} | ||
279 | - {% for course in courses_student %} | ||
280 | - {% if course.category.name == request.GET.category %} | ||
281 | - <div class="col-md-12"> | ||
282 | - <div class="panel panel-info"> | ||
283 | - <!--{% if course.image %} | ||
284 | - <img src="{{ course.image_url }}" class="img-responsive" /> | ||
285 | - {% else %} | ||
286 | - <img src="" class="img-responsive" /> | ||
287 | - {% endif %} --> | ||
288 | - <div class="panel-heading"> | ||
289 | - <div class="row"> | ||
290 | - <div class="col-md-9"> | ||
291 | - <h3 class="panel-title">{{course.name}}</h3> | ||
292 | - </div> | ||
293 | - <div class="col-md-3"> | ||
294 | - <span class="label label-info">{{ course.category }}</span> | ||
295 | - <span class="label label-warning">{{ course.max_students }} {% trans 'students tops' %}</span> | ||
296 | - </div> | ||
297 | - </div> | ||
298 | - </div> | ||
299 | - <div class="panel-body"> | ||
300 | - <p><b>Course Name: </b>{{ course.name }}</p> | ||
301 | - <p><b>Duration (in semesters): </b>09</p> | ||
302 | - <p><b>Coordinator: </b>{{course.professors}}</p> | ||
303 | - <p> | ||
304 | - <b>Description:</b> | ||
305 | - <i> | ||
306 | - {% if couse.description %} | ||
307 | - {{course.description|linebreaks}} | ||
308 | - {% else %} | ||
309 | - {% trans 'No description' %} | ||
310 | - {% endif %} | ||
311 | - </i> | ||
312 | - </p> | ||
313 | - | ||
314 | - <!--{% if user|has_role:'professor, system_admin' %} | ||
315 | - <a href="{% url 'course:update' course.slug %}" class="btn btn-sm btn-primary"> | ||
316 | - <span class="glyphicon glyphicon-edit"></span> | ||
317 | - </a> | ||
318 | - <a href="{% url 'course:delete' course.slug %}" class="btn btn-sm btn-danger"> | ||
319 | - <span class="glyphicon glyphicon-trash"></span> | ||
320 | - </a> | ||
321 | - {% endif %}--> | ||
322 | - | ||
323 | - <a href="{% url 'course:view' course.slug %}" class="btn btn-raised btn-default center-block">View Course</a> | ||
324 | - </div> | ||
325 | - </div> | ||
326 | - </div> | 212 | + </div> |
213 | + <div class="col-md-12"> | ||
214 | + <nav aria-label="Page navigation"> | ||
215 | + <ul class="pagination"> | ||
216 | + {% if page_obj.has_previous %} | ||
217 | + <li> | ||
218 | + <a href="?page={{ page_obj.previous_page_number }}"><span><<</span></a> | ||
219 | + </li> | ||
327 | {% endif %} | 220 | {% endif %} |
328 | - {% endfor %} | ||
329 | - {% endif %} | ||
330 | - | ||
331 | - <nav aria-label="Page navigation"> | ||
332 | - <ul class="pagination"> | ||
333 | - {% for page_number in paginator.page_range %} | ||
334 | - <li{% if page_obj.number == page_number %} class="active"{% endif %}> | ||
335 | - <a href="?page={{ page_number }}">{{ page_number }}</a> | ||
336 | - </li> | ||
337 | - {% endfor %} | ||
338 | - </ul> | 221 | + {% for page_number in paginator.page_range %} |
222 | + <li{% if page_obj.number == page_number %} class="active"{% endif %}> | ||
223 | + <a href="?page={{ page_number }}">{{ page_number }}</a> | ||
224 | + </li> | ||
225 | + {% endfor %} | ||
226 | + {% if page_obj.has_next %} | ||
227 | + <li> | ||
228 | + <a href="?page={{ page_obj.next_page_number }}"><span>>></span></a> | ||
229 | + </li> | ||
230 | + {% endif %} | ||
231 | + </ul> | ||
339 | </nav> | 232 | </nav> |
340 | - {% else %} | ||
341 | - {% trans 'No courses found' %} | ||
342 | - {% endif %} | ||
343 | -{% endif %} | ||
344 | - | 233 | + </div> |
345 | {% endblock %} | 234 | {% endblock %} |
courses/templates/subject/form_view_teacher.html
@@ -15,9 +15,11 @@ | @@ -15,9 +15,11 @@ | ||
15 | </div> | 15 | </div> |
16 | <div class="col-xs-3 col-md-2 divMoreActions"> | 16 | <div class="col-xs-3 col-md-2 divMoreActions"> |
17 | <div class="btn-group"> | 17 | <div class="btn-group"> |
18 | - <button type="button" class="btn btn-default btn-sm eye" data-toggle="tooltip" data-placement="bottom" title="Visible"> | 18 | + <a href="{% url 'course:view_topic' topic.slug %}"> |
19 | + <button type="button" class="btn btn-default btn-sm eye" data-toggle="tooltip" data-placement="bottom" title="Visible"> | ||
19 | <i class="fa fa-eye fa-2x" aria-hidden="true"></i> | 20 | <i class="fa fa-eye fa-2x" aria-hidden="true"></i> |
20 | - </button> | 21 | + </button> |
22 | + </a> | ||
21 | </div> | 23 | </div> |
22 | <div class="btn-group"> | 24 | <div class="btn-group"> |
23 | <button class="btn btn-default btn-sm dropdown-toggle" type="button" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | 25 | <button class="btn btn-default btn-sm dropdown-toggle" type="button" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> |
courses/templates/subject/index.html
@@ -36,16 +36,11 @@ | @@ -36,16 +36,11 @@ | ||
36 | <div class="panel panel-info"> | 36 | <div class="panel panel-info"> |
37 | <div class="panel-heading"> | 37 | <div class="panel-heading"> |
38 | <div class="row"> | 38 | <div class="row"> |
39 | - <div class="col-md-9 col-sm-7"> | 39 | + <div class="col-md-9 col-sm-9"> |
40 | <h3>{{subject}}</h3> | 40 | <h3>{{subject}}</h3> |
41 | </div> | 41 | </div> |
42 | - <div class="col-xs-4 col-md-3 divMoreActions"> | ||
43 | - <div class="btn-group"> | ||
44 | - <button type="button" class="btn btn-default btn-sm eye" data-toggle="tooltip" data-placement="bottom" title="Visible"> | ||
45 | - <i class="fa fa-eye fa-2x" aria-hidden="true"></i> | ||
46 | - </button> | ||
47 | - </div> | ||
48 | - {% if user|has_role:'system_admin' or user in subject.professors %} | 42 | + {% if user|has_role:'system_admin' or user in subject.professors %} |
43 | + <div class="col-xs-4 col-md-3 divMoreActions"> | ||
49 | <div class="btn-group"> | 44 | <div class="btn-group"> |
50 | <button class="btn btn-default btn-sm dropdown-toggle" type="button" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | 45 | <button class="btn btn-default btn-sm dropdown-toggle" type="button" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> |
51 | <i class="fa fa-ellipsis-v fa-2x" aria-hidden="true"></i> | 46 | <i class="fa fa-ellipsis-v fa-2x" aria-hidden="true"></i> |
@@ -56,8 +51,8 @@ | @@ -56,8 +51,8 @@ | ||
56 | <li><a href="{% url 'course:delete_subject' subject.slug %}" data-toggle="modal" data-target="#removeSubject"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans "Remove" %}</a></li> | 51 | <li><a href="{% url 'course:delete_subject' subject.slug %}" data-toggle="modal" data-target="#removeSubject"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans "Remove" %}</a></li> |
57 | </ul> | 52 | </ul> |
58 | </div> | 53 | </div> |
59 | - {% endif %} | ||
60 | - </div> | 54 | + </div> |
55 | + {% endif %} | ||
61 | </div> | 56 | </div> |
62 | </div> | 57 | </div> |
63 | <div class="panel-body"> | 58 | <div class="panel-body"> |
courses/views.py
@@ -2,7 +2,7 @@ from django.shortcuts import render, get_object_or_404, redirect | @@ -2,7 +2,7 @@ from django.shortcuts import render, get_object_or_404, redirect | ||
2 | from django.views import generic | 2 | from django.views import generic |
3 | from django.contrib import messages | 3 | from django.contrib import messages |
4 | from django.contrib.auth.decorators import login_required | 4 | from django.contrib.auth.decorators import login_required |
5 | -from django.core.paginator import Paginator, EmptyPage | 5 | +from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger |
6 | from django.contrib.auth.mixins import LoginRequiredMixin | 6 | from django.contrib.auth.mixins import LoginRequiredMixin |
7 | from rolepermissions.mixins import HasRoleMixin | 7 | from rolepermissions.mixins import HasRoleMixin |
8 | from django.core.urlresolvers import reverse_lazy | 8 | from django.core.urlresolvers import reverse_lazy |
@@ -26,23 +26,41 @@ class IndexView(LoginRequiredMixin, NotificationMixin, generic.ListView): | @@ -26,23 +26,41 @@ class IndexView(LoginRequiredMixin, NotificationMixin, generic.ListView): | ||
26 | queryset = Course.objects.all() | 26 | queryset = Course.objects.all() |
27 | template_name = 'course/index.html' | 27 | template_name = 'course/index.html' |
28 | context_object_name = 'courses' | 28 | context_object_name = 'courses' |
29 | - paginate_by = 3 | 29 | + paginate_by = 2 |
30 | 30 | ||
31 | def get_context_data(self, **kwargs): | 31 | def get_context_data(self, **kwargs): |
32 | context = super(IndexView, self).get_context_data(**kwargs) | 32 | context = super(IndexView, self).get_context_data(**kwargs) |
33 | - context['categories'] = CourseCategory.objects.filter(course_category = True) | ||
34 | - context['courses_teacher'] = Course.objects.filter(professors__name = self.request.user.name) | ||
35 | - context['courses_student'] = Course.objects.filter(students__name = self.request.user.name) | ||
36 | - context['categorys_courses'] = CourseCategory.objects.filter(course_category__students__name = self.request.user.name).distinct() | ||
37 | - context['categorys_courses_professor'] = CourseCategory.objects.filter(course_category__professors__name = self.request.user.name).distinct() | 33 | + list_courses = None |
34 | + categorys_courses = None | ||
35 | + if has_role(self.request.user,'professor') or has_role(self.request.user,'system_admin'): | ||
36 | + list_courses = Course.objects.filter(professors__name = self.request.user.name) | ||
37 | + categorys_courses = CourseCategory.objects.filter(course_category__professors__name = self.request.user.name).distinct() | ||
38 | + else: | ||
39 | + list_courses = Course.objects.filter(students__name = self.request.user.name) | ||
40 | + categorys_courses = CourseCategory.objects.filter(course_category__students__name = self.request.user.name).distinct() | ||
41 | + | ||
38 | courses_category = Course.objects.filter(category__name = self.request.GET.get('category')) | 42 | courses_category = Course.objects.filter(category__name = self.request.GET.get('category')) |
39 | - context['courses_category'] = courses_category | 43 | + |
40 | none = None | 44 | none = None |
41 | q = self.request.GET.get('category', None) | 45 | q = self.request.GET.get('category', None) |
42 | if q is None: | 46 | if q is None: |
43 | none = True | 47 | none = True |
44 | context['none'] = none | 48 | context['none'] = none |
45 | 49 | ||
50 | + paginator = Paginator(list_courses, self.paginate_by) | ||
51 | + page = self.request.GET.get('page') | ||
52 | + | ||
53 | + try: | ||
54 | + list_courses = paginator.page(page) | ||
55 | + except PageNotAnInteger: | ||
56 | + list_courses = paginator.page(1) | ||
57 | + except EmptyPage: | ||
58 | + list_courses = paginator.page(paginator.num_pages) | ||
59 | + | ||
60 | + context['courses_category'] = courses_category | ||
61 | + context['list_courses'] = list_courses | ||
62 | + context['categorys_courses'] = categorys_courses | ||
63 | + | ||
46 | return context | 64 | return context |
47 | 65 | ||
48 | class CreateCourseView(LoginRequiredMixin, HasRoleMixin, NotificationMixin,generic.edit.CreateView): | 66 | class CreateCourseView(LoginRequiredMixin, HasRoleMixin, NotificationMixin,generic.edit.CreateView): |