Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
123 lines (104 sloc) 4.49 KB
HTML form definitions.
from django import forms
from django.forms.models import modelformset_factory
from django.conf import settings
from occupywallst import models as db
from occupywallst.fields import ReCaptchaField
class ProfileForm(forms.Form):
email = forms.EmailField(required=False, help_text="""
We won't show it on the site or share it with anyone""")
info = forms.CharField(required=False, widget=forms.Textarea,
Say whatever you want about yourself here for others
to see.""")
position_lat = forms.FloatField(required=False, widget=forms.HiddenInput)
position_lng = forms.FloatField(required=False, widget=forms.HiddenInput)
formatted_address = forms.CharField(required=False,
country = forms.CharField(required=False, widget=forms.HiddenInput)
region = forms.CharField(required=False, widget=forms.HiddenInput)
city = forms.CharField(required=False, widget=forms.HiddenInput)
address = forms.CharField(required=False, widget=forms.HiddenInput)
zipcode = forms.CharField(required=False, widget=forms.HiddenInput)
def __init__(self, user, *args, **kwargs):
self.user = user
if user:
initial = {'email':,
'position_lat': user.userinfo.position_lat,
'position_lng': user.userinfo.position_lng,
'region': user.userinfo.region,
'address': user.userinfo.address,
'zipcode': user.userinfo.zipcode}
initial = {}
initial.update(kwargs.get('initial', {}))
kwargs['initial'] = initial
super(ProfileForm, self).__init__(*args, **kwargs)
def clean(self):
super(ProfileForm, self).clean()
return self.cleaned_data
def save(self):
user = self.user
ui = user.userinfo = self.cleaned_data.get('info')
position_lat = self.cleaned_data.get('position_lat')
position_lng = self.cleaned_data.get('position_lng')
if position_lat is not None and position_lng is not None:
ui.position_latlng = position_lat, position_lng
ui.position = None
ui.formatted_address = self.cleaned_data.get('formatted_address') = self.cleaned_data.get('country')
ui.region = self.cleaned_data.get('region') = self.cleaned_data.get('city')
ui.address = self.cleaned_data.get('address')
ui.zipcode = self.cleaned_data.get('zipcode') = self.cleaned_data.get('email')
return user
class SignupForm(ProfileForm):
username = forms.RegexField(
label="Username", max_length=30, regex=r'^[a-zA-Z0-9]{3,30}$',
help_text="Required. Letters and digits only and 3-30 characters.",
error_messages={'invalid': ("Please enter letters and digits only. "
"Minimum 3 characters and max 30.")})
password = forms.CharField(label="Password", widget=forms.PasswordInput,
min_length=6, max_length=128,
help_text="At least 6 characters")
if not settings.DEBUG:
captcha = ReCaptchaField()
def __init__(self, *args, **kwargs):
super(SignupForm, self).__init__(None, *args, **kwargs)
def clean_username(self):
username ='username')
if db.User.objects.filter(username__iexact=username).count():
raise forms.ValidationError("Username is taken")
return username
def save(self):
username = self.cleaned_data.get('username')
password = self.cleaned_data.get('password')
user = db.User()
user.username = username
userinfo = db.UserInfo()
userinfo.user = user
userinfo.attendance = 'maybe'
user.userinfo = userinfo
self.user = user
return super(SignupForm, self).save()
class SubscribeForm(forms.Form):
email = forms.EmailField()
class PledgeForm(forms.ModelForm):
class Meta:
model = db.Pledge
Jump to Line
Something went wrong with that request. Please try again.