Show software version information on datarun page
[htsworkflow.git] / htsworkflow / frontend / experiments / admin.py
1 from htsworkflow.frontend.experiments.models import \
2      FlowCell, DataRun, DataFile, FileType, ClusterStation, Sequencer, Lane
3 from django.contrib import admin
4 from django.contrib.admin.widgets import FilteredSelectMultiple
5 from django.forms import ModelForm
6 from django.forms.fields import Field, CharField
7 from django.forms.widgets import TextInput
8 from django.utils.translation import ugettext_lazy as _
9
10 class DataFileForm(ModelForm):
11     class Meta:
12         model = DataFile
13
14 class DataFileInline(admin.TabularInline):
15     model = DataFile
16     form = DataFileForm
17     raw_id_fields = ('library',)
18     extra = 0
19
20 class DataRunOptions(admin.ModelAdmin):
21   search_fields = [
22       'flowcell_id',
23       'run_folder',
24       'run_note',
25       ]
26   list_display = [
27       'runfolder_name',
28       'result_dir',
29       'run_start_time',
30   ]
31   fieldsets = (
32       (None, {
33         'fields': (('flowcell', 'run_status'),
34                    ('runfolder_name', 'cycle_start', 'cycle_stop'),
35                    ('result_dir',),
36                    ('last_update_time'),
37                    ('image_software', 'image_version'),
38                    ('basecall_software', 'basecall_version'),
39                    ('alignment_software', 'alignment_version'),
40                    ('comment',))
41       }),
42     )
43   inlines = [ DataFileInline ]
44   #list_filter = ('run_status', 'run_start_time')
45 admin.site.register(DataRun, DataRunOptions)
46
47
48 class FileTypeAdmin(admin.ModelAdmin):
49     list_display = ('name', 'mimetype', 'regex')
50 admin.site.register(FileType, FileTypeAdmin)
51
52 # lane form setup needs to come before Flowcell form config
53 # as flowcell refers to the LaneInline class
54 class LaneForm(ModelForm):
55     comment = CharField(widget=TextInput(attrs={'size':'80'}), required=False)
56
57     class Meta:
58         model = Lane
59
60 class LaneInline(admin.StackedInline):
61     """
62     Controls display of Lanes on the Flowcell form.
63     """
64     model = Lane
65     extra = 8
66     form = LaneForm
67     raw_id_fields = ('library',)
68     fieldsets = (
69       (None, {
70         'fields': ('lane_number', 'flowcell',
71                    ('library',),
72                    ('pM', 'cluster_estimate', 'status'),
73                    'comment',)
74       }),
75     )
76
77 class LaneOptions(admin.ModelAdmin):
78     """
79     Controls display of Lane browser
80     """
81     search_fields = ('=flowcell__flowcell_id', 'library__id', 'library__library_name' )
82     list_display = ('flowcell', 'lane_number', 'library', 'comment')
83     fieldsets = (
84       (None, {
85         'fields': ('lane_number', 'flowcell',
86                    ('library'),
87                    ('pM', 'cluster_estimate'))
88       }),
89       ('Optional', {
90         'classes': ('collapse', ),
91         'fields': ('comment', )
92       }),
93     )
94 admin.site.register(Lane, LaneOptions)
95
96 class FlowCellOptions(admin.ModelAdmin):
97     date_hierarchy = "run_date"
98     save_on_top = True
99     search_fields = ('flowcell_id',
100         'sequencer__name',
101         'cluster_station__name',
102         '=lane__library__id',
103         'lane__library__library_name')
104     list_display = ('flowcell_id','run_date','Lanes')
105     list_filter = ('sequencer','cluster_station')
106     fieldsets = (
107         (None, {
108           'fields': ('run_date', ('flowcell_id','cluster_station','sequencer'),
109                     ('read_length', 'control_lane', 'paired_end'),)
110         }),
111         ('Notes:', { 'fields': ('notes',),}),
112     )
113     inlines = [
114       LaneInline,
115     ]
116
117     def formfield_for_dbfield(self, db_field, **kwargs):
118         field = super(FlowCellOptions, self).formfield_for_dbfield(db_field,
119                                                                    **kwargs)
120         # Override field attributes
121         if db_field.name == "notes":
122             field.widget.attrs["rows"] = "3"
123         return field
124 admin.site.register(FlowCell, FlowCellOptions)
125
126 class ClusterStationOptions(admin.ModelAdmin):
127     list_display = ('name', )
128     fieldsets = ( ( None, { 'fields': ( 'name', ) } ), )
129 admin.site.register(ClusterStation, ClusterStationOptions)
130
131 class SequencerOptions(admin.ModelAdmin):
132     list_display = ('name', 'instrument_name', 'model')
133     fieldsets = ( ( None,
134                     { 'fields': (
135                         'name', 'instrument_name', 'serial_number',
136                         'model', 'comment') } ), )
137 admin.site.register(Sequencer, SequencerOptions)