eb243a70b264ebc371b81235652a39d383eeab00
[htsworkflow.git] / htsworkflow / frontend / experiments / admin.py
1 from htsworkflow.frontend.experiments.models import FlowCell, DataRun, ClusterStation, Sequencer, Lane
2 from django.contrib import admin
3 from django.contrib.admin.widgets import FilteredSelectMultiple
4 from django.forms import ModelForm
5 from django.forms.fields import Field, CharField
6 from django.forms.widgets import TextInput
7 from django.utils.translation import ugettext_lazy as _
8
9 class DataRunOptions(admin.ModelAdmin):
10   search_fields = [
11       'run_folder',
12       'run_note',
13       'config_params', ]
14   list_display = [
15       'run_folder', 
16       'Flowcell_Info', 
17       'run_start_time',
18       'main_status', 
19       'run_note',
20   ]
21   list_filter = ('run_status', 'run_start_time')
22
23 # lane form setup needs to come before Flowcell form config
24 # as flowcell refers to the LaneInline class
25 class LaneForm(ModelForm):
26     comment = CharField(widget=TextInput(attrs={'size':'80'}), required=False)
27     
28     class Meta:
29         model = Lane
30
31 class LaneInline(admin.StackedInline):
32     """
33     Controls display of Lanes on the Flowcell form.
34     """
35     model = Lane
36     max_num = 8
37     extra = 8
38     form = LaneForm
39     raw_id_fields = ('library',)
40     fieldsets = (
41       (None, {
42         'fields': ('lane_number', 'flowcell',
43                    ('library',),
44                    ('pM', 'cluster_estimate', 'status'),
45                    'comment',)
46       }),
47     )
48
49 class LaneOptions(admin.ModelAdmin):
50     """
51     Controls display of Lane browser
52     """
53     search_fields = ('=flowcell__flowcell_id', 'library__id', 'library__library_name' )
54     list_display = ('flowcell', 'lane_number', 'library', 'comment')
55     fieldsets = (
56       (None, {
57         'fields': ('lane_number', 'flowcell',
58                    ('library'),
59                    ('pM', 'cluster_estimate'))
60       }),
61       ('Optional', {
62         'classes': ('collapse', ),
63         'fields': ('comment', )
64       }),
65     )
66     
67 class FlowCellOptions(admin.ModelAdmin):
68     date_hierarchy = "run_date"
69     save_on_top = True
70     search_fields = ('flowcell_id',
71         'sequencer__name',
72         'cluster_station__name',
73         '=lane__library__id',
74         'lane__library__library_name')
75     list_display = ('flowcell_id','run_date','Lanes')
76     list_filter = ('sequencer','cluster_station')
77     fieldsets = (
78         (None, {
79           'fields': ('run_date', ('flowcell_id','cluster_station','sequencer'),
80                     ('read_length', 'control_lane', 'paired_end'),)
81         }),
82         ('Notes:', { 'fields': ('notes',),}),
83     )
84     inlines = [
85       LaneInline,
86     ]
87
88     def formfield_for_dbfield(self, db_field, **kwargs):
89         field = super(FlowCellOptions, self).formfield_for_dbfield(db_field,
90                                                                    **kwargs)
91         # Override field attributes
92         if db_field.name == "notes":
93             field.widget.attrs["rows"] = "3"
94         return field
95
96 class ClusterStationOptions(admin.ModelAdmin):
97     list_display = ('name', )
98     fieldsets = ( ( None, { 'fields': ( 'name', ) } ), )
99
100 class SequencerOptions(admin.ModelAdmin):
101     list_display = ('name', )
102     fieldsets = ( ( None, { 'fields': ( 'name', ) } ), )
103     
104
105 #admin.site.register(DataRun, DataRunOptions)
106 admin.site.register(FlowCell, FlowCellOptions)
107 admin.site.register(ClusterStation, ClusterStationOptions)
108 admin.site.register(Sequencer, SequencerOptions)
109 admin.site.register(Lane, LaneOptions)