3 from django
import forms
4 from django
.utils
.translation
import ugettext
as _
6 from mygpo
.api
.constants
import DEVICE_TYPES
7 from mygpo
.log
import log
8 from mygpo
.users
.models
import Device
11 class UserAccountForm(forms
.Form
):
13 the form that is used in the account settings.
15 if one of the three password fields is set, a password change is assumed
16 and the current and new passwords are checked.
18 email
= forms
.EmailField(label
=_('E-Mail address'))
19 password_current
= forms
.CharField(
20 label
=_(u
'Current password'),
21 widget
=forms
.PasswordInput(render_value
=False),
24 password1
= forms
.CharField(
25 label
=_(u
'New password'),
26 widget
=forms
.PasswordInput(render_value
=False),
29 password2
= forms
.CharField(
30 label
=_(u
'Confirm password'),
31 widget
=forms
.PasswordInput(render_value
=False),
35 if not super(UserAccountForm
, self
).is_valid():
38 pw1
= self
.cleaned_data
['password1']
39 pw2
= self
.cleaned_data
['password2']
41 if self
.cleaned_data
['password_current'] or pw1
or pw2
:
43 if self
.cleaned_data
['password_current'] == '':
44 return False # must give current password
47 return False # cant set empty password
50 return False # 5must confirm password
55 class ProfileForm(forms
.Form
):
56 twitter
= forms
.CharField(
60 about
= forms
.CharField(
61 label
=_(u
'A few words about you'),
63 widget
=forms
.Textarea
,
64 help_text
='You can use Markdown')
67 class FlattrForm(forms
.Form
):
68 """ Per-user Flattr settings """
70 # Authentication token; empty or None when not signed in
71 token
= forms
.CharField(
75 # Auto-flattring enabled
76 enable
= forms
.BooleanField(
78 label
=_('Auto-Flattr played episodes'))
80 # Auto-flattr mygpo (or whatever the FLATTR_MYGPO_THING
81 # in settings_prod.py is) on every other flattr
82 flattr_mygpo
= forms
.BooleanField(required
=False, label
=_('Flattr us'))
84 # username under which own content (eg podcast lists) should be published
85 username
= forms
.CharField(
87 label
=_('Username for own content'))
90 class DeviceForm(forms
.Form
):
92 form for editing device information by a user.
94 name
= forms
.CharField(max_length
=100, label
=_('Name'))
95 type = forms
.ChoiceField(choices
=DEVICE_TYPES
, label
=_('Type'))
96 uid
= forms
.CharField(max_length
=50, label
=_('Device ID'))
99 class PrivacyForm(forms
.Form
):
101 Form for editing the privacy settings for a subscription. It is shown on a
102 podcast page if the current user is subscribed to the podcast.
105 public
= forms
.BooleanField(
107 label
=_('Share this subscription with other users (public)'))
110 class SyncForm(forms
.Form
):
112 Form that is used to select either a single devices or a device group.
115 targets
= forms
.CharField()
117 def set_targets(self
, sync_targets
, label
=''):
118 targets
= map(self
.sync_target_choice
, sync_targets
)
119 self
.fields
['targets'] = forms
.ChoiceField(
123 def sync_target_choice(self
, target
):
125 returns a list of tuples that can be used as choices for a ChoiceField.
126 the first item in each tuple is a letter identifying the type of the
127 sync-target - either d for a Device, or g for a SyncGroup. This letter
128 is followed by the id of the target.
129 The second item in each tuple is the string-representation of the #
133 if isinstance(target
, Device
):
134 return (target
.uid
, target
.name
)
136 elif isinstance(target
, list):
137 return (target
[0].uid
, ', '.join(d
.name
for d
in target
))
139 def get_target(self
):
141 returns the target (device or device group) that has been selected
144 if not self
.is_valid():
145 log('no target given in SyncForm')
146 raise ValueError(_('No device selected'))
148 target
= self
.cleaned_data
['targets']
152 class ResendActivationForm(forms
.Form
):
153 username
= forms
.CharField(
155 label
=_('Please enter your username'),
158 email
= forms
.CharField(
160 label
=_('or the email address used while registering'),
164 class RestorePasswordForm(forms
.Form
):
165 username
= forms
.CharField(
170 email
= forms
.CharField(
172 label
=_('E-Mail address'),