Commit f7410615f1a900aa6849065570b65634df303b83

Authored by Gustavo Bernardo
1 parent 9d81616c

Fixed bug when listing categories, now lists by category name correctly [Issue:#228]

Showing 1 changed file with 5 additions and 3 deletions   Show diff stats
courses/views.py
@@ -445,17 +445,19 @@ class IndexCatView(LoginRequiredMixin, generic.ListView): @@ -445,17 +445,19 @@ class IndexCatView(LoginRequiredMixin, generic.ListView):
445 445
446 login_url = reverse_lazy("core:home") 446 login_url = reverse_lazy("core:home")
447 redirect_field_name = 'next' 447 redirect_field_name = 'next'
448 - queryset = CourseCategory.objects.all() 448 + queryset = sorted(CourseCategory.objects.all(),key = lambda x:x.name)
449 template_name = 'category/index.html' 449 template_name = 'category/index.html'
450 context_object_name = 'categories' 450 context_object_name = 'categories'
451 paginate_by = 5 451 paginate_by = 5
452 - 452 +
  453 + '''
453 def get_context_data(self, **kwargs): 454 def get_context_data(self, **kwargs):
454 context = super(IndexCatView, self).get_context_data(**kwargs) 455 context = super(IndexCatView, self).get_context_data(**kwargs)
455 list_cat = CourseCategory.objects.filter(course_category = True).order_by('name') 456 list_cat = CourseCategory.objects.filter(course_category = True).order_by('name')
456 paginator = Paginator(list_cat, self.paginate_by) 457 paginator = Paginator(list_cat, self.paginate_by)
457 page = self.request.GET.get('page') 458 page = self.request.GET.get('page')
458 459
  460 + print(list_cat)
459 try: 461 try:
460 list_cat = paginator.page(page) 462 list_cat = paginator.page(page)
461 except PageNotAnInteger: 463 except PageNotAnInteger:
@@ -466,7 +468,7 @@ class IndexCatView(LoginRequiredMixin, generic.ListView): @@ -466,7 +468,7 @@ class IndexCatView(LoginRequiredMixin, generic.ListView):
466 context['list_cat'] = list_cat 468 context['list_cat'] = list_cat
467 469
468 return context 470 return context
469 - 471 + '''
470 class CreateCatView(LoginRequiredMixin, HasRoleMixin, generic.edit.CreateView): 472 class CreateCatView(LoginRequiredMixin, HasRoleMixin, generic.edit.CreateView):
471 473
472 allowed_roles = ['professor', 'system_admin'] 474 allowed_roles = ['professor', 'system_admin']