Debian Codegraph @

adjutant_ui/content/signup/forms.py

raw
1 # Copyright (c) 2016 Catalyst IT Ltd.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 from django.conf import settings
16 from django import forms
17 from django import http
18 from django.utils.translation import gettext_lazy as _
19
20 from horizon import forms as hforms
21 from horizon.utils import functions as utils
22
23 from adjutant_ui.api import adjutant
24
25
26 class SignupForm(hforms.SelfHandlingForm):
27 username = forms.CharField(
28 max_length=255, label=_("User Name"),
29 widget=forms.TextInput(attrs={"autofocus": "autofocus"}))
30 email = forms.EmailField(label=_("Email"))
31 project_name = forms.CharField(label=_("Project Name"), max_length=64)
32 setup_network = forms.BooleanField(
33 label=_("Create Default Network"),
34 help_text=_("Create a basic network during account creation so that "
35 "you can deploy VMs immediately."),
36 required=False,
37 initial=True)
38
39 def __init__(self, *args, **kwargs):
40 super(SignupForm, self).__init__(*args, **kwargs)
41 if (hasattr(settings, 'USERNAME_IS_EMAIL') and
42 getattr(settings, 'USERNAME_IS_EMAIL')):
43 self.fields.pop('username')
44 self.fields['email'].widget = forms.TextInput(
45 attrs={"autofocus": "autofocus"})
46
47 def handle(self, request, data):
48 submit_response = adjutant.signup_submit(
49 request, data)
50 if submit_response.ok:
51 return True
52
53 # Send the user back to the login page.
54 msg = _("The signup service is currently unavailable. "
55 "Please try again later.")
56 response = http.HttpResponseRedirect(settings.LOGOUT_URL)
57 utils.add_logout_reason(self.request, response, msg)
58 return response