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