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 FlattrForm(forms
.Form
):
88 """ Per-user Flattr settings """
90 # Authentication token; empty or None when not signed in
91 token
= forms
.CharField(
95 # Auto-flattring enabled
96 enable
= forms
.BooleanField(
98 label
=_('Auto-Flattr played episodes'),
99 widget
=forms
.CheckboxInput(attrs
={
100 'class': 'input input-sm form-control',
104 # Auto-flattr mygpo (or whatever the FLATTR_MYGPO_THING
105 # in settings_prod.py is) on every other flattr
106 flattr_mygpo
= forms
.BooleanField(
108 label
=_('Flattr us'),
109 widget
=forms
.CheckboxInput(attrs
={
110 'class': 'input input-sm form-control',
114 # username under which own content (eg podcast lists) should be published
115 username
= forms
.CharField(
117 label
=_('Username for own content'),
118 widget
=forms
.TextInput(attrs
={
119 'class': 'input input-sm form-control',
120 'placeholder': 'Device Name',
125 class DeviceForm(forms
.Form
):
127 form for editing device information by a user.
129 name
= forms
.CharField(max_length
=100, label
=_('Name'),
130 widget
=forms
.TextInput(attrs
={
131 'class': 'input input-sm form-control',
132 'placeholder': 'Device Name',
134 type = forms
.ChoiceField(choices
=Client
.TYPES
, label
=_('Type'),
135 widget
=forms
.Select(attrs
={
136 'class': 'input input-sm form-control',
138 uid
= forms
.CharField(max_length
=50, label
=_('Device ID'),
139 widget
=forms
.TextInput(attrs
={
140 'class': 'input input-sm form-control',
141 'placeholder': _('ID on device'),
145 class PrivacyForm(forms
.Form
):
147 Form for editing the privacy settings for a subscription. It is shown on a
148 podcast page if the current user is subscribed to the podcast.
151 public
= forms
.BooleanField(
153 label
=_('Share this subscription with other users (public)'))
156 class SyncForm(forms
.Form
):
158 Form that is used to select either a single devices or a device group.
161 targets
= forms
.CharField(
162 widget
= forms
.Select(attrs
={
163 'class': 'input input-sm form-control',
167 def set_targets(self
, sync_targets
, label
=''):
168 targets
= list(map(self
.sync_target_choice
, sync_targets
))
169 self
.fields
['targets'] = forms
.ChoiceField(
173 def sync_target_choice(self
, target
):
175 returns a list of tuples that can be used as choices for a ChoiceField.
176 the first item in each tuple is a letter identifying the type of the
177 sync-target - either d for a Device, or g for a SyncGroup. This letter
178 is followed by the id of the target.
179 The second item in each tuple is the string-representation of the #
183 if isinstance(target
, Client
):
184 return (target
.uid
, target
.name
)
186 elif isinstance(target
, list):
187 return (target
[0].uid
, ', '.join(d
.name
for d
in target
))
189 def get_target(self
):
191 returns the target (device or device group) that has been selected
194 if not self
.is_valid():
195 logger
.warn('no target given in SyncForm')
196 raise ValueError(_('No device selected'))
198 target
= self
.cleaned_data
['targets']
202 class ResendActivationForm(forms
.Form
):
203 username
= forms
.CharField(
205 label
=_('Please enter your username'),
208 email
= forms
.CharField(
210 label
=_('or the email address used while registering'),
214 class RestorePasswordForm(forms
.Form
):
215 username
= forms
.CharField(
220 email
= forms
.CharField(
222 label
=_('E-Mail address'),