Commit 068cbc59e5a6acad7226b33d5188fe53522c8916
1 parent
e4ad011b
Exists in
master
and in
3 other branches
Adding subjects page pagination
Showing
2 changed files
with
16 additions
and
22 deletions
Show diff stats
subjects/templates/subjects/list.html
1 | 1 | {% extends 'categories/home.html' %} |
2 | 2 | |
3 | -{% load static i18n permission_tags %} | |
3 | +{% load static i18n permission_tags pagination %} | |
4 | 4 | {% load django_bootstrap_breadcrumbs %} |
5 | 5 | |
6 | 6 | {% block javascript%} |
... | ... | @@ -169,6 +169,7 @@ |
169 | 169 | </div> |
170 | 170 | {% endif %} |
171 | 171 | {% endfor %} |
172 | + {% pagination request paginator page_obj %} | |
172 | 173 | </div> |
173 | 174 | </div> |
174 | 175 | <div id="modal_course"> | ... | ... |
subjects/views.py
... | ... | @@ -69,11 +69,22 @@ class IndexView(LoginRequiredMixin, ListView): |
69 | 69 | queryset = Category.objects.all() |
70 | 70 | template_name = 'subjects/list.html' |
71 | 71 | context_object_name = 'categories' |
72 | - | |
72 | + paginate_by = 5 | |
73 | 73 | |
74 | 74 | def get_queryset(self): |
75 | - result = super(IndexView, self).get_queryset() | |
76 | - return result | |
75 | + categories = Category.objects.all().order_by('name') | |
76 | + | |
77 | + if not self.request.user.is_staff: | |
78 | + if not self.kwargs.get('option'): | |
79 | + categories = Category.objects.filter(visible=True) | |
80 | + | |
81 | + for category in categories: | |
82 | + category.subjects = Subject.objects.filter(category= category) | |
83 | + | |
84 | + categories = [category for category in categories if category.subjects.count() > 0 or self.request.user in category.coordinators.all()] | |
85 | + #So I remove all categories that doesn't have the possibility for the user to be on | |
86 | + | |
87 | + return categories | |
77 | 88 | |
78 | 89 | def render_to_response(self, context, **response_kwargs): |
79 | 90 | if self.request.user.is_staff: |
... | ... | @@ -81,8 +92,6 @@ class IndexView(LoginRequiredMixin, ListView): |
81 | 92 | else: |
82 | 93 | context['page_template'] = "categories/home_teacher_student.html" |
83 | 94 | |
84 | - | |
85 | - | |
86 | 95 | if self.request.is_ajax(): |
87 | 96 | if self.request.user.is_staff: |
88 | 97 | self.template_name = "categories/home_admin_content.html" |
... | ... | @@ -101,22 +110,6 @@ class IndexView(LoginRequiredMixin, ListView): |
101 | 110 | context['all'] = True |
102 | 111 | context['title'] = _('All Subjects') |
103 | 112 | |
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 | 113 | context['subjects_menu_active'] = 'subjects_menu_active' |
121 | 114 | |
122 | 115 | return context | ... | ... |