3 from django
import forms
4 from django
.utils
.translation
import gettext
as _
6 from mygpo
.users
.models
import Client
10 logger
= logging
.getLogger(__name__
)
13 class UserAccountForm(forms
.Form
):
15 the form that is used in the account settings.
17 if one of the three password fields is set, a password change is assumed
18 and the current and new passwords are checked.
21 email
= forms
.EmailField(
22 label
=_("E-Mail address"),
23 widget
=forms
.TextInput(attrs
={"class": "input input-sm form-control"}),
27 password_current
= forms
.CharField(
28 label
=_("Current password"),
29 widget
=forms
.PasswordInput(
30 render_value
=False, attrs
={"class": "input input-sm form-control"}
35 password1
= forms
.CharField(
36 label
=_("New password"),
37 widget
=forms
.PasswordInput(
38 render_value
=False, attrs
={"class": "input input-sm form-control"}
43 password2
= forms
.CharField(
44 label
=_("Confirm password"),
45 widget
=forms
.PasswordInput(
46 render_value
=False, attrs
={"class": "input input-sm form-control"}
52 if not super(UserAccountForm
, self
).is_valid():
55 pw1
= self
.cleaned_data
["password1"]
56 pw2
= self
.cleaned_data
["password2"]
58 if self
.cleaned_data
["password_current"] or pw1
or pw2
:
60 if self
.cleaned_data
["password_current"] == "":
61 return False # must give current password
64 return False # cant set empty password
67 return False # 5must confirm password
72 class ProfileForm(forms
.Form
):
73 twitter
= forms
.CharField(
75 widget
=forms
.TextInput(attrs
={"class": "input input-sm form-control"}),
79 about
= forms
.CharField(
80 label
=_("A few words about you"),
82 widget
=forms
.Textarea(attrs
={"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.
92 name
= forms
.CharField(
95 widget
=forms
.TextInput(
96 attrs
={"class": "input input-sm form-control", "placeholder": "Device Name"}
99 type = forms
.ChoiceField(
100 choices
=Client
.TYPES
,
102 widget
=forms
.Select(attrs
={"class": "input input-sm form-control"}),
104 uid
= forms
.CharField(
106 label
=_("Device ID"),
107 widget
=forms
.TextInput(
109 "class": "input input-sm form-control",
110 "placeholder": _("ID on device"),
116 class PrivacyForm(forms
.Form
):
118 Form for editing the privacy settings for a subscription. It is shown on a
119 podcast page if the current user is subscribed to the podcast.
122 public
= forms
.BooleanField(
123 required
=False, label
=_("Share this subscription with other users (public)")
127 class SyncForm(forms
.Form
):
129 Form that is used to select either a single devices or a device group.
132 targets
= forms
.CharField(
133 widget
=forms
.Select(attrs
={"class": "input input-sm form-control"})
136 def set_targets(self
, sync_targets
, label
=""):
137 targets
= list(map(self
.sync_target_choice
, sync_targets
))
138 self
.fields
["targets"] = forms
.ChoiceField(choices
=targets
, label
=label
)
140 def sync_target_choice(self
, target
):
142 returns a list of tuples that can be used as choices for a ChoiceField.
143 the first item in each tuple is a letter identifying the type of the
144 sync-target - either d for a Device, or g for a SyncGroup. This letter
145 is followed by the id of the target.
146 The second item in each tuple is the string-representation of the #
150 if isinstance(target
, Client
):
151 return (target
.uid
, target
.name
)
153 elif isinstance(target
, list):
154 return (target
[0].uid
, ", ".join(d
.name
for d
in target
))
156 def get_target(self
):
158 returns the target (device or device group) that has been selected
161 if not self
.is_valid():
162 logger
.warning("no target given in SyncForm")
163 raise ValueError(_("No device selected"))
165 target
= self
.cleaned_data
["targets"]
169 class ResendActivationForm(forms
.Form
):
170 username
= forms
.CharField(
171 max_length
=100, label
=_("Please enter your username"), required
=False
174 email
= forms
.CharField(
176 label
=_("or the email address used while registering"),
181 class RestorePasswordForm(forms
.Form
):
182 username
= forms
.CharField(max_length
=100, label
=_("Username"), required
=False)
184 email
= forms
.CharField(max_length
=100, label
=_("E-Mail address"), required
=False)