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 | 66 | {% endif %} |
67 | 67 | |
68 | 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 | 80 | </div> |
78 | 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 | 88 | </div> |
95 | 89 | |
96 | 90 | </fieldset> |
97 | -{% if user|has_role:'professor, system_admin' %} | |
98 | 91 | <div class="col-md-12"> |
99 | 92 | {% if courses|length > 0 %} |
100 | 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 | 95 | <div class="panel-group ui-accordion ui-widget ui-helper-reset ui-sortable" id="accordion" role="tablist" aria-multiselectable="false"> |
104 | 96 | <div class="group"> |
105 | 97 | <div class="panel panel-info"> |
... | ... | @@ -112,12 +104,6 @@ |
112 | 104 | </div> |
113 | 105 | <div class="col-xs-4 col-md-3" id="divMoreActions"> |
114 | 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 | 107 | <button class="btn btn-default btn-sm dropdown-toggle" type="button" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> |
122 | 108 | <i class="fa fa-ellipsis-v fa-2x" aria-hidden="true"></i> |
123 | 109 | </button> |
... | ... | @@ -148,7 +134,7 @@ |
148 | 134 | </div> |
149 | 135 | {% endfor %} |
150 | 136 | {% else %} |
151 | - {% for course in courses_teacher %} | |
137 | + {% for course in courses_category %} | |
152 | 138 | {% if course.category.name == request.GET.category %} |
153 | 139 | <!-- Put your content here! --> |
154 | 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 | 207 | </div> |
222 | 208 | </div> |
223 | 209 | </div> |
224 | - </div> | |
225 | 210 | </div> |
226 | 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 | 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 | 232 | </nav> |
340 | - {% else %} | |
341 | - {% trans 'No courses found' %} | |
342 | - {% endif %} | |
343 | -{% endif %} | |
344 | - | |
233 | + </div> | |
345 | 234 | {% endblock %} | ... | ... |
courses/templates/subject/form_view_teacher.html
... | ... | @@ -15,9 +15,11 @@ |
15 | 15 | </div> |
16 | 16 | <div class="col-xs-3 col-md-2 divMoreActions"> |
17 | 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 | 20 | <i class="fa fa-eye fa-2x" aria-hidden="true"></i> |
20 | - </button> | |
21 | + </button> | |
22 | + </a> | |
21 | 23 | </div> |
22 | 24 | <div class="btn-group"> |
23 | 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 | 36 | <div class="panel panel-info"> |
37 | 37 | <div class="panel-heading"> |
38 | 38 | <div class="row"> |
39 | - <div class="col-md-9 col-sm-7"> | |
39 | + <div class="col-md-9 col-sm-9"> | |
40 | 40 | <h3>{{subject}}</h3> |
41 | 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 | 44 | <div class="btn-group"> |
50 | 45 | <button class="btn btn-default btn-sm dropdown-toggle" type="button" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> |
51 | 46 | <i class="fa fa-ellipsis-v fa-2x" aria-hidden="true"></i> |
... | ... | @@ -56,8 +51,8 @@ |
56 | 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 | 52 | </ul> |
58 | 53 | </div> |
59 | - {% endif %} | |
60 | - </div> | |
54 | + </div> | |
55 | + {% endif %} | |
61 | 56 | </div> |
62 | 57 | </div> |
63 | 58 | <div class="panel-body"> | ... | ... |
courses/views.py
... | ... | @@ -2,7 +2,7 @@ from django.shortcuts import render, get_object_or_404, redirect |
2 | 2 | from django.views import generic |
3 | 3 | from django.contrib import messages |
4 | 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 | 6 | from django.contrib.auth.mixins import LoginRequiredMixin |
7 | 7 | from rolepermissions.mixins import HasRoleMixin |
8 | 8 | from django.core.urlresolvers import reverse_lazy |
... | ... | @@ -26,23 +26,41 @@ class IndexView(LoginRequiredMixin, NotificationMixin, generic.ListView): |
26 | 26 | queryset = Course.objects.all() |
27 | 27 | template_name = 'course/index.html' |
28 | 28 | context_object_name = 'courses' |
29 | - paginate_by = 3 | |
29 | + paginate_by = 2 | |
30 | 30 | |
31 | 31 | def get_context_data(self, **kwargs): |
32 | 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 | 42 | courses_category = Course.objects.filter(category__name = self.request.GET.get('category')) |
39 | - context['courses_category'] = courses_category | |
43 | + | |
40 | 44 | none = None |
41 | 45 | q = self.request.GET.get('category', None) |
42 | 46 | if q is None: |
43 | 47 | none = True |
44 | 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 | 64 | return context |
47 | 65 | |
48 | 66 | class CreateCourseView(LoginRequiredMixin, HasRoleMixin, NotificationMixin,generic.edit.CreateView): | ... | ... |