Skip to content

Commit

Permalink
Fix dbxref queries if a synonym contains the same text as the dbxref.
Browse files Browse the repository at this point in the history
Closes #80
  • Loading branch information
elserj committed Feb 3, 2024
1 parent 75e5f67 commit 9420f32
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion annotations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,13 @@ def get_context_data(self, **kwargs):
db_references = annotation.db_reference.split("|")
for db_reference in db_references:
dbname = db_reference.split(':')[0]
db_reference_dict[db_reference] = DBXref.objects.get(Q(dbname=dbname) | Q(synonyms__icontains=dbname))
try:
db_reference_dict[db_reference] = DBXref.objects.get(Q(dbname=dbname))
except DBXref.DoesNotExist:
try:
db_reference_dict[dbname] = DBXref.objects.get(synonyms__icontains=dbname)
except DBXref.DoesNotExist:
db_reference_dict[dbname] = None
context['db_references_dict'] = db_reference_dict
# Get the count of changes that been approved for this annotation
change_count = AnnotationApproval.objects.filter(source_annotation=annotation, status=choices.ApprovalStates.APPROVED).count()
Expand Down
8 changes: 7 additions & 1 deletion dbxrefs/templatetags/dbxref_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ def example_id_db_remove(id, db):
def get_dbxref_url(object):
db = object.split(':')[0]
id = object.split(':', 1)[1]
dbxref = DBXref.objects.get(Q(dbname=db) | Q(synonyms__icontains=db))
try:
dbxref = DBXref.objects.get(Q(dbname=db))
except DBXref.DoesNotExist:
try:
dbxref = DBXref(Q(synonyms__icontains=db))
except DBXref.DoesNotExist:
dbxref = None
return dbxref_url_replace(dbxref.xrefURL, id)

@register.filter(name='get_id_from_dbxref')
Expand Down

0 comments on commit 9420f32

Please sign in to comment.