Skip to content

Commit

Permalink
speed up showing the list of genes for voucher
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosp420 committed Apr 28, 2015
1 parent 2ffe5ea commit 9de60f4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 26 deletions.
4 changes: 4 additions & 0 deletions voseq/public_interface/management/commands/_migrate_db.py
Expand Up @@ -336,6 +336,10 @@ def import_table_sequences(self):

item['time_edited'] = date_obj

ambiguous_chars = item['sequences'].count('?') + item['sequences'].count('-')
ambiguous_chars += item['sequences'].count('N') + item['sequences'].count('n')
item['number_ambiguous_bp'] = ambiguous_chars

def save_table_sequences_to_db(self):
if self.table_sequences_items is None:
self.import_table_sequences()
Expand Down
Expand Up @@ -297,7 +297,7 @@ <h3 class="panel-title"><b>Sequence Information</b></h3>
<tr>
<td><a href="/s/{{ item.code.code }}/{{ item.gene_code }}/">{{ item.gene_code }}</a></td>
<td>{{ item.sequence_length }}</td>
<td>{{ item.ambiguous_seq_length }}</td>
<td>{{ item.number_ambiguous_bp }}</td>
<td>{{ item.labPerson }}</td>
<td><a href="http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=Search&db=nucleotide&term={{ item.accession }}[accn]&doptcmdl=GenBank">{{ item.accession }}</a></td>
<td class="text-center">
Expand Down
40 changes: 15 additions & 25 deletions voseq/public_interface/views.py
Expand Up @@ -90,13 +90,9 @@ def show_voucher(request, voucher_code):

images_queryset = FlickrImages.objects.filter(voucher=voucher_code)

seqs_queryset = Sequences.objects.filter(code=voucher_code).order_by('gene_code')
for item in seqs_queryset:
seq = item.sequences
item.sequence_length = len(seq)
item.ambiguous_seq_length = seq.count('?') + seq.count('-') + seq.count('N') + seq.count('n')
if item.labPerson is not None:
item.labPerson = item.labPerson.split(" ")[0]
seqs_queryset = Sequences.objects.filter(code=voucher_code).values('code', 'gene_code',
'number_ambiguous_bp',
'labPerson')

return render(request, 'public_interface/show_voucher.html',
{'voucher': voucher_queryset,
Expand Down Expand Up @@ -135,32 +131,32 @@ def show_sequence(request, voucher_code, gene_code):
@csrf_protect
def change_selected(request, selected):
"""
Changes field values from Vouchers in batch.
This action first displays a change form page whichs shows all the
fields of a Vouchers type.
Next, it changes all selected objects and redirects back to the changed list.
The action that calls this function should raise a PermissionDenied
if the user has no rights for changes.
"""
Changes field values from Vouchers in batch.
This action first displays a change form page whichs shows all the
fields of a Vouchers type.
Next, it changes all selected objects and redirects back to the changed list.
The action that calls this function should raise a PermissionDenied
if the user has no rights for changes.
"""

# The user has already proposed the changes.
# Apply the changes and return a None to display the changed list.

if request.method == 'POST':
form = BatchChangesForm(request.POST)
ids = selected.split(",")
queryset = Vouchers.objects.filter(pk__in=ids)
n = queryset.count()

if n and form.is_valid():
# do changes
keywords = {}
for field, value in form.cleaned_data.items():
if value:
keywords[field] = value

queryset.update(**keywords)

return HttpResponseRedirect('/admin/public_interface/vouchers/')
Expand All @@ -171,9 +167,3 @@ def change_selected(request, selected):
# Display the changes page
context = {'form': form, 'selected': selected}
return render(request, 'admin/public_interface/vouchers/batch_changes.html', context)






0 comments on commit 9de60f4

Please sign in to comment.