Commit 2e5cee0a31633428547c9c902bacae266b698284

Authored by Zambom
1 parent 7da17356

Adjusting home subjects presentation

subjects/templates/subjects/initial.html
1 1 {% extends "categories/home.html" %}
2 2  
  3 +{% load pagination %}
  4 +
3 5 {% block content %}
4 6  
5 7 <div id="" class="col-md-12">
6 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 14 </div>
13 15 </div>
  16 +
14 17 <div class="col-md-12 cards-content">
15 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 22 </div>
20 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 27 {% endblock content %}
38 28 \ No newline at end of file
... ...
subjects/templates/subjects/subject_card.html
... ... @@ -5,7 +5,7 @@
5 5 <div class="row">
6 6 <div class="col-md-12 category-header">
7 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 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 10 </a>
11 11 </h4>
... ...
subjects/views.py
... ... @@ -32,30 +32,35 @@ class HomeView(LoginRequiredMixin, ListView):
32 32 redirect_field_name = 'next'
33 33 queryset = Subject.objects.all()
34 34 template_name = 'subjects/initial.html'
35   -
  35 + context_object_name = 'subjects'
  36 + paginate_by = 2
36 37  
37   - def get_context_data(self, **kwargs):
38   - context = super(HomeView, self).get_context_data(**kwargs)
  38 + def get_queryset(self):
39 39 if self.request.user.is_staff:
40 40 subjects = Subject.objects.all()
41 41 else:
42 42 subjects = Subject.objects.all()
43 43 subjects = [subject for subject in subjects if self.request.user in subject.students.all() or self.request.user in subject.professor.all()]
  44 +
  45 + return subjects
  46 +
  47 + def get_context_data(self, **kwargs):
  48 + context = super(HomeView, self).get_context_data(**kwargs)
44 49  
45   - paginator = Paginator(subjects, 2)
  50 + # paginator = Paginator(subjects, 2)
46 51  
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)
  52 + # page = self.request.GET.get('page')
  53 + # try:
  54 + # subjects = paginator.page(page)
  55 + # except PageNotAnInteger:
  56 + # # If page is not an integer, deliver first page.
  57 + # subjects = paginator.page(1)
53 58  
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)
  59 + # except EmptyPage:
  60 + # # If page is out of range (e.g. 9999), deliver last page of results.
  61 + # subjects = paginator.page(paginator.num_pages)
57 62  
58   - context['subjects'] = subjects
  63 + # context['subjects'] = subjects
59 64 #bringing users
60 65 users = User.objects.all()
61 66 context['users'] = users
... ...