Slice Request page added /portal/slice_request
[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 UserRegisterForm(forms.Form): # Not ModelForm
31     """
32     Form for registering a new user account.
33     
34     Validates that the requested username is not already in use, and
35     requires the password to be entered twice to catch typos.
36     
37     Subclasses should feel free to add any additional validation they
38     need, but should avoid defining a ``save()`` method -- the actual
39     saving of collected user data is delegated to the active
40     registration backend.
41
42     """
43     required_css_class = 'required'
44     
45     first_name = forms.RegexField(regex=r'^[\w.@+-]+$',
46                                  max_length=30,
47                                  label=_("First name"),
48                                  error_messages={'invalid': _("This value may contain only letters, numbers and @/./+/-/_ characters.")})
49     last_name = forms.RegexField(regex=r'^[\w.@+-]+$',
50                                  max_length=30,
51                                  label=_("Last name"),
52                                  error_messages={'invalid': _("This value may contain only letters, numbers and @/./+/-/_ characters.")})
53     affiliation = forms.RegexField(regex=r'^[\w.@+-]+$',
54                              max_length=30,
55                              label=_("Affiliation"),
56                              error_messages={'invalid': _("This value may contain only letters, numbers and @/./+/-/_ characters.")})
57
58     email = forms.EmailField(label=_("E-mail"))
59     password1 = forms.CharField(widget=forms.PasswordInput,
60                                 label=_("Password"))
61     password2 = forms.CharField(widget=forms.PasswordInput,
62                                 label=_("Password (again)"))
63     keypair    = forms.CharField( widget=forms.FileInput )
64
65     tos = forms.BooleanField(widget=forms.CheckboxInput,
66                              label=_(u'I have read and agree to the Terms of Service'),
67                              error_messages={'required': _("You must agree to the terms to register")})
68
69 #    def clean_username(self):
70 #        """
71 #        Validate that the username is alphanumeric and is not already
72 #        in use.
73 #        
74 #        """
75 #        existing = User.objects.filter(username__iexact=self.cleaned_data['username'])
76 #        if existing.exists():
77 #            raise forms.ValidationError(_("A user with that username already exists."))
78 #        else:
79 #            return self.cleaned_data['username']
80
81     def clean_email(self):
82         """
83         Validate that the supplied email address is unique for the
84         site.
85         
86         """
87         if PendingUser.objects.filter(email__iexact=self.cleaned_data['email']):
88             raise forms.ValidationError(_("This email address is already in use. Please supply a different email address."))
89         return self.cleaned_data['email']
90
91     def clean(self):
92         """
93         Verifiy that the values entered into the two password fields
94         match. Note that an error here will end up in
95         ``non_field_errors()`` because it doesn't apply to a single
96         field.
97         
98         """
99         if 'password1' in self.cleaned_data and 'password2' in self.cleaned_data:
100             if self.cleaned_data['password1'] != self.cleaned_data['password2']:
101                 raise forms.ValidationError(_("The two password fields didn't match."))
102         return self.cleaned_data
103
104 # DEPRECATED #    class Meta:
105 # DEPRECATED #        model = PendingUser
106
107 class SliceRequestForm(forms.ModelForm):
108     slice_name = forms.CharField( widget=forms.TextInput )
109     class Meta:
110         model = PendingSlice
111
112 # DEPRECATED #class RegisterUserStep2Form(forms.ModelForm):
113 # DEPRECATED #    class Meta:
114 # DEPRECATED #        model = PendingUser
115
116 class ContactForm(forms.Form):
117     first_name = forms.CharField()
118     last_name = forms.CharField()
119     affiliation = forms.CharField()
120     subject = forms.CharField(max_length=100)
121     message = forms.CharField(widget=forms.Textarea)
122     email = forms.EmailField()
123     cc_myself = forms.BooleanField(required=False)
124
125 class SliceRequestForm(forms.Form):
126     slice_name = forms.CharField()
127     number_of_nodes  = forms.DecimalField()
128     type_of_nodes = forms.CharField()
129     purpose = forms.CharField(widget=forms.Textarea)
130     email = forms.EmailField()
131     cc_myself = forms.BooleanField(required=False)
132