1 # -*- coding: utf-8 -*-
3 # portal/forms.py: forms for the portal application
4 # This file is part of the Manifold project.
7 # Jordan Augé <jordan.auge@lip6.fr>
8 # Mohammed-Yasin Rahman <mohammed-yasin.rahman@lip6.fr>
9 # Copyright 2013, UPMC Sorbonne Universités / LIP6
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.
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
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.
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 _
31 # bootstrap3 requires the <input> fields to be tagged class='form-control'
32 # my first idea was to add this in the view template of course, BUT
33 # I can't find a way to access the 'type=' value for a given field
34 # I've looked rather deeply out there but to no avail so far
35 # so as we have a demo coming up soon, and until we can come with a less intrusive way to handle this...
38 #class ContactForm(forms.Form):
39 # first_name = forms.CharField()
40 # last_name = forms.CharField()
41 # affiliation = forms.CharField()
42 # subject = forms.CharField(max_length=100)
43 # message = forms.CharField(widget=forms.Textarea)
44 # email = forms.EmailField()
45 # cc_myself = forms.BooleanField(required=False)
47 class ContactForm(forms.Form):
48 first_name = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control'}))
49 last_name = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control'}))
50 affiliation = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control'}))
51 email = forms.EmailField(widget=forms.TextInput(attrs={'class':'form-control'}))
52 subject = forms.CharField(max_length=100,widget=forms.TextInput(attrs={'class':'form-control'}))
53 message = forms.CharField(widget=forms.Textarea(attrs={'class':'form-control'}))
54 cc_myself = forms.BooleanField(required=False,widget=forms.CheckboxInput(attrs={'class':'form-control'}))
56 class PassResetForm(forms.Form):
57 email = forms.EmailField(widget=forms.TextInput(attrs={'class':'form-control'}))
59 class SliceRequestForm(forms.Form):
60 # slice_name = forms.CharField()
61 # authority_hrn = forms.ChoiceField(choices=[(1, 'un')])
62 # number_of_nodes = forms.DecimalField()
63 # type_of_nodes = forms.CharField()
64 # purpose = forms.CharField(widget=forms.Textarea)
65 # email = forms.EmailField()
66 # cc_myself = forms.BooleanField(required=False)
68 slice_name = forms.CharField(
69 widget=forms.TextInput(attrs={'class':'form-control'}),
70 help_text="The name for the slice you wish to create")
71 authority_hrn = forms.ChoiceField(
72 widget = forms.Select(attrs={'class':'form-control'}),
74 help_text = "An authority responsible for vetting your slice")
75 number_of_nodes = forms.DecimalField(
76 widget = forms.TextInput(attrs={'class':'form-control'}),
77 help_text = "The number of nodes you expect to request (informative)")
78 type_of_nodes = forms.CharField(
79 widget = forms.TextInput(attrs={'class':'form-control'}),
80 help_text = "The type of nodes you expect to request (informative)")
81 purpose = forms.CharField(
82 widget = forms.Textarea(attrs={'class':'form-control'}),
83 help_text = "The purpose of your experiment (informative)")
84 email = forms.EmailField(
85 widget = forms.TextInput(attrs={'class':'form-control'}),
86 help_text = "Your email address")
87 cc_myself = forms.BooleanField(
88 widget = forms.CheckboxInput(attrs={'class':'form-control'}),
90 help_text = "If you'd like to be cc'ed on the request email")
92 def __init__(self, *args, **kwargs):
93 initial = kwargs.get('initial', {})
94 authority_hrn = initial.get('authority_hrn', None)
96 # set just the initial value
97 # in the real form needs something like this {'authority_hrn':'a'}
98 # but in this case you want {'authority_hrn':('a', 'letter_a')}
100 kwargs['initial']['authority_hrn'] = authority_hrn[0]
103 super(SliceRequestForm, self).__init__(*args, **kwargs)
105 # self.fields only exist after, so a double validation is needed
106 if authority_hrn:# and authority_hrn[0] not in (c[0] for c in authority_hrn):
107 # XXX This does not work, the choicefield is not updated...
108 #self.fields['authority_hrn'].choices.extend(authority_hrn)
109 self.fields['authority_hrn'] = forms.ChoiceField(
110 widget = forms.Select(attrs={'class':'form-control'}),
111 choices = authority_hrn,
112 help_text = "An authority responsible for vetting your slice")