2011-10-03 16:36:04 +00:00
|
|
|
from django import forms
|
|
|
|
from django.db import models
|
|
|
|
from django.contrib.auth.models import User
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2011-11-18 14:22:21 +00:00
|
|
|
|
2011-10-11 17:03:40 +00:00
|
|
|
from decimal import Decimal as D
|
2011-11-20 19:02:09 +00:00
|
|
|
from selectable.forms import AutoCompleteSelectMultipleWidget,AutoCompleteSelectMultipleField
|
2011-11-20 19:22:51 +00:00
|
|
|
from selectable.forms import AutoCompleteSelectWidget,AutoCompleteSelectField
|
2011-11-18 14:22:21 +00:00
|
|
|
|
2011-11-20 02:12:18 +00:00
|
|
|
from regluit.core.models import UserProfile, RightsHolder, Claim, Campaign
|
2011-11-18 14:22:21 +00:00
|
|
|
from regluit.core.lookups import OwnerLookup
|
2011-11-15 23:20:29 +00:00
|
|
|
|
|
|
|
class ClaimForm(forms.ModelForm):
|
2011-11-16 05:22:22 +00:00
|
|
|
i_agree=forms.BooleanField()
|
2011-11-15 23:20:29 +00:00
|
|
|
class Meta:
|
|
|
|
model = Claim
|
2011-11-16 19:45:37 +00:00
|
|
|
exclude = 'status'
|
2011-11-15 23:20:29 +00:00
|
|
|
widgets = { 'user': forms.HiddenInput, 'work': forms.HiddenInput }
|
2011-11-15 04:28:55 +00:00
|
|
|
|
|
|
|
class RightsHolderForm(forms.ModelForm):
|
2011-11-18 14:22:21 +00:00
|
|
|
owner = AutoCompleteSelectField(
|
|
|
|
OwnerLookup,
|
|
|
|
label='Owner',
|
|
|
|
widget=AutoCompleteSelectWidget(OwnerLookup),
|
|
|
|
required=True,
|
|
|
|
)
|
|
|
|
|
2011-11-15 04:28:55 +00:00
|
|
|
class Meta:
|
|
|
|
model = RightsHolder
|
|
|
|
|
2011-11-17 19:35:29 +00:00
|
|
|
def clean_rights_holder_name(self):
|
|
|
|
rights_holder_name = self.data["rights_holder_name"]
|
|
|
|
try:
|
|
|
|
RightsHolder.objects.get(rights_holder_name__iexact=rights_holder_name)
|
2011-11-18 14:22:21 +00:00
|
|
|
except RightsHolder.DoesNotExist:
|
2011-11-17 19:35:29 +00:00
|
|
|
return rights_holder_name
|
|
|
|
raise forms.ValidationError(_("Another rights holder with that name already exists."))
|
2011-11-18 14:22:21 +00:00
|
|
|
|
2011-10-03 16:36:04 +00:00
|
|
|
class ProfileForm(forms.ModelForm):
|
2011-11-14 18:23:14 +00:00
|
|
|
clear_facebook=forms.BooleanField(required=False)
|
|
|
|
clear_twitter=forms.BooleanField(required=False)
|
2011-10-03 16:36:04 +00:00
|
|
|
class Meta:
|
|
|
|
model = UserProfile
|
2011-11-14 18:23:14 +00:00
|
|
|
fields = 'tagline', 'librarything_id', 'home_url', 'clear_facebook', 'clear_twitter'
|
2011-10-03 16:36:04 +00:00
|
|
|
widgets = {
|
2011-10-19 07:13:29 +00:00
|
|
|
'tagline': forms.Textarea(attrs={'cols': 35, 'rows': 4}),
|
2011-10-03 16:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class UserData(forms.Form):
|
|
|
|
username = forms.RegexField(
|
|
|
|
label=_("New Username"),
|
|
|
|
max_length=30,
|
|
|
|
regex=r'^[\w.@+-]+$',
|
|
|
|
help_text = _("30 characters or less."),
|
|
|
|
error_messages = {
|
|
|
|
'invalid': _("This value may contain only letters, numbers and @/./+/-/_ characters.")
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def clean_username(self):
|
|
|
|
username = self.data["username"]
|
|
|
|
oldusername = self.data["oldusername"]
|
|
|
|
if username != oldusername:
|
|
|
|
try:
|
2011-11-17 19:35:29 +00:00
|
|
|
User.objects.get(username__iexact=username)
|
2011-10-03 16:36:04 +00:00
|
|
|
except User.DoesNotExist:
|
|
|
|
return username
|
|
|
|
raise forms.ValidationError(_("Another user with that username already exists."))
|
2011-10-09 19:17:43 +00:00
|
|
|
raise forms.ValidationError(_("Your username is already "+oldusername))
|
2011-10-11 17:03:40 +00:00
|
|
|
|
2011-11-20 02:12:18 +00:00
|
|
|
class OpenCampaignForm(forms.ModelForm):
|
2011-11-20 19:02:09 +00:00
|
|
|
manager = AutoCompleteSelectMultipleField(
|
2011-11-20 02:12:18 +00:00
|
|
|
OwnerLookup,
|
|
|
|
label='Campaign Manager',
|
2011-11-20 19:02:09 +00:00
|
|
|
widget=AutoCompleteSelectMultipleWidget(OwnerLookup),
|
2011-11-20 02:12:18 +00:00
|
|
|
required=False,
|
|
|
|
)
|
|
|
|
userid = forms.IntegerField( required = True, widget = forms.HiddenInput )
|
|
|
|
class Meta:
|
|
|
|
model = Campaign
|
|
|
|
fields = 'name', 'work', 'target', 'deadline', 'manager'
|
|
|
|
widgets = { 'work': forms.HiddenInput }
|
|
|
|
|
|
|
|
|
2011-10-11 17:03:40 +00:00
|
|
|
class CampaignPledgeForm(forms.Form):
|
2011-11-20 02:12:18 +00:00
|
|
|
preapproval_amount = forms.DecimalField(
|
|
|
|
initial=None,
|
|
|
|
required=True,
|
|
|
|
min_value=D('0.00'),
|
|
|
|
max_value=D('10000.00'),
|
|
|
|
decimal_places=2,
|
|
|
|
label="Pledge Amount",
|
|
|
|
)
|
2011-11-01 21:08:09 +00:00
|
|
|
anonymous = forms.BooleanField(required=False, label="Don't display my username in the supporters list")
|
2011-11-01 00:26:05 +00:00
|
|
|
|
|
|
|
class GoodreadsShelfLoadingForm(forms.Form):
|
2011-11-15 20:51:38 +00:00
|
|
|
goodreads_shelf_name_number = forms.CharField(widget=forms.Select(choices=(
|
2011-11-01 00:26:05 +00:00
|
|
|
('all','all'),
|
|
|
|
)))
|
2011-11-16 18:20:10 +00:00
|
|
|
|
|
|
|
class LibraryThingForm(forms.Form):
|
2011-11-16 19:58:39 +00:00
|
|
|
lt_username = forms.CharField(max_length=30, required=True)
|