From: Diane Trout Date: Sat, 23 Jun 2012 00:38:17 +0000 (-0700) Subject: Add an 'active' state to the sequencers. X-Git-Tag: v0.5.5~10 X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=htsworkflow.git;a=commitdiff_plain;h=d188105c2937068e4bbcf6dbf5229a85725a2e7d Add an 'active' state to the sequencers. On the flowcell admin page hack the sequencer select combo box to strike out the disabled ones. (Yes it involves hacking an override into the FlowCell admin form by replacing the default widget it creates. Maybe there's a cleaner way, but I didn't figure it out) --- diff --git a/htsworkflow/frontend/experiments/admin.py b/htsworkflow/frontend/experiments/admin.py index 60072e7..b915def 100644 --- a/htsworkflow/frontend/experiments/admin.py +++ b/htsworkflow/frontend/experiments/admin.py @@ -4,7 +4,9 @@ from django.contrib import admin from django.contrib.admin.widgets import FilteredSelectMultiple from django.forms import ModelForm from django.forms.fields import Field, CharField -from django.forms.widgets import TextInput +from django.forms.widgets import TextInput, Select +from django.utils.encoding import force_unicode +from django.utils.html import escape, conditional_escape from django.utils.translation import ugettext_lazy as _ class DataFileForm(ModelForm): @@ -94,6 +96,8 @@ class LaneOptions(admin.ModelAdmin): admin.site.register(Lane, LaneOptions) class FlowCellOptions(admin.ModelAdmin): + class Media: + css = { 'all': ('css/admin_flowcell.css',) } date_hierarchy = "run_date" save_on_top = True search_fields = ('flowcell_id', @@ -117,8 +121,17 @@ class FlowCellOptions(admin.ModelAdmin): def formfield_for_dbfield(self, db_field, **kwargs): field = super(FlowCellOptions, self).formfield_for_dbfield(db_field, **kwargs) + # Override field attributes - if db_field.name == "notes": + if db_field.name == 'sequencer': + # seems kind of clunky. + # the goal is to replace the default select/combo box with one + # that can strike out disabled options. + attrs = field.widget.widget.attrs + disabled_sequencers = field.queryset.filter(active=False) + attrs['disabled_sequencers'] = [ unicode(s.id) for s in disabled_sequencers ] + field.widget.widget = SequencerSelect(attrs=attrs) + elif db_field.name == "notes": field.widget.attrs["rows"] = "3" return field admin.site.register(FlowCell, FlowCellOptions) @@ -128,10 +141,21 @@ class ClusterStationOptions(admin.ModelAdmin): fieldsets = ( ( None, { 'fields': ( 'name', ) } ), ) admin.site.register(ClusterStation, ClusterStationOptions) +class SequencerSelect(Select): + def render_option(self, selected_choices, option_value, option_label): + disabled_sequencers = self.attrs.get('disabled_sequencers', []) + option_value = unicode(option_value) + selected_html = (option_value in selected_choices) and u' selected="selected"' or '' + cssclass = "strikeout" if option_value in disabled_sequencers else '' + return u'' % ( + cssclass, escape(option_value), selected_html, + conditional_escape(force_unicode(option_label))) + class SequencerOptions(admin.ModelAdmin): - list_display = ('name', 'instrument_name', 'model') + list_display = ('name', 'active', 'instrument_name', 'model') fieldsets = ( ( None, { 'fields': ( - 'name', 'instrument_name', 'serial_number', + 'name', 'active', 'instrument_name', 'serial_number', 'model', 'comment') } ), ) + admin.site.register(Sequencer, SequencerOptions) diff --git a/htsworkflow/frontend/experiments/fixtures/initial_data.json b/htsworkflow/frontend/experiments/fixtures/initial_data.json index 3b4d1d5..ff619ce 100644 --- a/htsworkflow/frontend/experiments/fixtures/initial_data.json +++ b/htsworkflow/frontend/experiments/fixtures/initial_data.json @@ -112,6 +112,7 @@ "instrument_name": "ILLUMINA-33A494", "serial_number": "", "model": "Illumina Genome Analyzer II", + "active": false, "comment": "after 2010 pipeline name, was exchanged for hiseq" } }, @@ -122,6 +123,7 @@ "instrument_name": "ILLUMINA-EC5D15", "serial_number": "", "model": "Illumina Genome Analyzer IIx", + "active": true, "comment": "after 2010 pipeline name" } }, @@ -132,6 +134,7 @@ "instrument_name": "", "serial_number": "", "model": "Unknown", + "active": false, "comment": "Sequenced somewhere else" } }, @@ -142,6 +145,7 @@ "instrument_name": "HWI-ST0787", "serial_number": "", "model": "Illumina HiSeq 2000", + "active": true, "comment": "" } }, @@ -152,6 +156,7 @@ "instrument_name": "HWUSI-EAS627", "serial_number": "", "model": "Illumina Genome Analyzer II", + "active": false, "comment": "earlier version of tardigrade" } }, @@ -162,6 +167,7 @@ "instrument_name": "HWUSI-EAS229", "serial_number": "", "model": "Illumina Genome Analyzer II", + "active": false, "comment": "earlier rotifer name" } }, @@ -172,6 +178,7 @@ "instrument_name": "USI-EAS44", "serial_number": "", "model": "Illumina Genome Analyzer I", + "active": false, "comment": "our first sequencer" } } diff --git a/htsworkflow/frontend/experiments/models.py b/htsworkflow/frontend/experiments/models.py index bf353e1..25707f3 100644 --- a/htsworkflow/frontend/experiments/models.py +++ b/htsworkflow/frontend/experiments/models.py @@ -55,14 +55,19 @@ class Sequencer(models.Model): instrument_name = models.CharField(max_length=50, db_index=True) serial_number = models.CharField(max_length=50, db_index=True) model = models.CharField(max_length=255) + active = models.BooleanField(default=True, null=False) comment = models.CharField(max_length=255) + class Meta: + ordering = ["-active", "name"] + def __unicode__(self): name = [unicode(self.name)] if self.instrument_name is not None: name.append("(%s)" % (unicode(self.instrument_name),)) return " ".join(name) + @models.permalink def get_absolute_url(self): return ('htsworkflow.frontend.experiments.views.sequencer',