Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into dev
  • Loading branch information
gustavo-salazar committed Oct 4, 2022
2 parents 0dd90b5 + 6854fdc commit 781ff20
Show file tree
Hide file tree
Showing 26 changed files with 333 additions and 306 deletions.
6 changes: 5 additions & 1 deletion webfront/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,22 @@ class EmptyQuerysetError(Exception):
def __init__(self, message):
self.message = message


class ExpectedUniqueError(Exception):
def __init__(self, message):
self.message = message


class HmmerWebError(Exception):
def __init__(self, message):
self.message = message


class BadURLParameterError(Exception):
def __init__(self, message):
self.message = message


class InvalidOperationRequest(Exception):
def __init__(self, message):
self.message = message
self.message = message
10 changes: 4 additions & 6 deletions webfront/migrations/0010_wiki_field_type_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@

class Migration(migrations.Migration):

dependencies = [
('webfront', '0009_entry_annotation_changes'),
]
dependencies = [("webfront", "0009_entry_annotation_changes")]

operations = [
migrations.AlterField(
model_name='entry',
name='wikipedia',
model_name="entry",
name="wikipedia",
field=jsonfield.fields.JSONField(null=True),
),
)
]
14 changes: 5 additions & 9 deletions webfront/migrations/0016_structural_model_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,16 @@

class Migration(migrations.Migration):

dependencies = [
('webfront', '0015_structural_model_lddt'),
]
dependencies = [("webfront", "0015_structural_model_lddt")]

operations = [
migrations.AddField(
model_name='structuralmodel',
name='algorithm',
field=models.CharField(default='trRosetta', max_length=20),
model_name="structuralmodel",
name="algorithm",
field=models.CharField(default="trRosetta", max_length=20),
preserve_default=False,
),
migrations.AlterField(
model_name='structuralmodel',
name='lddt',
field=models.BinaryField(),
model_name="structuralmodel", name="lddt", field=models.BinaryField()
),
]
10 changes: 3 additions & 7 deletions webfront/migrations/0017_structural_model_plddt.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@

class Migration(migrations.Migration):

dependencies = [
('webfront', '0016_structural_model_algorithm'),
]
dependencies = [("webfront", "0016_structural_model_algorithm")]

operations = [
migrations.RenameField(
model_name='structuralmodel',
old_name='lddt',
new_name='plddt',
),
model_name="structuralmodel", old_name="lddt", new_name="plddt"
)
]
10 changes: 3 additions & 7 deletions webfront/migrations/0018_taxa_modifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@

class Migration(migrations.Migration):

dependencies = [
('webfront', '0017_structural_model_plddt'),
]
dependencies = [("webfront", "0017_structural_model_plddt")]

operations = [
migrations.AddField(
model_name='entry',
name='taxa',
field=jsonfield.fields.JSONField(null=True),
),
model_name="entry", name="taxa", field=jsonfield.fields.JSONField(null=True)
)
]
28 changes: 15 additions & 13 deletions webfront/migrations/0019_entrytaxa_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,25 @@

class Migration(migrations.Migration):

dependencies = [
('webfront', '0018_taxa_modifier'),
]
dependencies = [("webfront", "0018_taxa_modifier")]

operations = [
migrations.CreateModel(
name='EntryTaxa',
name="EntryTaxa",
fields=[
('accession', models.OneToOneField(db_column='accession', on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='webfront.entry')),
('tree', jsonfield.fields.JSONField(null=True)),
(
"accession",
models.OneToOneField(
db_column="accession",
on_delete=django.db.models.deletion.CASCADE,
primary_key=True,
serialize=False,
to="webfront.entry",
),
),
("tree", jsonfield.fields.JSONField(null=True)),
],
options={
'db_table': 'webfront_entrytaxa',
},
),
migrations.RemoveField(
model_name='entry',
name='taxa',
options={"db_table": "webfront_entrytaxa"},
),
migrations.RemoveField(model_name="entry", name="taxa"),
]
10 changes: 4 additions & 6 deletions webfront/migrations/0020_alter_entryannotation_num_sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@

class Migration(migrations.Migration):

dependencies = [
('webfront', '0019_entrytaxa_table'),
]
dependencies = [("webfront", "0019_entrytaxa_table")]

operations = [
migrations.AlterField(
model_name='entryannotation',
name='num_sequences',
model_name="entryannotation",
name="num_sequences",
field=models.IntegerField(null=True),
),
)
]
84 changes: 25 additions & 59 deletions webfront/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,51 @@ class CustomPagination(CursorPagination):
current_size = None
after_key = None
before_key = None
elastic_result = None

def get_paginated_response(self, data):
base = [
("count", self.current_size),
("next", self.get_next_link()),
("previous", self.get_previous_link()),
("results", data["data"]),
("results", self._sortBasedOnElastic(data["data"])),
]
if "extensions" in data and len(data["extensions"]) > 0:
for ext in data["extensions"]:
base.append((ext, data["extensions"][ext]))
return Response(OrderedDict(base))

# If there is data in elastic_result, implies that the wueryset was created by querying elastic first.
# This method uses the list of accession retrieved via elastic to order the results.
def _sortBasedOnElastic(self, data):
if self.elastic_result is None:
return data
ordered_data = []
for acc in self.elastic_result:
obj = next(
filter(
lambda item: item.get("metadata", {}).get("accession", "").lower()
== acc.lower(),
data,
),
None,
)
if obj is not None:
ordered_data.append(obj)
return ordered_data

def _get_position_from_instance(self, instance, ordering):
if type(instance) == tuple:
return instance[0]
return super(CustomPagination, self)._get_position_from_instance(
instance, ordering
)

# Extract some values passed as kwargs before invoking the implementation in the super class
def paginate_queryset(self, queryset, request, **kwargs):
self.current_size = None
self.after_key = None
self.elastic_result = None
if (
hasattr(queryset, "model")
and queryset.model._meta.ordering != []
Expand All @@ -69,6 +91,8 @@ def paginate_queryset(self, queryset, request, **kwargs):
self.after_key = kwargs["after_key"]
if "before_key" in kwargs and kwargs["before_key"] is not None:
self.before_key = kwargs["before_key"]
if "elastic_result" in kwargs and kwargs["elastic_result"] is not None:
self.elastic_result = kwargs["elastic_result"]
return super(CustomPagination, self).paginate_queryset(
queryset, request, kwargs["view"]
)
Expand Down Expand Up @@ -105,61 +129,3 @@ def get_previous_link(self):
return replace_query_param(
self.base_url, "cursor", "-{}".format(self.before_key)
)


class CustomPaginationOld(PageNumberPagination):
page_size = settings.INTERPRO_CONFIG.get("default_page_size", 20)
page_size_query_param = "page_size"
max_page_size = 200
ordering = "-accession"
django_paginator_class = CustomPaginator
current_size = None

def get_paginated_response(self, data):
self.current_size = (
self.page.paginator.count
if self.current_size is None
else self.current_size
)
return Response(
OrderedDict(
[
("count", self.current_size),
("next", self.get_next_link()),
("previous", self.get_previous_link()),
("results", data),
]
)
)

def paginate_queryset(self, queryset, request, **kwargs):
self.current_size = None
if "search_size" in kwargs and kwargs["search_size"] is not None:
if not queryset.ordered:
queryset = queryset.order_by("accession")
self.current_size = kwargs["search_size"]

return super(CustomPagination, self).paginate_queryset(
queryset, request, kwargs["view"]
)

def get_next_link(self):
if not self.has_next():
return None
url = replace_url_host(self.request.build_absolute_uri())
page_number = self.page.number + 1
return replace_query_param(url, self.page_query_param, page_number)

def has_next(self):
if self.current_size is None:
return False
return self.page.number * self.page.paginator.per_page < self.current_size

def get_previous_link(self):
if not self.page.has_previous():
return None
url = replace_url_host(self.request.build_absolute_uri())
page_number = self.page.previous_page_number()
if page_number == 1:
return remove_query_param(url, self.page_query_param)
return replace_query_param(url, self.page_query_param, page_number)
Loading

0 comments on commit 781ff20

Please sign in to comment.