4181e5c91aef2aa0d2a7af9b2d0bddcc37ad65e6
[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                    ('comment',))
38       }),
39     )
40   inlines = [ DataFileInline ]
41   #list_filter = ('run_status', 'run_start_time')
42 admin.site.register(DataRun, DataRunOptions)
43
44
45 class FileTypeAdmin(admin.ModelAdmin):
46     list_display = ('name', 'mimetype', 'regex')
47 admin.site.register(FileType, FileTypeAdmin)
48   
49 # lane form setup needs to come before Flowcell form config
50 # as flowcell refers to the LaneInline class
51 class LaneForm(ModelForm):
52     comment = CharField(widget=TextInput(attrs={'size':'80'}), required=False)
53     
54     class Meta:
55         model = Lane
56
57 class LaneInline(admin.StackedInline):
58     """
59     Controls display of Lanes on the Flowcell form.
60     """
61     model = Lane
62     max_num = 8
63     extra = 8
64     form = LaneForm
65     raw_id_fields = ('library',)
66     fieldsets = (
67       (None, {
68         'fields': ('lane_number', 'flowcell',
69                    ('library',),
70                    ('pM', 'cluster_estimate', 'status'),
71                    'comment',)
72       }),
73     )
74
75 class LaneOptions(admin.ModelAdmin):
76     """
77     Controls display of Lane browser
78     """
79     search_fields = ('=flowcell__flowcell_id', 'library__id', 'library__library_name' )
80     list_display = ('flowcell', 'lane_number', 'library', 'comment')
81     fieldsets = (
82       (None, {
83         'fields': ('lane_number', 'flowcell',
84                    ('library'),
85                    ('pM', 'cluster_estimate'))
86       }),
87       ('Optional', {
88         'classes': ('collapse', ),
89         'fields': ('comment', )
90       }),
91     )
92 admin.site.register(Lane, LaneOptions)
93     
94 class FlowCellOptions(admin.ModelAdmin):
95     date_hierarchy = "run_date"
96     save_on_top = True
97     search_fields = ('flowcell_id',
98         'sequencer__name',
99         'cluster_station__name',
100         '=lane__library__id',
101         'lane__library__library_name')
102     list_display = ('flowcell_id','run_date','Lanes')
103     list_filter = ('sequencer','cluster_station')
104     fieldsets = (
105         (None, {
106           'fields': ('run_date', ('flowcell_id','cluster_station','sequencer'),
107                     ('read_length', 'control_lane', 'paired_end'),)
108         }),
109         ('Notes:', { 'fields': ('notes',),}),
110     )
111     inlines = [
112       LaneInline,
113     ]
114
115     def formfield_for_dbfield(self, db_field, **kwargs):
116         field = super(FlowCellOptions, self).formfield_for_dbfield(db_field,
117                                                                    **kwargs)
118         # Override field attributes
119         if db_field.name == "notes":
120             field.widget.attrs["rows"] = "3"
121         return field
122 admin.site.register(FlowCell, FlowCellOptions)
123
124 class ClusterStationOptions(admin.ModelAdmin):
125     list_display = ('name', )
126     fieldsets = ( ( None, { 'fields': ( 'name', ) } ), )
127 admin.site.register(ClusterStation, ClusterStationOptions)
128
129 class SequencerOptions(admin.ModelAdmin):
130     list_display = ('name', )
131     fieldsets = ( ( None, { 'fields': ( 'name', ) } ), )
132 admin.site.register(Sequencer, SequencerOptions)