3 from django
import forms
4 from django
.utils
.translation
import ugettext
as _
6 from mygpo
.users
.models
import Client
9 logger
= logging
.getLogger(__name__
)
12 class UserAccountForm(forms
.Form
):
14 the form that is used in the account settings.
16 if one of the three password fields is set, a password change is assumed
17 and the current and new passwords are checked.
19 email
= forms
.EmailField(
20 label
=_('E-Mail address'),
21 widget
=forms
.TextInput(attrs
={
22 'class': 'input input-sm form-control',
26 password_current
= forms
.CharField(
27 label
=_('Current password'),
28 widget
=forms
.PasswordInput(render_value
=False, attrs
={
29 'class': 'input input-sm form-control',
33 password1
= forms
.CharField(
34 label
=_('New password'),
35 widget
=forms
.PasswordInput(render_value
=False, attrs
={
36 'class': 'input input-sm form-control',
40 password2
= forms
.CharField(
41 label
=_('Confirm password'),
42 widget
=forms
.PasswordInput(render_value
=False, attrs
={
43 'class': 'input input-sm form-control',
48 if not super(UserAccountForm
, self
).is_valid():
51 pw1
= self
.cleaned_data
['password1']
52 pw2
= self
.cleaned_data
['password2']
54 if self
.cleaned_data
['password_current'] or pw1
or pw2
:
56 if self
.cleaned_data
['password_current'] == '':
57 return False # must give current password
60 return False # cant set empty password
63 return False # 5must confirm password
68 class ProfileForm(forms
.Form
):
69 twitter
= forms
.CharField(
71 widget
=forms
.TextInput(attrs
={
72 'class': 'input input-sm form-control',
77 about
= forms
.CharField(
78 label
=_('A few words about you'),
80 widget
=forms
.Textarea(attrs
={
81 'class': 'input input-sm form-control',
83 help_text
='You can use Markdown',
87 class DeviceForm(forms
.Form
):
89 form for editing device information by a user.
91 name
= forms
.CharField(max_length
=100, label
=_('Name'),
92 widget
=forms
.TextInput(attrs
={
93 'class': 'input input-sm form-control',
94 'placeholder': 'Device Name',
96 type = forms
.ChoiceField(choices
=Client
.TYPES
, label
=_('Type'),
97 widget
=forms
.Select(attrs
={
98 'class': 'input input-sm form-control',
100 uid
= forms
.CharField(max_length
=50, label
=_('Device ID'),
101 widget
=forms
.TextInput(attrs
={
102 'class': 'input input-sm form-control',
103 'placeholder': _('ID on device'),
107 class PrivacyForm(forms
.Form
):
109 Form for editing the privacy settings for a subscription. It is shown on a
110 podcast page if the current user is subscribed to the podcast.
113 public
= forms
.BooleanField(
115 label
=_('Share this subscription with other users (public)'))
118 class SyncForm(forms
.Form
):
120 Form that is used to select either a single devices or a device group.
123 targets
= forms
.CharField(
124 widget
= forms
.Select(attrs
={
125 'class': 'input input-sm form-control',
129 def set_targets(self
, sync_targets
, label
=''):
130 targets
= list(map(self
.sync_target_choice
, sync_targets
))
131 self
.fields
['targets'] = forms
.ChoiceField(
135 def sync_target_choice(self
, target
):
137 returns a list of tuples that can be used as choices for a ChoiceField.
138 the first item in each tuple is a letter identifying the type of the
139 sync-target - either d for a Device, or g for a SyncGroup. This letter
140 is followed by the id of the target.
141 The second item in each tuple is the string-representation of the #
145 if isinstance(target
, Client
):
146 return (target
.uid
, target
.name
)
148 elif isinstance(target
, list):
149 return (target
[0].uid
, ', '.join(d
.name
for d
in target
))
151 def get_target(self
):
153 returns the target (device or device group) that has been selected
156 if not self
.is_valid():
157 logger
.warn('no target given in SyncForm')
158 raise ValueError(_('No device selected'))
160 target
= self
.cleaned_data
['targets']
164 class ResendActivationForm(forms
.Form
):
165 username
= forms
.CharField(
167 label
=_('Please enter your username'),
170 email
= forms
.CharField(
172 label
=_('or the email address used while registering'),
176 class RestorePasswordForm(forms
.Form
):
177 username
= forms
.CharField(
182 email
= forms
.CharField(
184 label
=_('E-Mail address'),