From 9de60f4acce6aeb35afb3a427b93e8c3a4afdb96 Mon Sep 17 00:00:00 2001 From: carlosp420 Date: Tue, 28 Apr 2015 23:20:10 +0300 Subject: [PATCH] speed up showing the list of genes for voucher --- .../management/commands/_migrate_db.py | 4 ++ .../public_interface/show_voucher.html | 2 +- voseq/public_interface/views.py | 40 +++++++------------ 3 files changed, 20 insertions(+), 26 deletions(-) diff --git a/voseq/public_interface/management/commands/_migrate_db.py b/voseq/public_interface/management/commands/_migrate_db.py index c59d85f9..5b74c0c2 100644 --- a/voseq/public_interface/management/commands/_migrate_db.py +++ b/voseq/public_interface/management/commands/_migrate_db.py @@ -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() diff --git a/voseq/public_interface/templates/public_interface/show_voucher.html b/voseq/public_interface/templates/public_interface/show_voucher.html index bccc6a6f..7ee288c8 100644 --- a/voseq/public_interface/templates/public_interface/show_voucher.html +++ b/voseq/public_interface/templates/public_interface/show_voucher.html @@ -297,7 +297,7 @@

Sequence Information

{{ item.gene_code }} {{ item.sequence_length }} - {{ item.ambiguous_seq_length }} + {{ item.number_ambiguous_bp }} {{ item.labPerson }} {{ item.accession }} diff --git a/voseq/public_interface/views.py b/voseq/public_interface/views.py index 3f8622d1..020c567c 100644 --- a/voseq/public_interface/views.py +++ b/voseq/public_interface/views.py @@ -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, @@ -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/') @@ -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) - - - - - -