Skip to content

Commit

Permalink
Merge pull request #931 from rfdeoliveira/issue-806
Browse files Browse the repository at this point in the history
Reordena apresentação de Revista-Fascículo
  • Loading branch information
viniciusandrade committed Oct 9, 2019
2 parents b2a1dab + 7cb1b63 commit bac298d
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions bireme/biblioref/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.views.generic.edit import FormView, CreateView, UpdateView, DeleteView
from django.contrib.contenttypes.models import ContentType
from django.db.models import Q
from django.db.models.functions import Substr

from django.shortcuts import render_to_response
from django.views.decorators.csrf import csrf_exempt
Expand All @@ -26,6 +27,8 @@

import json

JOURNALS_FASCICLE = "S"


class BiblioRefGenericListView(LoginRequiredView, ListView):
"""
Expand All @@ -39,7 +42,6 @@ def dispatch(self, *args, **kwargs):
return super(BiblioRefGenericListView, self).dispatch(*args, **kwargs)

def get_queryset(self):

source_id = self.request.GET.get('source', None)
document_type = self.request.GET.get('document_type', None)

Expand Down Expand Up @@ -81,8 +83,24 @@ def get_queryset(self):
object_list = object_list.filter(literature_type__startswith=literature_type,
treatment_level=treatment_level)

if document_type == JOURNALS_FASCICLE:
object_list = object_list.annotate(
publication_year=Substr("publication_date_normalized", 1, 4)
)

if self.actions['order'] == "-":
if self.model.__name__ == "Reference":
volume_serial_field = "referencesource__volume_serial"
issue_number_field = "referencesource__issue_number"
else:
volume_serial_field = "volume_serial"
issue_number_field = "issue_number"

object_list = object_list.order_by(
"-publication_year",
"-{}".format(volume_serial_field),
"-{}".format(issue_number_field)
)
elif self.actions['order'] == "-":
object_list = object_list.order_by("%s%s" % (self.actions["order"], self.actions["orderby"]))

# if not at main reference list and source or document_type remove filter by user
Expand Down Expand Up @@ -138,7 +156,6 @@ def get_queryset(self):
if self.actions['filter_status'] == '':
object_list = object_list.exclude(status='3', literature_type='S')


return object_list

def get_context_data(self, **kwargs):
Expand Down

0 comments on commit bac298d

Please sign in to comment.