Commit 7b3b73e5d5550312415acc1aa1ba20403f8616cb
1 parent
198a2738
Exists in
master
and in
5 other branches
Fixed some sort issues [Issue:#251]
Showing
1 changed file
with
20 additions
and
10 deletions
Show diff stats
users/views.py
@@ -176,6 +176,7 @@ class SearchView(LoginRequiredMixin, generic.ListView): | @@ -176,6 +176,7 @@ class SearchView(LoginRequiredMixin, generic.ListView): | ||
176 | 176 | ||
177 | def get_context_data(self, **kwargs): | 177 | def get_context_data(self, **kwargs): |
178 | context = super(SearchView, self).get_context_data(**kwargs) | 178 | context = super(SearchView, self).get_context_data(**kwargs) |
179 | + #result_list = [] | ||
179 | search = self.request.GET.get('search', None) | 180 | search = self.request.GET.get('search', None) |
180 | link_list = [] | 181 | link_list = [] |
181 | file_list = [] | 182 | file_list = [] |
@@ -189,11 +190,11 @@ class SearchView(LoginRequiredMixin, generic.ListView): | @@ -189,11 +190,11 @@ class SearchView(LoginRequiredMixin, generic.ListView): | ||
189 | polls = Poll.objects.all() | 190 | polls = Poll.objects.all() |
190 | exams = Exam.objects.all() | 191 | exams = Exam.objects.all() |
191 | forums = Forum.objects.all() | 192 | forums = Forum.objects.all() |
192 | - link_list = sorted([link for link in links for topic in topics if link.topic == topic]) | ||
193 | - exam_list = sorted([exam for exam in exams for topic in topics if exam.topic == topic]) | ||
194 | - file_list = sorted([arquivo for arquivo in files for topic in topics if arquivo.topic == topic]) | ||
195 | - poll_list = sorted([poll for poll in polls for topic in topics if poll.topic == topic]) | ||
196 | - forum_list = sorted([forum for forum in forums for topic in topics if forum.topic == topic]) | 193 | + link_list = sorted([link for link in links for topic in topics if link.topic == topic],key = lambda x:x.name) |
194 | + exam_list = sorted([exam for exam in exams for topic in topics if exam.topic == topic],key = lambda x:x.name) | ||
195 | + file_list = sorted([arquivo for arquivo in files for topic in topics if arquivo.topic == topic],key = lambda x:x.name) | ||
196 | + poll_list = sorted([poll for poll in polls for topic in topics if poll.topic == topic],key = lambda x:x.name) | ||
197 | + forum_list = sorted([forum for forum in forums for topic in topics if forum.topic == topic],key = lambda x:x.name) | ||
197 | elif has_role(self.request.user,'system_admin'): | 198 | elif has_role(self.request.user,'system_admin'): |
198 | link_list = Link.objects.filter( Q(name__icontains=search)).order_by('name') | 199 | link_list = Link.objects.filter( Q(name__icontains=search)).order_by('name') |
199 | file_list = TopicFile.objects.filter(Q(name__icontains=search)).order_by('name') | 200 | file_list = TopicFile.objects.filter(Q(name__icontains=search)).order_by('name') |
@@ -208,15 +209,23 @@ class SearchView(LoginRequiredMixin, generic.ListView): | @@ -208,15 +209,23 @@ class SearchView(LoginRequiredMixin, generic.ListView): | ||
208 | forum_list = Forum.objects.filter(Q(name__icontains=search)and Q(students__name = self.request.user.name)).order_by('name') | 209 | forum_list = Forum.objects.filter(Q(name__icontains=search)and Q(students__name = self.request.user.name)).order_by('name') |
209 | 210 | ||
210 | ''' | 211 | ''' |
211 | - paginator = Paginator(list_links, self.paginate_by) | 212 | + result_list = list(chain(link_list,file_list,poll_list,exam_list,forum_list)) |
213 | + for x in result_list: | ||
214 | + if isinstance(x,Link): | ||
215 | + print(x) | ||
216 | + paginator = Paginator(result_list, self.paginate_by) | ||
217 | + print(paginator.num_pages) | ||
218 | + print(paginator.count) | ||
212 | page = self.request.GET.get('page') | 219 | page = self.request.GET.get('page') |
213 | - | ||
214 | try: | 220 | try: |
215 | - list_links = paginator.page(page) | 221 | + result_list = paginator.page(page) |
222 | + print (result_list) | ||
216 | except PageNotAnInteger: | 223 | except PageNotAnInteger: |
217 | - list_links = paginator.page(1) | 224 | + result_list = paginator.page(1) |
218 | except EmptyPage: | 225 | except EmptyPage: |
219 | - list_links = paginator.page(paginator.num_pages) | 226 | + #print ((paginator.num_pages)) |
227 | + result_list = paginator.page(paginator.num_pages) | ||
228 | + | ||
220 | ''' | 229 | ''' |
221 | 230 | ||
222 | context['link_list'] = link_list | 231 | context['link_list'] = link_list |
@@ -224,5 +233,6 @@ class SearchView(LoginRequiredMixin, generic.ListView): | @@ -224,5 +233,6 @@ class SearchView(LoginRequiredMixin, generic.ListView): | ||
224 | context['poll_list'] = poll_list | 233 | context['poll_list'] = poll_list |
225 | context['exam_list'] = exam_list | 234 | context['exam_list'] = exam_list |
226 | context['forum_list'] = forum_list | 235 | context['forum_list'] = forum_list |
236 | + #context['result_list'] = result_list | ||
227 | 237 | ||
228 | return context | 238 | return context |