Add support for tracking the multiplex index sequence.
[htsworkflow.git] / htsworkflow / frontend / samples / admin.py
index 345e32ac4167723caa52873f4275267ed915ebe4..bcd77e2ca26e9db6d51ece2e41a33862ee92e686 100644 (file)
@@ -6,8 +6,11 @@ from django.contrib.auth.forms import UserCreationForm, UserChangeForm
 from django.template import Context, Template
 from django.db import models
 from django.utils.translation import ugettext_lazy as _
+from django.forms import TextInput, Textarea
 
-from htsworkflow.frontend.samples.models import Antibody, Cellline, Condition, ExperimentType, HTSUser, LibraryType, Species, Affiliation, Library, Tag
+from htsworkflow.frontend.samples.models import \
+     Antibody, Cellline, Condition, ExperimentType, HTSUser, \
+     LibraryType, MultiplexIndex, Species, Affiliation, Library, Tag
 from htsworkflow.frontend.experiments.models import Lane
 from htsworkflow.frontend.inventory.models import PrinterTemplate
 from htsworkflow.frontend.bcmagic.utils import print_zpl_socket
@@ -23,7 +26,7 @@ class AffiliationOptions(admin.ModelAdmin):
       }),
     )
 
-    # some post 1.0.2 version of django has formfield_overrides 
+    # some post 1.0.2 version of django has formfield_overrides
     # which would replace this code with:
     # formfield_overrids = {
     #   models.ManyToMany: { 'widget': widgets.FilteredSelectMultiple }
@@ -46,11 +49,11 @@ class AntibodyOptions(admin.ModelAdmin):
      )
 
 class CelllineOptions(admin.ModelAdmin):
-    list_display = ('cellline_name', 'nickname', 'notes')
+    list_display = ('cellline_name', 'notes')
     search_fields = ('cellline_name', 'nickname', 'notes')
     fieldsets = (
       (None, {
-          'fields': (('cellline_name'),('notes'),)
+          'fields': (('cellline_name','nickname',),('notes'),)
       }),
      )
 
@@ -75,7 +78,7 @@ class HTSUserCreationForm(UserCreationForm):
 class HTSUserChangeForm(UserChangeForm):
     class Meta:
         model = HTSUser
-        
+
 class HTSUserOptions(UserAdmin):
     form = HTSUserChangeForm
     add_form = HTSUserCreationForm
@@ -88,14 +91,19 @@ class Library_Inline(admin.TabularInline):
   model = Library
 
 class LibraryTypeOptions(admin.ModelAdmin):
+    list_display = ['name', 'is_paired_end', 'can_multiplex']
     model = LibraryType
 
+class MultiplexIndexOptions(admin.ModelAdmin):
+    model = MultiplexIndex
+    list_display = ['adapter_type', 'multiplex_id', 'sequence']
+
 class LibraryOptions(admin.ModelAdmin):
     class Media:
         css = {
             "all": ("css/wide_account_number.css",)
             }
-        
+
     date_hierarchy = "creation_date"
     save_as = True
     save_on_top = True
@@ -108,108 +116,108 @@ class LibraryOptions(admin.ModelAdmin):
     )
     list_display = (
         'id',
-        #'aligned_reads',
-        #'DataRun',
         'library_name',
-        'public',
-        #'experiment_type',
-        #'organism',
-        #'antibody_name',
-        #'cell_line',
-        #'libtags',
-        #'made_for',
+        'index_sequence_text',
         'affiliation',
-        #'made_by',
         'undiluted_concentration',
+        'gel_cut_size',
         'creation_date',
-        'stopping_point',
-        #'condition',
-
     )
     list_filter = (
-        'experiment_type', 
-        'library_species', 
-        'tags',
-        #'made_for',
+        'hidden',
         'affiliations',
-        'made_by', 
-        'antibody',
+        'library_species',
+        'experiment_type',
+        'made_by',
         'cell_line',
-        'condition',
-        'stopping_point',
-        'hidden')
+        'stopping_point',)
     list_display_links = ('id', 'library_name',)
     fieldsets = (
       (None, {
         'fields': (
           ('id','library_name','hidden'),
-          ('library_species'),
-          ('library_type', 'experiment_type', 'replicate'),
-          ('cell_line','condition','antibody'),)
+          ('library_species', 'experiment_type'),
+          ('library_type', 'multiplex_id'),
+          )
          }),
+         ('Experiment Detail:', {
+            'fields': (('cell_line', 'replicate',),
+                       ('condition',),
+                       ('antibody', ),
+                       ),
+            'classes': ('collapse',),
+            }),
          ('Creation Information:', {
-             'fields' : (('made_for', 'made_by', 'creation_date'), ('stopping_point', 'amplified_from_sample'), ('avg_lib_size','undiluted_concentration', 'ten_nM_dilution', 'successful_pM'), 'account_number', 'notes',)
+             'fields' : (('made_by', 'creation_date', 'stopping_point'),
+                         ('amplified_from_sample'),
+                         ('gel_cut_size', 'insert_size',
+                          'undiluted_concentration'),
+                         ('bioanalyzer_concentration','bioanalyzer_image_url'),
+                         ('bioanalyzer_summary'),
+                         ('notes'))
          }),
          ('Library/Project Affiliation:', {
-             'fields' : (('affiliations'), ('tags'),)
+             'fields' : (('account_number', 'affiliations'),)
          }),
          )
     inlines = [
       LaneLibraryInline,
     ]
     actions = ['action_print_library_labels']
-    
-    
+
     def action_print_library_labels(self, request, queryset):
         """
         Django action which prints labels for the selected set of labels from the
         Django Admin interface.
         """
-        
+
         #Probably should ask if the user really meant to print all selected
         # libraries if the count is above X. X=10 maybe?
-        
+
         # Grab the library template
         #FIXME: Hardcoding library template name. Not a good idea... *sigh*.
         EVIL_HARDCODED_LIBRARY_TEMPLATE_NAME = "Library"
-        
+
         try:
             template = PrinterTemplate.objects.get(item_type__name=EVIL_HARDCODED_LIBRARY_TEMPLATE_NAME)
         except PrinterTemplate.DoesNotExist:
             self.message_user(request, "Could not find a library template with ItemType.name of '%s'" % \
                               (EVIL_HARDCODED_LIBRARY_TEMPLATE_NAME))
             return
-        
+
         # ZPL Template
         t = Template(template.template)
-        
+
+        zpl_list = []
         #Iterate over selected labels to print
         for library in queryset.all():
-            
+
             # Django Template Context
             c = Context({'library': library})
-            
+
             # Send rendered template to the printer that the template
             #  object has been attached to in the database.
-            print_zpl_socket(t.render(c), host=template.printer.ip_address)
-    
-        self.message_user(request, "%s labels printed." % (len(queryset)))
-                          
-    action_print_library_labels.short_description = "Print Labels"
+            zpl_list.append(t.render(c))
 
+        print_zpl_socket(zpl_list, host=template.printer.ip_address)
 
+        self.message_user(request, "%s labels printed." % (len(queryset)))
+
+    action_print_library_labels.short_description = "Print Labels"
 
-    # some post 1.0.2 version of django has formfield_overrides 
-    # which would replace this code with:
-    # formfield_overrids = {
-    #    models.ManyToMany: { 'widget': widgets.FilteredSelectMultiple }
-    #}
     def formfield_for_dbfield(self, db_field, **kwargs):
-      if db_field.name in ('affiliations', 'tags'):
-        kwargs['widget'] = widgets.FilteredSelectMultiple(db_field.verbose_name,
-                                                          (db_field.name in self.filter_vertical))
-      rv = super(LibraryOptions, self).formfield_for_dbfield(db_field, **kwargs)
-      return rv
+        # Override Field type
+        if db_field.name in ('affiliations', 'tags'):
+            kwargs['widget'] = widgets.FilteredSelectMultiple(
+                db_field.verbose_name,
+                (db_field.name in self.filter_vertical)
+            )
+        field = super(LibraryOptions, self).formfield_for_dbfield(db_field,
+                                                                  **kwargs)
+        # Override field attributes
+        if db_field.name == "bioanalyzer_summary":
+            field.widget.attrs["rows"] = "3"
+        return field
 
 class SpeciesOptions(admin.ModelAdmin):
     fieldsets = (
@@ -220,19 +228,20 @@ class SpeciesOptions(admin.ModelAdmin):
 
 class TagOptions(admin.ModelAdmin):
     list_display = ('tag_name', 'context')
-    fieldsets = ( 
+    fieldsets = (
         (None, {
           'fields': ('tag_name', 'context')
           }),
         )
 
+admin.site.register(Library, LibraryOptions)
 admin.site.register(Affiliation, AffiliationOptions)
 admin.site.register(Antibody, AntibodyOptions)
 admin.site.register(Cellline, CelllineOptions)
 admin.site.register(Condition, ConditionOptions)
 admin.site.register(ExperimentType, ExperimentTypeOptions)
-admin.site.register(HTSUser, HTSUserOptions)
+#admin.site.register(HTSUser, HTSUserOptions)
 admin.site.register(LibraryType, LibraryTypeOptions)
-admin.site.register(Library, LibraryOptions)
+admin.site.register(MultiplexIndex, MultiplexIndexOptions)
 admin.site.register(Species, SpeciesOptions)
-admin.site.register(Tag, TagOptions)
+#admin.site.register(Tag, TagOptions)