Commit 3aa59e9b2d6e2bc9e125716bda695135a26810af
1 parent
40d29a80
Exists in
master
and in
3 other branches
search routine completed
Showing
3 changed files
with
84 additions
and
28 deletions
Show diff stats
... | ... | @@ -0,0 +1,54 @@ |
1 | +{% extends "subjects/list.html" %} | |
2 | + | |
3 | +{% load static i18n pagination %} | |
4 | +{% load django_bootstrap_breadcrumbs subject_counter %} | |
5 | + | |
6 | +{% block content %} | |
7 | + | |
8 | + {% if messages %} | |
9 | + {% for message in messages %} | |
10 | + <script type="text/javascript"> | |
11 | + {% if message.tags == "danger" %} | |
12 | + alertify.error('{{message}}'); | |
13 | + {% else %} | |
14 | + alertify.success('{{message}}'); | |
15 | + {% endif %} | |
16 | + </script> | |
17 | + {% endfor %} | |
18 | + {% endif %} | |
19 | + | |
20 | + <div id="core-subjects-options-div"> | |
21 | + <ul class="core-subjects-options"> | |
22 | + {% if all %} | |
23 | + <a href="{% url 'subjects:search' %}?search= {{tags}} "><li >{% trans "My subjects" %} ({{ totals.my_subjects }})</li></a> | |
24 | + <a href="{% url 'subjects:search' 'all' %}?search={{tags}}" ><li class="active">{% trans "All subjects" %} ({{ totals.all_subjects }})</li></a> | |
25 | + {% else %} | |
26 | + <a href="{% url 'subjects:search' %}?search={{tags}}"><li class="active">{% trans "My subjects" %} ({{ totals.my_subjects }})</li></a> | |
27 | + <a href="{% url 'subjects:search' 'all' %}?search={{tags}}" ><li>{% trans "All subjects" %} ({{ totals.all_subjects }})</li></a> | |
28 | + {% endif %} | |
29 | + | |
30 | + </ul> | |
31 | + </div> | |
32 | + | |
33 | + <div class="col-md-12 cards-content"> | |
34 | + | |
35 | + | |
36 | + {% if subjects|length > 0 %} | |
37 | + <div class="panel-group" id="subject-accordion" role="tablist" aria-multiselectable="true"> | |
38 | + {% for subject in subjects %} | |
39 | + {% include "subjects/subject_card.html" with accordion_id="subject-accordion" %} | |
40 | + {% endfor %} | |
41 | + | |
42 | + {% pagination request paginator page_obj %} | |
43 | + </div> | |
44 | + {% else %} | |
45 | + <div class="text-center no-subjects"> | |
46 | + <i class="fa fa-graduation-cap"></i> | |
47 | + <h4>{% trans 'You still do not posses any subject in our platform' %}</h4> | |
48 | + </div> | |
49 | + {% endif %} | |
50 | + </div> | |
51 | + | |
52 | + | |
53 | + | |
54 | +{% endblock content %} | |
0 | 55 | \ No newline at end of file | ... | ... |
subjects/urls.py
... | ... | @@ -5,7 +5,6 @@ urlpatterns = [ |
5 | 5 | url(r'^home/$', views.HomeView.as_view(), name='home'), |
6 | 6 | url(r'^$', views.IndexView.as_view(), name='index'), |
7 | 7 | url(r'^category/(?P<slug>[\w_-]+)/$', views.IndexView.as_view(), name='cat_view'), |
8 | - url(r'^(?P<option>[\w_-]+)/$', views.IndexView.as_view(), name='index'), | |
9 | 8 | url(r'^create/(?P<slug>[\w_-]+)/$', views.SubjectCreateView.as_view(), name='create'), |
10 | 9 | url(r'^replicate/(?P<subject_slug>[\w_-]+)/$', views.SubjectCreateView.as_view(), name='replicate'), |
11 | 10 | url(r'^update/(?P<slug>[\w_-]+)/$', views.SubjectUpdateView.as_view(), name='update'), |
... | ... | @@ -13,4 +12,6 @@ urlpatterns = [ |
13 | 12 | url(r'^view/(?P<slug>[\w_-]+)/$', views.SubjectDetailView.as_view(), name='view'), |
14 | 13 | url(r'^subscribe/(?P<slug>[\w_-]+)/$', views.SubjectSubscribeView.as_view(), name='subscribe'), |
15 | 14 | url(r'^search/$', views.SubjectSearchView.as_view(), name='search'), |
15 | + url(r'^search/(?P<option>[\w_-]+)/$', views.SubjectSearchView.as_view(), name='search'), | |
16 | + url(r'^(?P<option>[\w_-]+)/$', views.IndexView.as_view(), name='index'), | |
16 | 17 | ] |
17 | 18 | \ No newline at end of file | ... | ... |
subjects/views.py
... | ... | @@ -343,40 +343,41 @@ class SubjectSubscribeView(LoginRequiredMixin, TemplateView): |
343 | 343 | |
344 | 344 | class SubjectSearchView(LoginRequiredMixin, ListView): |
345 | 345 | login_url = reverse_lazy("users:login") |
346 | - template_name = 'subjects/list.html' | |
347 | - context_object_name = 'categories' | |
346 | + template_name = 'subjects/list_search.html' | |
347 | + context_object_name = 'subjects' | |
348 | 348 | paginate_by = 10 |
349 | 349 | |
350 | 350 | def get_queryset(self): |
351 | - if self.request.user.is_staff: | |
352 | - subjects = Subject.objects.all().order_by("name") | |
353 | - else: | |
354 | - pk = self.request.user.pk | |
355 | - | |
356 | - subjects = Subject.objects.filter(Q(students__pk=pk) | Q(professor__pk=pk) | Q(category__coordinators__pk=pk)).distinct() | |
357 | 351 | |
358 | - self.total = len(subjects) | |
359 | - | |
352 | + tags = self.request.GET.get('search') | |
353 | + self.tags = tags | |
354 | + tags = tags.split(" ") | |
355 | + | |
356 | + subjects = Subject.objects.filter(tags__name__in=tags) | |
357 | + pk = self.request.user.pk | |
358 | + my_subjects = Subject.objects.filter(Q(students__pk=pk) | Q(professor__pk=pk) | Q(category__coordinators__pk=pk) & Q(tags__name__in=tags) ).distinct() | |
359 | + | |
360 | + self.totals = {'all_subjects': subjects.count(), 'my_subjects': my_subjects.count()} | |
361 | + if self.kwargs.get('option'): | |
362 | + subjects = my_subjects | |
360 | 363 | return subjects |
361 | - def post(self, request, *args, **kwargs): | |
362 | - print("aqui") | |
363 | - | |
364 | - return HttpResponse("T") | |
365 | - | |
366 | - def get(self, request, *args, **kwargs): | |
367 | - print("get") | |
368 | - print(args) | |
369 | - print(kwargs) | |
370 | - return HttpResponse("t") | |
371 | - | |
372 | - | |
364 | + | |
373 | 365 | def get_context_data(self, **kwargs): |
374 | 366 | context = super(SubjectSearchView, self).get_context_data(**kwargs) |
375 | - print(kwargs) | |
376 | - print("teste") | |
377 | - tags = kwargs.get('tags').strip() | |
378 | - print(tags) | |
379 | - | |
367 | + | |
368 | + context['tags'] = self.tags | |
380 | 369 | context['all'] = False |
381 | 370 | context['title'] = _('My Subjects') |
371 | + | |
372 | + context['show_buttons'] = True #So it shows subscribe and access buttons | |
373 | + context['totals'] = self.totals | |
374 | + | |
375 | + if self.kwargs.get('option'): | |
376 | + context['all'] = True | |
377 | + context['title'] = _('All Subjects') | |
378 | + | |
379 | + context['subjects_menu_active'] = 'subjects_menu_active' | |
380 | + | |
382 | 381 | return context |
382 | + | |
383 | + | ... | ... |