Commit cdaefc85e5133d81cc51ae3d54a4d13f89b2b98b
1 parent
4096a888
Exists in
master
and in
3 other branches
fixed subject count and case where the search field is empty now does not goes f…
…urther, it stays on the same page
Showing
1 changed file
with
23 additions
and
6 deletions
Show diff stats
subjects/views.py
@@ -6,7 +6,7 @@ from django.core.urlresolvers import reverse_lazy | @@ -6,7 +6,7 @@ from django.core.urlresolvers import reverse_lazy | ||
6 | from rolepermissions.verifications import has_role | 6 | from rolepermissions.verifications import has_role |
7 | from django.db.models import Q | 7 | from django.db.models import Q |
8 | from django.contrib import messages | 8 | from django.contrib import messages |
9 | -from django.http import HttpResponse, JsonResponse | 9 | +from django.http import HttpResponse, JsonResponse, HttpResponseRedirect |
10 | from django.utils.translation import ugettext_lazy as _ | 10 | from django.utils.translation import ugettext_lazy as _ |
11 | 11 | ||
12 | from django.contrib.auth.mixins import LoginRequiredMixin | 12 | from django.contrib.auth.mixins import LoginRequiredMixin |
@@ -346,20 +346,37 @@ class SubjectSearchView(LoginRequiredMixin, ListView): | @@ -346,20 +346,37 @@ class SubjectSearchView(LoginRequiredMixin, ListView): | ||
346 | template_name = 'subjects/list_search.html' | 346 | template_name = 'subjects/list_search.html' |
347 | context_object_name = 'subjects' | 347 | context_object_name = 'subjects' |
348 | paginate_by = 10 | 348 | paginate_by = 10 |
349 | + | ||
350 | + def dispatch(self, request, *args, **kwargs): | ||
351 | + # Try to dispatch to the right method; if a method doesn't exist, | ||
352 | + # defer to the error handler. Also defer to the error handler if the | ||
353 | + # request method isn't on the approved list. | ||
354 | + tags = request.GET.get('search') | ||
355 | + tags = tags.split(" ") | ||
356 | + | ||
357 | + if tags[0] == '': | ||
358 | + return HttpResponseRedirect(request.META.get('HTTP_REFERER')) | ||
359 | + if request.method.lower() in self.http_method_names: | ||
360 | + handler = getattr(self, request.method.lower(), self.http_method_not_allowed) | ||
361 | + else: | ||
362 | + handler = self.http_method_not_allowed | ||
363 | + return handler(request, *args, **kwargs) | ||
349 | 364 | ||
350 | def get_queryset(self): | 365 | def get_queryset(self): |
351 | 366 | ||
352 | tags = self.request.GET.get('search') | 367 | tags = self.request.GET.get('search') |
368 | + | ||
353 | self.tags = tags | 369 | self.tags = tags |
354 | tags = tags.split(" ") | 370 | tags = tags.split(" ") |
355 | 371 | ||
372 | + | ||
356 | subjects = Subject.objects.filter(tags__name__in=tags) | 373 | 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() | 374 | + #pk = self.request.user.pk |
375 | + #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 | 376 | ||
360 | - self.totals = {'all_subjects': subjects.count(), 'my_subjects': my_subjects.count()} | ||
361 | - if self.kwargs.get('option'): | ||
362 | - subjects = my_subjects | 377 | + self.totals = {'all_subjects': subjects.count(), 'my_subjects': subjects.count()} |
378 | + #if self.kwargs.get('option'): | ||
379 | + # subjects = my_subjects | ||
363 | return subjects | 380 | return subjects |
364 | 381 | ||
365 | def get_context_data(self, **kwargs): | 382 | def get_context_data(self, **kwargs): |