Commit 4536c27f5f75188efb32b27aa79c6b53f372c0e9
1 parent
98e11391
Exists in
master
and in
3 other branches
Adding category breadcrumb go back (only in subject view for now)
Showing
5 changed files
with
67 additions
and
5 deletions
Show diff stats
subjects/templates/subjects/list.html
@@ -90,6 +90,7 @@ | @@ -90,6 +90,7 @@ | ||
90 | <div id="{{category.slug}}" class="panel-collapse panel-body collapse category-panel-content"> | 90 | <div id="{{category.slug}}" class="panel-collapse panel-body collapse category-panel-content"> |
91 | <input type="hidden" class="log_url" value="{% url 'categories:view_log' category.id %}" /> | 91 | <input type="hidden" class="log_url" value="{% url 'categories:view_log' category.id %}" /> |
92 | <input type="hidden" class="log_id" value="" /> | 92 | <input type="hidden" class="log_id" value="" /> |
93 | + | ||
93 | {% if category.coordinators.all|length > 0 %} | 94 | {% if category.coordinators.all|length > 0 %} |
94 | <h4><b>{% trans "Coordinator(s) " %}: </b> | 95 | <h4><b>{% trans "Coordinator(s) " %}: </b> |
95 | {{ category.coordinators.all|join:', ' }} | 96 | {{ category.coordinators.all|join:', ' }} |
@@ -193,4 +194,17 @@ | @@ -193,4 +194,17 @@ | ||
193 | <div id="modal_subject"></div> | 194 | <div id="modal_subject"></div> |
194 | 195 | ||
195 | <script type="text/javascript" src="{% static 'js/course.js' %}"></script> | 196 | <script type="text/javascript" src="{% static 'js/course.js' %}"></script> |
197 | + <script type="text/javascript"> | ||
198 | + $(function (){ | ||
199 | + var cat_slug = "{{ cat_slug }}" | ||
200 | + | ||
201 | + if (cat_slug != "") { | ||
202 | + $("#" + cat_slug).collapse('show'); | ||
203 | + | ||
204 | + $('html, body').animate({ | ||
205 | + scrollTop: $("#" + cat_slug).parent().offset().top | ||
206 | + }, 2000); | ||
207 | + } | ||
208 | + }); | ||
209 | + </script> | ||
196 | {% endblock %} | 210 | {% endblock %} |
subjects/templates/subjects/view.html
@@ -9,7 +9,7 @@ | @@ -9,7 +9,7 @@ | ||
9 | 9 | ||
10 | {% block breadcrumbs %} | 10 | {% block breadcrumbs %} |
11 | {{ block.super }} | 11 | {{ block.super }} |
12 | - {% breadcrumb subject.category 'subjects:index' %} | 12 | + {% breadcrumb subject.category 'subjects:cat_view' subject.category.slug %} |
13 | {% breadcrumb subject 'subjects:view' subject.slug %} | 13 | {% breadcrumb subject 'subjects:view' subject.slug %} |
14 | {% endblock %} | 14 | {% endblock %} |
15 | 15 |
subjects/urls.py
@@ -4,6 +4,7 @@ from . import views | @@ -4,6 +4,7 @@ from . import views | ||
4 | urlpatterns = [ | 4 | urlpatterns = [ |
5 | url(r'^home/$', views.HomeView.as_view(), name='home'), | 5 | url(r'^home/$', views.HomeView.as_view(), name='home'), |
6 | url(r'^$', views.IndexView.as_view(), name='index'), | 6 | url(r'^$', views.IndexView.as_view(), name='index'), |
7 | + url(r'^category/(?P<slug>[\w_-]+)/$', views.IndexView.as_view(), name='cat_view'), | ||
7 | url(r'^(?P<option>[\w_-]+)/$', views.IndexView.as_view(), name='index'), | 8 | url(r'^(?P<option>[\w_-]+)/$', views.IndexView.as_view(), name='index'), |
8 | url(r'^create/(?P<slug>[\w_-]+)/$', views.SubjectCreateView.as_view(), name='create'), | 9 | url(r'^create/(?P<slug>[\w_-]+)/$', views.SubjectCreateView.as_view(), name='create'), |
9 | url(r'^replicate/(?P<subject_slug>[\w_-]+)/$', views.SubjectCreateView.as_view(), name='replicate'), | 10 | url(r'^replicate/(?P<subject_slug>[\w_-]+)/$', views.SubjectCreateView.as_view(), name='replicate'), |
subjects/utils.py
@@ -18,6 +18,17 @@ def has_professor_profile(user, category): | @@ -18,6 +18,17 @@ def has_professor_profile(user, category): | ||
18 | 18 | ||
19 | return False | 19 | return False |
20 | 20 | ||
21 | +def get_category_page(categories, slug, per_page): | ||
22 | + total = 1 | ||
23 | + | ||
24 | + for category in categories: | ||
25 | + if category.slug == slug: | ||
26 | + return total / per_page + 1 | ||
27 | + | ||
28 | + total += 1 | ||
29 | + | ||
30 | + return 1 | ||
31 | + | ||
21 | def count_subjects( user, all_subs = True): | 32 | def count_subjects( user, all_subs = True): |
22 | total = 0 | 33 | total = 0 |
23 | pk = user.pk | 34 | pk = user.pk |
subjects/views.py
@@ -26,7 +26,7 @@ import time | @@ -26,7 +26,7 @@ import time | ||
26 | import datetime | 26 | import datetime |
27 | from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger | 27 | from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger |
28 | from .forms import CreateSubjectForm | 28 | from .forms import CreateSubjectForm |
29 | -from .utils import has_student_profile, has_professor_profile, count_subjects | 29 | +from .utils import has_student_profile, has_professor_profile, count_subjects, get_category_page |
30 | from users.models import User | 30 | from users.models import User |
31 | 31 | ||
32 | 32 | ||
@@ -55,6 +55,7 @@ class HomeView(LoginRequiredMixin, ListView): | @@ -55,6 +55,7 @@ class HomeView(LoginRequiredMixin, ListView): | ||
55 | #bringing users | 55 | #bringing users |
56 | tags = Tag.objects.all() | 56 | tags = Tag.objects.all() |
57 | context['tags'] = tags | 57 | context['tags'] = tags |
58 | + | ||
58 | return context | 59 | return context |
59 | 60 | ||
60 | 61 | ||
@@ -67,8 +68,7 @@ class IndexView(LoginRequiredMixin, ListView): | @@ -67,8 +68,7 @@ class IndexView(LoginRequiredMixin, ListView): | ||
67 | context_object_name = 'categories' | 68 | context_object_name = 'categories' |
68 | paginate_by = 10 | 69 | paginate_by = 10 |
69 | 70 | ||
70 | - def get_queryset(self): | ||
71 | - | 71 | + def get_queryset(self): |
72 | if self.request.user.is_staff: | 72 | if self.request.user.is_staff: |
73 | categories = Category.objects.all().order_by('name') | 73 | categories = Category.objects.all().order_by('name') |
74 | else: | 74 | else: |
@@ -94,6 +94,39 @@ class IndexView(LoginRequiredMixin, ListView): | @@ -94,6 +94,39 @@ class IndexView(LoginRequiredMixin, ListView): | ||
94 | 94 | ||
95 | return categories | 95 | return categories |
96 | 96 | ||
97 | + def paginate_queryset(self, queryset, page_size): | ||
98 | + paginator = self.get_paginator( | ||
99 | + queryset, page_size, orphans=self.get_paginate_orphans(), | ||
100 | + allow_empty_first_page=self.get_allow_empty()) | ||
101 | + | ||
102 | + page_kwarg = self.page_kwarg | ||
103 | + | ||
104 | + page = self.kwargs.get(page_kwarg) or self.request.GET.get(page_kwarg) or 1 | ||
105 | + | ||
106 | + if self.kwargs.get('slug'): | ||
107 | + categories = queryset | ||
108 | + | ||
109 | + paginator = Paginator(categories, self.paginate_by) | ||
110 | + | ||
111 | + page = get_category_page(categories, self.kwargs.get('slug'), self.paginate_by) | ||
112 | + | ||
113 | + try: | ||
114 | + page_number = int(page) | ||
115 | + except ValueError: | ||
116 | + if page == 'last': | ||
117 | + page_number = paginator.num_pages | ||
118 | + else: | ||
119 | + raise Http404(_("Page is not 'last', nor can it be converted to an int.")) | ||
120 | + | ||
121 | + try: | ||
122 | + page = paginator.page(page_number) | ||
123 | + return (paginator, page, page.object_list, page.has_other_pages()) | ||
124 | + except InvalidPage as e: | ||
125 | + raise Http404(_('Invalid page (%(page_number)s): %(message)s') % { | ||
126 | + 'page_number': page_number, | ||
127 | + 'message': str(e) | ||
128 | + }) | ||
129 | + | ||
97 | def render_to_response(self, context, **response_kwargs): | 130 | def render_to_response(self, context, **response_kwargs): |
98 | if self.request.user.is_staff: | 131 | if self.request.user.is_staff: |
99 | context['page_template'] = "categories/home_admin_content.html" | 132 | context['page_template'] = "categories/home_admin_content.html" |
@@ -116,11 +149,14 @@ class IndexView(LoginRequiredMixin, ListView): | @@ -116,11 +149,14 @@ class IndexView(LoginRequiredMixin, ListView): | ||
116 | 149 | ||
117 | context['show_buttons'] = True #So it shows subscribe and access buttons | 150 | context['show_buttons'] = True #So it shows subscribe and access buttons |
118 | context['totals'] = self.totals | 151 | context['totals'] = self.totals |
119 | - | 152 | + |
120 | if self.kwargs.get('option'): | 153 | if self.kwargs.get('option'): |
121 | context['all'] = True | 154 | context['all'] = True |
122 | context['title'] = _('All Subjects') | 155 | context['title'] = _('All Subjects') |
123 | 156 | ||
157 | + if self.kwargs.get('slug'): | ||
158 | + context['cat_slug'] = self.kwargs.get('slug') | ||
159 | + | ||
124 | context['subjects_menu_active'] = 'subjects_menu_active' | 160 | context['subjects_menu_active'] = 'subjects_menu_active' |
125 | 161 | ||
126 | return context | 162 | return context |