Initial port to python3
[htsworkflow.git] / htsworkflow / frontend / eland_config / forms.py
1 from django import forms
2 from django.forms.util import ErrorList
3
4
5 SPECIES_LIST = [#('--choose--', '--Choose--'),
6                 ('hg18', 'Homo sapiens (Hg18)'),
7                 ('Mm8', 'Mus musculus (Mm8)'),
8                 ('arabv6', 'Arabadopsis Thaliana v6'),
9                 ('other', 'Other species (Include in description)')]
10
11
12 class DivErrorList(ErrorList):
13   def __unicode__(self):
14     return self.as_divs()
15   
16   def as_divs(self):
17     if not self: return ''
18     return '<div class="errorlist">%s</div>' % (''.join(['<div class="error">%s</div>' % e for e in self]))
19
20
21
22 class ConfigForm(forms.Form):
23   
24   flow_cell_number = forms.CharField(min_length=2)
25   run_date = forms.DateTimeField()
26   advanced_run = forms.BooleanField(required=False)
27   read_length = forms.IntegerField(min_value=1, initial=32)
28   #eland_repeat = forms.BooleanField()
29   
30   #needs a for loop or something to allow for n configurations
31   #analysis_type = forms.ChoiceField(choices=[('eland','eland')])
32   lane1_species = forms.ChoiceField(choices=SPECIES_LIST)
33   lane1_description = forms.CharField(widget=forms.TextInput(attrs={'size':'60'}))
34   
35   lane2_species = forms.ChoiceField(choices=SPECIES_LIST)
36   lane2_description = forms.CharField(widget=forms.TextInput(attrs={'size':'60'}))
37   
38   lane3_species = forms.ChoiceField(choices=SPECIES_LIST)
39   lane3_description = forms.CharField(widget=forms.TextInput(attrs={'size':'60'}))
40   
41   lane4_species = forms.ChoiceField(choices=SPECIES_LIST)
42   lane4_description = forms.CharField(widget=forms.TextInput(attrs={'size':'60'}))
43   
44   lane5_species = forms.ChoiceField(choices=SPECIES_LIST)
45   lane5_description = forms.CharField(widget=forms.TextInput(attrs={'size':'60'}))
46   
47   lane6_species = forms.ChoiceField(choices=SPECIES_LIST)
48   lane6_description = forms.CharField(widget=forms.TextInput(attrs={'size':'60'}))
49   
50   lane7_species = forms.ChoiceField(choices=SPECIES_LIST)
51   lane7_description = forms.CharField(widget=forms.TextInput(attrs={'size':'60'}))
52   
53   lane8_species = forms.ChoiceField(choices=SPECIES_LIST)
54   lane8_description = forms.CharField(widget=forms.TextInput(attrs={'size':'60'}))
55   
56   notes = forms.CharField(widget=forms.Textarea(attrs={'cols':'70'}), required=False)
57   
58   #lane_specific_read_length = forms.IntegerField(min_value=1)
59   
60   #eland_genome_lanes = forms.MultipleChoiceField(choices=[('lane1','1'),
61   #                                              ('lane2','2'),
62   #                                              ('lane3','3'),
63   #                                              ('lane4','4'),
64   #                                              ('lane5','5'),
65   #                                              ('lane6','6'),
66   #                                              ('lane7','7'),
67   #                                              ('lane8','8') ])
68   
69   #eland_genome = forms.ChoiceField(choices=)
70   
71   #use_bases_lanes = forms.MultipleChoiceField(choices=[('lane1','1'),
72   #                                              ('lane2','2'),
73   #                                              ('lane3','3'),
74   #                                              ('lane4','4'),
75   #                                              ('lane5','5'),
76   #                                              ('lane6','6'),
77   #                                              ('lane7','7'),
78   #                                              ('lane8','8') ])
79   
80   #use_bases_mask = forms.CharField()
81   
82   #sequence_format = forms.ChoiceField(choices=[('scarf', 'scarf')])
83   
84   
85   
86   #subject = forms.CharField(max_length=100)
87   #message = forms.CharField()
88   #sender = forms.EmailField()
89   #cc_myself = forms.BooleanField()
90   
91   def as_custom(self):
92     """
93     Displays customized html output
94     """
95     html = []
96     
97     fcn = self['flow_cell_number']
98     
99     html.append(fcn.label_tag() + ': ' + str(fcn) + str(fcn.errors) + '<br />')
100     
101     run_date = self['run_date']
102     html.append(run_date.label_tag() + ': ' + str(run_date) + str(run_date.errors) + '<br />')
103     
104     arun = self['advanced_run']
105     html.append(arun.label_tag() + ': ' + str(arun) + str(arun.errors) + '<br />')
106     
107     rl = self['read_length']
108     html.append(rl.label_tag() + ': ' + str(rl) + str(rl.errors) + '<br /><br />')
109     
110     html.append('<table border="0">')
111     html.append(' <tr><td>%s</td><td>%s</td><td>%s</td></tr>' \
112                 % ('Lane', 'Species', 'Description'))
113     
114     l1s = self['lane1_species']
115     l1d = self['lane1_description']
116     html.append(' <tr><td>%s</td><td>%s %s</td><td>%s %s</td></tr>' \
117                 % ('1', str(l1s), str(l1s.errors), str(l1d), str(l1d.errors)))
118     
119     l2s = self['lane2_species']
120     l2d = self['lane2_description']
121     html.append(' <tr><td>%s</td><td>%s %s</td><td>%s %s</td></tr>' \
122                 % ('2', str(l2s), str(l2s.errors), str(l2d), str(l2d.errors)))
123     
124     l3s = self['lane3_species']
125     l3d = self['lane3_description']
126     html.append(' <tr><td>%s</td><td>%s %s</td><td>%s %s</td></tr>' \
127                 % ('3', str(l3s), str(l3s.errors), str(l3d), str(l3d.errors)))
128     
129     l4s = self['lane4_species']
130     l4d = self['lane4_description']
131     html.append(' <tr><td>%s</td><td>%s %s</td><td>%s %s</td></tr>' \
132                 % ('4', str(l4s), str(l4s.errors), str(l4d), str(l4d.errors)))
133     
134     l5s = self['lane5_species']
135     l5d = self['lane5_description']
136     html.append(' <tr><td>%s</td><td>%s %s</td><td>%s %s</td></tr>' \
137                 % ('5', str(l5s), str(l5s.errors), str(l5d), str(l5d.errors)))
138     
139     l6s = self['lane6_species']
140     l6d = self['lane6_description']
141     html.append(' <tr><td>%s</td><td>%s %s</td><td>%s %s</td></tr>' \
142                 % ('6', str(l6s), str(l6s.errors), str(l6d), str(l6d.errors)))
143     
144     l7s = self['lane7_species']
145     l7d = self['lane7_description']
146     html.append(' <tr><td>%s</td><td>%s %s</td><td>%s %s</td></tr>' \
147                 % ('7', str(l7s), str(l7s.errors), str(l7d), str(l7d.errors)))
148     
149     l8s = self['lane8_species']
150     l8d = self['lane8_description']
151     html.append(' <tr><td>%s</td><td>%s %s</td><td>%s %s</td></tr>' \
152                 % ('8', str(l8s), str(l8s.errors), str(l8d), str(l8d.errors)))
153     
154     html.append('</table><br />')
155     
156     notes = self['notes']
157     html.append('<p>Notes:</p>')
158     html.append(' %s<br />' % (str(notes)))
159     
160     return '\n'.join(html)
161     
162     
163