Skip to content

Commit

Permalink
Finish link annotation to internal gene stub. Closes #81. May still want
Browse files Browse the repository at this point in the history
to work on changes made by a superuser for that not showing up on the
changes page. Did add a note explaining it though.
  • Loading branch information
elserj committed Apr 10, 2024
1 parent 3f6c0e3 commit 774ab78
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 1 deletion.
32 changes: 31 additions & 1 deletion annotations/templates/annotations/annotation_link_internal.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,37 @@

{% block main %}
{% if logged_in %}
<h2>HI!</h2>
<h2>Use this page to link to a known gene in Planteome</h2>
<br>
<div style="text-align: center">
<form class="form-inline my-2 my-lg-0" style="display: inline-block" method="GET" action="{% url 'annotations:link_internal' pk=annotation.pk %}">
<div id="search_box">
<input class="form-control mr-sm-2" placeholder="Search for genes: CONSTANS, AT5G15850" type="search" name="search" size="40">
<button class="btn btn-primary" type="submit"><i class="fa fa-search"></i> </button>
</div>
</form>
</div>
{% if search_genes %}
<br>
Please pick one of these genes to link:
<br>
<table class="table table-striped table-bordered table-hover">
<thead>
<th>Gene Symbol</th>
<th>Gene Name</th>
<th>Gene ID</th>
<th>Species</th>
</thead>
{% for gene in search_genes %}
<tr>
<td><a href="{% url 'annotations:link_with_gene' annot_pk=annotation.pk gene_pk=gene.meta.id %}">{{ gene.symbol }}</a></td>
<td>{{ gene.name }}</td>
<td>{{ gene.gene_id }}</td>
<td>{{ gene.species.name }}</td>
</tr>
{% endfor %}
</table>
{% endif %}
{% else %}
<h2>You must be a logged in user to use this page.</h2>
{% endif %}
Expand Down
2 changes: 2 additions & 0 deletions annotations/templates/annotations/changes.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ <h3>Summary of approved changes to source annotation <a href=" {% url 'annotatio
<td><a href="{% url 'accounts:info' delta.changed_by %}">{{ delta.changed_by }}</a></td>
<td>{{ delta.datetime }}</td>
</tr>
{% empty %}
The changes may have been entered by a superuser internally and will not show up here
{% endfor %}
</tbody>
{% endfor %}
Expand Down
1 change: 1 addition & 0 deletions annotations/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
path('add_ontology_term/', views.OntologyTermAddView.as_view(), name='add_onto_term'),
path('onto_term/<int:pk>', views.OntologyTermView.as_view(), name='onto_term'),
path('link_internal/<int:pk>', views.LinkInternalView.as_view(), name='link_internal'),
path('link_with_gene/<int:annot_pk>/<int:gene_pk>', views.LinkInternalGeneView.as_view(), name='link_with_gene'),
path('', views.BaseAnnotationView.as_view(), name='base_annotation')

] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
62 changes: 62 additions & 0 deletions annotations/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json

from django.contrib.auth.mixins import LoginRequiredMixin
from django.forms import model_to_dict
from django.utils import timezone

Expand Down Expand Up @@ -282,8 +283,69 @@ def get_context_data(self, **kwargs):
annotation = Annotation.objects.get(pk=annotation_id)
context['annotation'] = annotation

if self.request.GET.get('search'):
s = self.get_queryset()
hit_list = []
for hit in s:
hit_list.append(hit)
context['search_genes'] = hit_list
return context

def get_queryset(self, **kwargs):
search_term = self.request.GET.get('search')
if search_term:
search_term = "*" + search_term + "*"
postresult = ESGeneDocument.search().query("query_string", query=search_term,
fields=["symbol", "name", "gene_id"])
result = postresult
else:
result = None
return result


class LinkInternalGeneView(LoginRequiredMixin, TemplateView):
model = Annotation
template_name = 'annotations/annotation_request.html'

def get(self, request, *args, **kwargs):
context = super(LinkInternalGeneView, self)
user = self.request.user

existing_annotation = get_object_or_404(Annotation, pk=self.kwargs['annot_pk'])
existing_gene = get_object_or_404(Gene, pk=self.kwargs['gene_pk'])

# initialize the changed annotation to the same as the existing
changed_annotation = AnnotationApproval()
for field in existing_annotation._meta.fields:
setattr(changed_annotation, field.name, getattr(existing_annotation, field.name))
# Change the value
changed_annotation.internal_gene = existing_gene

# update status and requestor fields
status = choices.ApprovalStates.PENDING
requestor = self.request.user
curr_time = timezone.now()

# add new values
changed_annotation.status = status
changed_annotation.action = choices.ApprovalActions.INITIAL
changed_annotation.requestor = requestor
changed_annotation.datetime = curr_time
changed_annotation.date = curr_time
changed_annotation.source_annotation = existing_annotation

# Set it to approved already if the user was a superuser
if requestor.is_superuser:
changed_annotation.status = choices.ApprovalStates.APPROVED
changed_annotation.action = choices.ApprovalActions.APPROVE
existing_annotation.internal_gene = existing_gene
existing_annotation.save()

# save it to the db as a AnnotationApproval model
changed_annotation.save()

return render(self.request, 'annotations/annotation_request.html')


class AnnotationSearchGeneView(TemplateView):
template_name = 'annotations/annotation_search_gene.html'
Expand Down

0 comments on commit 774ab78

Please sign in to comment.