Add an 'active' state to the sequencers.
authorDiane Trout <diane@caltech.edu>
Sat, 23 Jun 2012 00:38:17 +0000 (17:38 -0700)
committerDiane Trout <diane@caltech.edu>
Sat, 23 Jun 2012 00:38:17 +0000 (17:38 -0700)
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)

htsworkflow/frontend/experiments/admin.py
htsworkflow/frontend/experiments/fixtures/initial_data.json
htsworkflow/frontend/experiments/models.py

index 60072e7ad6e4d04b210c6212688641463b3eb144..b915def496b069f68c7cf504923545430d3a9212 100644 (file)
@@ -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'<option class="%s" value="%s"%s>%s</option>' % (
+            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)
index 3b4d1d57fec7df03be3723188c44d66a2d87aae3..ff619ce91c7ee91524e5776c8ae8214905aa10ef 100644 (file)
       "instrument_name": "ILLUMINA-33A494",
       "serial_number": "",
       "model": "Illumina Genome Analyzer II",
+      "active": false,
       "comment": "after 2010 pipeline name, was exchanged for hiseq"
     }
   },
       "instrument_name": "ILLUMINA-EC5D15",
       "serial_number": "",
       "model": "Illumina Genome Analyzer IIx",
+      "active": true,
       "comment": "after 2010 pipeline name"
     }
   },
       "instrument_name": "",
       "serial_number": "",
       "model": "Unknown",
+      "active": false,
       "comment": "Sequenced somewhere else"
     }
   },
       "instrument_name": "HWI-ST0787",
       "serial_number": "",
       "model": "Illumina HiSeq 2000",
+      "active": true,
       "comment": ""
     }
   },
       "instrument_name": "HWUSI-EAS627",
       "serial_number": "",
       "model": "Illumina Genome Analyzer II",
+      "active": false,
       "comment": "earlier version of tardigrade"
     }
   },
       "instrument_name": "HWUSI-EAS229",
       "serial_number": "",
       "model": "Illumina Genome Analyzer II",
+      "active": false,
       "comment": "earlier rotifer name"
     }
   },
       "instrument_name": "USI-EAS44",
       "serial_number": "",
       "model": "Illumina Genome Analyzer I",
+      "active": false,
       "comment": "our first sequencer"
     }
   }
index bf353e1a3898eda784bc87a019ec55ae924cd49e..25707f3166aefcb681946a40ee23fbd0f3017ec2 100644 (file)
@@ -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',