Add search field to the lanes admin page
[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'), ('read_length', 'control_lane', 'paired_end'),)
80         }),
81         #('Lanes:', {
82         #   'fields' : (('lane__library__id', 'lane__pM', 'lane__cluster_estimate'),)
83         #}),
84         ('Notes:', { 'fields': ('notes',),}),
85     )
86     inlines = [
87       LaneInline,
88     ]
89
90 class ClusterStationOptions(admin.ModelAdmin):
91     list_display = ('name', )
92     fieldsets = ( ( None, { 'fields': ( 'name', ) } ), )
93
94 class SequencerOptions(admin.ModelAdmin):
95     list_display = ('name', )
96     fieldsets = ( ( None, { 'fields': ( 'name', ) } ), )
97     
98
99 admin.site.register(DataRun, DataRunOptions)
100 admin.site.register(FlowCell, FlowCellOptions)
101 admin.site.register(ClusterStation, ClusterStationOptions)
102 admin.site.register(Sequencer, SequencerOptions)
103 admin.site.register(Lane, LaneOptions)