Change experiments.FileType.regex to a text field so it can be arbitrarily long.
[htsworkflow.git] / htsworkflow / frontend / experiments / admin.py
index b915def496b069f68c7cf504923545430d3a9212..1a27a17c6ffc2a1e19898947960a50347a89643f 100644 (file)
@@ -1,5 +1,6 @@
+from itertools import chain
 from htsworkflow.frontend.experiments.models import \
-     FlowCell, DataRun, DataFile, FileType, ClusterStation, Sequencer, Lane
+     FlowCell, FlowCellModel, DataRun, DataFile, FileType, ClusterStation, Sequencer, Lane
 from django.contrib import admin
 from django.contrib.admin.widgets import FilteredSelectMultiple
 from django.forms import ModelForm
@@ -48,7 +49,13 @@ admin.site.register(DataRun, DataRunOptions)
 
 
 class FileTypeAdmin(admin.ModelAdmin):
-    list_display = ('name', 'mimetype', 'regex')
+    list_display = ('name', 'mimetype', 'regex', 'regex_is_valid')
+    fieldsets = (
+        (None, {
+            'fields': (('name', 'mimetype'),
+                       ('regex'))
+            }
+        )),
 admin.site.register(FileType, FileTypeAdmin)
 
 # lane form setup needs to come before Flowcell form config
@@ -95,6 +102,14 @@ class LaneOptions(admin.ModelAdmin):
     )
 admin.site.register(Lane, LaneOptions)
 
+class FlowCellModelOptions(admin.ModelAdmin):
+    search_fields = ('name',)
+    list_display = ('name', 'fixed_time', 'per_cycle_time', 'isdefault')
+    fieldsets = (
+        (None, { 'fields': ('name', 'fixed_time', 'per_cycle_time', 'isdefault') }),
+        )
+admin.site.register(FlowCellModel, FlowCellModelOptions)
+
 class FlowCellOptions(admin.ModelAdmin):
     class Media:
         css = { 'all': ('css/admin_flowcell.css',) }
@@ -106,11 +121,11 @@ class FlowCellOptions(admin.ModelAdmin):
         '=lane__library__id',
         'lane__library__library_name')
     list_display = ('flowcell_id','run_date','Lanes')
-    list_filter = ('sequencer','cluster_station')
+    list_filter = ('sequencer','cluster_station', 'paired_end')
     fieldsets = (
         (None, {
           'fields': ('run_date', ('flowcell_id','cluster_station','sequencer'),
-                    ('read_length', 'control_lane', 'paired_end'),)
+                    ('flowcell_model', 'read_length', 'paired_end', 'control_lane', ),)
         }),
         ('Notes:', { 'fields': ('notes',),}),
     )
@@ -128,22 +143,56 @@ class FlowCellOptions(admin.ModelAdmin):
             # 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)
+            field.widget.widget = SequencerSelect(attrs=attrs, queryset=field.queryset)
         elif db_field.name == "notes":
             field.widget.attrs["rows"] = "3"
         return field
 admin.site.register(FlowCell, FlowCellOptions)
 
 class ClusterStationOptions(admin.ModelAdmin):
-    list_display = ('name', )
-    fieldsets = ( ( None, { 'fields': ( 'name', ) } ), )
+    list_display = ('name', 'isdefault',)
+    fieldsets = ( ( None, { 'fields': ( 'name', 'isdefault') } ), )
 admin.site.register(ClusterStation, ClusterStationOptions)
 
 class SequencerSelect(Select):
+    def __init__(self, queryset=None, *args, **kwargs):
+        super(SequencerSelect, self).__init__(*args, **kwargs)
+        self.queryset = queryset
+
+    def render_options(self, choices, selected_choices):
+        # Normalize to strings.
+        selected_choices = set([force_unicode(v) for v in selected_choices])
+        output = []
+        for option_value, option_label in chain(self.choices, choices):
+            if isinstance(option_label, (list, tuple)):
+                output.append(u'<optgroup label="%s">' % escape(force_unicode(option_value)))
+                for option in option_label:
+                    output.append(self.render_option(selected_choices, *option))
+                output.append(u'</optgroup>')
+            else:
+                output.append(self.render_option(selected_choices, option_value, option_label))
+        return u'\n'.join(output)
+
+    # render_options blatently grabbed from 1.3.1 as the 1.2 version
+    # has render_option, which is what I needed to overload as a
+    # nested function in render_options
+    def render_options(self, choices, selected_choices):
+        # Normalize to strings.
+        selected_choices = set([force_unicode(v) for v in selected_choices])
+        output = []
+        for option_value, option_label in chain(self.choices, choices):
+            if isinstance(option_label, (list, tuple)):
+                output.append(u'<optgroup label="%s">' % escape(force_unicode(option_value)))
+                for option in option_label:
+                    output.append(self.render_option(selected_choices, *option))
+                output.append(u'</optgroup>')
+            else:
+                output.append(self.render_option(selected_choices, option_value, option_label))
+        return u'\n'.join(output)
+
+
     def render_option(self, selected_choices, option_value, option_label):
-        disabled_sequencers = self.attrs.get('disabled_sequencers', [])
+        disabled_sequencers = [ unicode(s.id) for s in self.queryset.filter(active=False) ]
         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 ''
@@ -152,10 +201,10 @@ class SequencerSelect(Select):
             conditional_escape(force_unicode(option_label)))
 
 class SequencerOptions(admin.ModelAdmin):
-    list_display = ('name', 'active', 'instrument_name', 'model')
+    list_display = ('name', 'active', 'isdefault', 'instrument_name', 'model')
     fieldsets = ( ( None,
                     { 'fields': (
-                        'name', 'active', 'instrument_name', 'serial_number',
+                        'name', ('active', 'isdefault'), 'instrument_name', 'serial_number',
                         'model', 'comment') } ), )
 
 admin.site.register(Sequencer, SequencerOptions)