discard deprecated code
[myslice.git] / portal / forms.py
1 # -*- coding: utf-8 -*-
2 #
3 # portal/forms.py: forms for the portal application
4 # This file is part of the Manifold project.
5 #
6 # Authors:
7 #   Jordan AugĂ© <jordan.auge@lip6.fr>
8 #   Mohammed-Yasin Rahman <mohammed-yasin.rahman@lip6.fr>
9 # Copyright 2013, UPMC Sorbonne UniversitĂ©s / LIP6
10 #
11 # This program is free software; you can redistribute it and/or modify it under
12 # the terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 3, or (at your option) any later version.
14
15 # This program is distributed in the hope that it will be useful, but WITHOUT
16 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
18 # details.
19
20 # You should have received a copy of the GNU General Public License along with
21 # this program; see the file COPYING.  If not, write to the Free Software
22 # Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24 from django import forms
25 from portal.models import PendingUser, PendingSlice
26 #from crispy_forms.helper import FormHelper
27 #from crispy_forms.layout import Submit
28 from django.utils.translation import ugettext_lazy as _
29
30 class ContactForm(forms.Form):
31     first_name = forms.CharField()
32     last_name = forms.CharField()
33     affiliation = forms.CharField()
34     subject = forms.CharField(max_length=100)
35     message = forms.CharField(widget=forms.Textarea)
36     email = forms.EmailField()
37     cc_myself = forms.BooleanField(required=False)
38
39 class SliceRequestForm(forms.Form):
40     slice_name = forms.CharField()
41     authority_hrn = forms.ChoiceField(choices=[(1, 'un')])
42     number_of_nodes  = forms.DecimalField()
43     type_of_nodes = forms.CharField()
44     purpose = forms.CharField(widget=forms.Textarea)
45     email = forms.EmailField()
46     cc_myself = forms.BooleanField(required=False)
47
48     def __init__(self, *args, **kwargs):
49         initial =  kwargs.get('initial', {})
50         authority_hrn = initial.get('authority_hrn', None)
51
52         # set just the initial value
53         # in the real form needs something like this {'authority_hrn':'a'}
54         # but in this case you want {'authority_hrn':('a', 'letter_a')}
55         if authority_hrn:
56             kwargs['initial']['authority_hrn'] = authority_hrn[0]
57
58         # create the form
59         super(SliceRequestForm, self).__init__(*args, **kwargs)
60
61         # self.fields only exist after, so a double validation is needed
62         if authority_hrn:# and authority_hrn[0] not in (c[0] for c in authority_hrn):
63             # XXX This does not work, the choicefield is not updated...
64             #self.fields['authority_hrn'].choices.extend(authority_hrn)
65             self.fields['authority_hrn'] = forms.ChoiceField( choices=authority_hrn)
66