class EditPostForm(forms.Form): title = forms.CharField() listed = forms.BooleanField( required=False, widget=forms.CheckboxInput(attrs={'class': 'checkbox'}), ) content = forms.CharField(widget=forms.Textarea, )
class VELocalForm(forms.Form): ve_dni_format = VEDNIField() ve_rif_format = VERIFField() ve_zip_code = VEZipCodeField() ve_phone_format = VEPhoneField() ve_regions = forms.CharField(label=_(u"Regions"), widget=VERegionsSelect()) ve_states = forms.CharField(label=_(u"States"), widget=VEStateSelect())
class LoginForm(forms.Form): """ Creates LoginForm instance for general login """ # form inputs username = forms.CharField(max_length=30) password = forms.CharField(widget=PasswordInput)
class RegistrationForm(forms.Form): username = forms.CharField(label='Username', max_length=30) email = forms.EmailField(label='Email') password1 = forms.CharField(label='Password', widget=forms.PasswordInput()) password2 = forms.CharField(label='Password (Again)', widget=forms.PasswordInput()) def clean_password2(self): if 'password1' in self.clean_data: password1 = self.clean_data['password1'] password2 = self.clean_data['password2'] if password1 == password2: return password2 raise forms.ValidationError('Passwords do not match.') def clean_username(self): username = self.clean_data['username'] if not re.search(r'^\w+$', username): raise forms.ValidationError( 'Username can only containalphanumeric characters and the underscore.' ) try: User.objects.get(username=username) except ObjectDoesNotExist: return username raise forms.ValidationError('Username is already taken.')
class SignUpForm(forms.Form): which_form = forms.CharField(widget=forms.HiddenInput, initial="signup") signup_email = forms.EmailField(label="Email") signup_first_name = forms.CharField(label="First Name") signup_last_name = forms.CharField(label="Last Name") signup_password = forms.CharField(widget=forms.PasswordInput,label="Password") signup_password_confirm = forms.CharField(widget=forms.PasswordInput,label="Verify Password")
class PostForm(djangoforms.ModelForm): # log = logging.getLogger() title = forms.CharField(widget=forms.TextInput(attrs={'id':'name'})) body = forms.CharField(widget=forms.Textarea(attrs={ 'id':'message', 'rows': 10, 'cols': 20})) body_markup = forms.ChoiceField( choices=[(k, v[0]) for k, v in markup.MARKUP_MAP.iteritems()]) tags = forms.CharField(widget=forms.Textarea(attrs={'rows': 5, 'cols': 20})) draft = forms.BooleanField(required=False) image_url = forms.CharField(required=False, widget=forms.TextInput(attrs={'id':'image_url'})) if common.PROD: url = '%s/api/authors' % (config.main_site_origin) else: url = '%s/api/authors' % (config.main_site_test_origin) sorted_profiles = [] try: response = urlfetch.fetch(url) if response.status_code == 200: sorted_profiles = simplejson.loads(response.content).keys() except urlfetch.DownloadError: pass author_id = forms.ChoiceField( choices=[(id,id) for id in sorted_profiles]) IMAGE_STYLES = (('top','top'), ('left','left'), ('right','right')) image_style = forms.ChoiceField(required=False, choices=IMAGE_STYLES) class Meta: model = models.BlogPost fields = [ 'title', 'body', 'tags', 'author_id', 'image_url', 'image_style' ]
class SearchForm(forms.Form): lval_1 = forms.CharField(max_length=75) file_1 = forms.CharField(max_length=100) line_1 = forms.IntegerField() lval_2 = forms.CharField(max_length=75) file_2 = forms.CharField(max_length=100) line_2 = forms.IntegerField()
class UpgradeForm(forms.Form, SavesPayment): #TODO: Fill in first name if available first_name = forms.CharField( label="First name", min_length=2, max_length=30, required=False, ) last_name = forms.CharField( label="Last name", min_length=2, max_length=30, required=False, ) card_number = forms.CharField( label="Card number", required=False, ) card_expiration = forms.DateField( label="Expiration", required=False, ) def __init__(self, requires_payment, *args, **kwargs): self.requires_payment = requires_payment forms.Form.__init__(self, *args, **kwargs)
class AccountForm(forms.Form, ManualFormHelpers): name = forms.CharField( label="Company / Organization", min_length=2, max_length=30, ) timezone = forms.ChoiceField(label="Time zone", choices=settings.ACCOUNT_TIME_ZONES) subdomain = forms.CharField( min_length=2, max_length=30, ) domain = forms.ChoiceField(choices=settings.ACCOUNT_DOMAINS) def clean_subdomain(self): if not self.cleaned_data['subdomain'].isalnum(): raise forms.ValidationError( "Your subdomain can only include letters and numbers.") return self.cleaned_data['subdomain'] def update_account(self, account): for n in ['name', 'subdomain', 'domain', 'timezone']: setattr(account, n, self.cleaned_data[n]) if not account.validate(): account.save() return account else: logging.debug(str(account.subscription_level_id)) logging.debug('UPDATE_ACCOUNT validation errors: %s' % str(account.validate())) raise ValueError
class CertForm(forms.Form): text = forms.CharField(widget = forms.Textarea(attrs = dict(rows=14, cols=72)), required = False) file = forms.CharField(widget = forms.FileInput(), required = False) def clean_text(self): text = self.clean_data.get('text') file = self.data.get('file') if not text and not file: raise forms.ValidationError('One of "text" or "file" must be filled out') if text and not is_valid_cert(text): raise forms.ValidationError('A valid certificate is required') return text def clean_file(self): text = self.data.get('text') file = self.data.get('file') if text and file: raise forms.ValidationError('Only one of "text" or "file" must be filled out') if file and not is_valid_cert(file['content']): raise forms.ValidationError('A valid certificate is required') return file
class StyleForm(forms.Form): Logo = forms.CharField(help_text="Image SRC for home page logo") Alt = forms.CharField(max_length=80, \ help_text = "Image ALT for home page logo") StyleSheet = forms.CharField(initial='', help_text="URL for home page CSS", required=False)
class RedirectionForm(forms.Form): experiment_name = forms.CharField(label="Experiment name") targets = forms.CharField(label="Target URLs", widget=forms.Textarea(attrs={ 'rows': '10', 'cols': '70' })) stratify = forms.BooleanField(label="Stratify", required=False)
class CommentForm(forms.Form): id = forms.CharField(widget=forms.HiddenInput) name = forms.CharField(max_length=64) url = forms.URLField(max_length=128, required=False) comment = forms.CharField(widget=forms.Textarea(attrs={ 'rows': 8, 'cols': 60 })) remember = forms.BooleanField(initial=True, required=False)
class SignupForm(LoginForm): """ Creates signup form instance with custom validation """ # form inputs email = forms.EmailField() password2 = forms.CharField(widget=PasswordInput) first_name = forms.CharField(max_length=30) last_name = forms.CharField(max_length=30) where_heard = forms.CharField(max_length=100, required=False) def clean_password2(self): """ Validates that the two password inputs match. """ if self.cleaned_data.get('password', None) and self.cleaned_data.get('password2', None) and \ self.cleaned_data['password'] == self.cleaned_data['password2']: return self.cleaned_data['password2'] else: raise forms.ValidationError(u'The passwords did not match') def clean_username(self): """ Validates that username is not in use """ username = self.cleaned_data.get('username', None) if username: try: User.objects.get(username=username) raise forms.ValidationError( u'username already exists, please choose another') except User.DoesNotExist: return username def save(self): """ Overrides save method to commit user to database and set their profile and group information """ user = User.objects.create_user( username=self.cleaned_data['username'], email=self.cleaned_data['email'], \ password=self.cleaned_data['password']) user.first_name = self.cleaned_data['first_name'] user.last_name = self.cleaned_data['last_name'] # add user to 'users' group so we can easily deal with permissions group_user = Group.objects.get(name="users") user.groups.add(group_user) user.save() # add profile info user_profile = UserProfile( where_heard=self.cleaned_data['where_heard'], criteria_pref_type="simple", user=user) user_profile.save() return user
class ContactForm(forms.Form): """ Contact form """ # form inputs name = forms.CharField() email = forms.EmailField() message = forms.CharField(widget=Textarea)
class RepositoryForm(forms.Form): location = forms.CharField( widget=forms.TextInput(attrs={'class': 'text-wide'}), ) enable_polling = forms.BooleanField( required=False, widget=forms.CheckboxInput(attrs={'class': 'checkbox'}), ) forward_pinger_mail = forms.BooleanField( required=False, widget=forms.CheckboxInput(attrs={'class': 'checkbox'}), ) poll_frequency = forms.IntegerField( widget=forms.TextInput(attrs={'class': 'text'}), ) revision_url = forms.CharField( required=False, widget=forms.TextInput(attrs={'class': 'text-wide'}), ) path_regexes = forms.CharField( required=False, widget=forms.Textarea, ) def clean_location(self): # On success, this will set up internal state in the # model but *not* set the location itself. That will # be done during apply(), so that it's included in # the changeset. location = self.cleaned_data['location'] # XXX - Bear hack: Unconditionally probe, so if we reactivated # the repository we don't pull all revisions since way back when. # Also makes sure the location is still valid. #if location != self.data.model.location: if location: # shouldn't be neccessary, required = True self.data.model.get_client().probe(location) return location def clean_revision_url(self): return self.cleaned_data.get('revision_url') or None def clean_path_regexes(self): # Remove extra whitespace and blank lines, then parse the resulting regexes. regexes = [] line_no = 1 for line in self.cleaned_data.get('path_regexes', '').split('\n'): line = line.strip() if line: try: re.compile(line, re.VERBOSE) except re.error, e: raise forms.ValidationError("Syntax error on line %d: %s" % (line_no, e)) regexes.append(line) line_no += 1 if regexes: return '\n'.join(regexes)
class RegistrationForm(forms.Form): first_name = forms.CharField(max_length=30) last_name = forms.CharField(max_length=30) email = forms.EmailField() username = forms.RegexField( r"^[a-zA-Z0-9_\-\.]*$", max_length=30, error_message='Only A-Z, 0-9, "_", "-", and "." allowed.') password = forms.CharField(min_length=5, max_length=30) password2 = forms.CharField()
class ItemForm(djangoforms.ModelForm): ## Custom djangoforms.ModelForm, ## http://groups.google.com/group/google-appengine/browse_thread/thread/d3673d0ec7ead0e2 mail = forms.CharField( label='您的邮箱(不会公开,无法更改)', widget=forms.TextInput( attrs={ 'readonly': '', 'size': '30', 'maxlength': '30', 'value': EditedUser.user.email() })) #urlname =forms.CharField(label='URL显示地址',widget=forms.TextInput(attrs={'size':'30','maxlength':'30','value':CurrentUser.urlname})) dispname = forms.CharField( label='显示名称', widget=forms.TextInput( attrs={ 'size': '30', 'maxlength': '30', 'value': EditedUser.dispname, 'class': 'sl' })) website = forms.CharField( label='您的网址(请加http://)', widget=forms.TextInput( attrs={ 'size': '36', 'maxlength': '36', 'value': EditedUser.website, 'class': 'sl' })) ##Please reference more from the URL #notify_dailybriefing = forms.BooleanField(label='每日邮件提醒',widget=forms.CheckboxInput(attrs={'checked':EditedUser.notify_dailybriefing})) #notify_dailybriefing_time = forms.CharField(label='每日邮件提醒时间', widget=forms.TextInput(attrs={'value':EditedUser.notify_dailybriefing_time,'class':'sl'})) #notify_addedasfriend = forms.BooleanField(label='用户添加好友邮件提醒',widget=forms.CheckboxInput(attrs={'checked':EditedUser.notify_addedasfriend})) apikey = forms.CharField(label="ApiKey(请勿泄露)", widget=forms.TextInput( attrs={ 'readonly': '', 'class': 'sl', 'value': EditedUser.apikey })) class Meta: model = tarsusaUser #exclude =['user','userid','usedtags','urlname','friends','datejoinin'] exclude = [ 'user', 'userid', 'usedtags', 'urlname', 'friends', 'datejoinin', 'notify_dailybriefing', 'notify_dailybriefing_time', 'notify_addedasfriend' ]
class EditBotForm(forms.Form): filter_mode = forms.ChoiceField( choices = models.filter_mode_choices, widget = forms.RadioSelect, ) project_list = forms.CharField( required = False, widget = forms.Textarea, ) show_project_names = forms.BooleanField( required = False, widget = forms.CheckboxInput(attrs = {'class': 'checkbox'}), ) def __init__(self, data=None): forms.Form.__init__(self, data) self.filter_modes = formtools.RadioChoices(self['filter_mode'], models.FILTER) def clean_filter_mode(self): return int(self.cleaned_data['filter_mode']) def clean_project_list(self): # Remove extra whitespace, split into individual projects. projects = [] for line in self.cleaned_data['project_list'].split('\n'): line = line.strip() if line: projects.append(line) # Is the project list required? if int(self.data['filter_mode']) == models.FILTER.PROJECT_LIST and not projects: raise forms.ValidationError("Please enter at least one project.") return '\n'.join(projects) custom_ruleset = forms.CharField( required = False, widget = forms.Textarea, ) def clean_custom_ruleset(self): # Empty rulesets are okay if we aren't using them. We never # allow a ruleset to be stored if it isn't well-formed and # valid. allow_empty = int(self.data['filter_mode']) != models.FILTER.CUSTOM # Use LibCIA to validate the ruleset. It would be nice to # hilight errors, or even interactively validate rulesets on # the client side.. but this is sufficient for now. return models.validate_ruleset(self.cleaned_data['custom_ruleset'], allow_empty) def apply(self, cset): cset.set_field_dict(self.cleaned_data) cset.asset.syncToServer()
class RSVPForm(forms.Form): name = forms.CharField(widget=DijitText) will_attend = forms.BooleanField(widget=DijitBoolean, label="Will Attend?", required=False) num_guests = forms.IntegerField(widget=DijitNumberSpinner, required=False, label="Total Number of Guests") additional_guests = forms.CharField(widget=DijitTextArea, required=False, label="Additional Guest Names")
class CommentForm(forms.Form): """ A form representing a comment on an entry. """ person_name = forms.CharField( label = _("Name (required)"), widget = forms.TextInput(attrs=dict(size="22"))) comment = forms.CharField( label = "", widget = forms.Textarea(attrs=dict(cols="60")))
class SKeyForm(forms.Form): skey = forms.CharField(label='S/Key', widget=forms.TextInput(attrs=dict(size=30))) email = forms.EmailField(widget=forms.TextInput(attrs=dict(size=42))) newpw = forms.CharField(label='New Password') def clean_skey(self): s = self.data['skey'] try: return skey.put(skey.get(s)) except KeyError: raise forms.ValidationError('Invalid S/Key data')
class CreateForm(forms.Form): username = forms.RegexField('^[a-zA-Z0-9_]*$', max_length=30) first_name = forms.CharField(max_length = 30, required = False) last_name = forms.CharField(max_length = 30, required = False) email = forms.EmailField() pw1 = forms.CharField(widget = forms.PasswordInput, label = 'Password') pw2 = forms.CharField(widget = forms.PasswordInput, label = 'Password (again)', required = False)
class NewRequestForm(forms.Form): title = forms.CharField( min_length=8, max_length=256, label=_('Title'), help_text=_('A short descriptive title for this request.')) description = forms.CharField( min_length=16, max_length=8192, widget=forms.Textarea, label=_('Description'), help_text= _('A longer, more elaboratively descriptive summary of the issue or request. "textile"-style markup is permitted here, or simply free-form text.' ))
class NameForm(forms.Form): Domain = forms.RegexField( r'^[a-zA-Z0-9\.-]+$', help_text="Fully-Qualified Domain Name of this machine") Organization = forms.CharField(help_text="Legal Name of Organization") OrganizationalUnit = forms.CharField( help_text="Organizational Unit, e.g. department name", required=False) ApplianceName = forms.CharField( help_text="Short name, appears in web pages and emails") CommonName = forms.CharField(help_text="Short name, appears in web pages")
class PaymentForm(forms.Form, SavesPayment): first_name = forms.CharField( label="First name", min_length=2, max_length=30, ) last_name = forms.CharField( label="Last name", min_length=2, max_length=30, ) card_number = forms.CharField(label="Card number", ) card_expiration = forms.DateField(label="Expiration", )
class PageForm(djangoforms.ModelForm): title = forms.CharField(widget=forms.Textarea(attrs={ 'id': 'name', 'rows': 5, 'cols': 50 })) body = forms.CharField(widget=forms.Textarea(attrs={ 'id': 'message', 'rows': 20, 'cols': 50 })) class Meta: model = models.PagePost fields = ['title', 'body']
class StatsMetadataForm(forms.Form): title = forms.CharField(widget=forms.TextInput(attrs={'class': 'text'}), ) subtitle = forms.CharField( required=False, widget=forms.TextInput(attrs={'class': 'text'}), ) url = forms.URLField( required=False, widget=forms.TextInput(attrs={'class': 'text'}), # Disabled for now, since it seems to imply required=True. # verify_exists = True, ) description = forms.CharField( required=False, widget=forms.Textarea, ) photo_id = forms.IntegerField( required=False, widget=ImageWidget, ) icon_id = forms.IntegerField( required=False, widget=ImageWidget, ) def clean_subtitle(self): return self.cleaned_data.get('subtitle') or None def clean_url(self): return self.cleaned_data.get('url') or None def clean_description(self): return self.cleaned_data.get('description') or None def clean_photo_id(self): return self.cleaned_data.get('photo_id') or None def clean_icon_id(self): return self.cleaned_data.get('icon_id') or None def apply(self, cset): target = cset.asset.target cset.set_field_dict(self.cleaned_data, prefix='target.') if target.photo: target.photo.reference() if target.icon: target.icon.reference()
def ship_charfield_clean(self, field_name): if self.cleaned_data['copy_address']: if field_name in self.cleaned_data: self.cleaned_data['ship_' + field_name] = self.cleaned_data[field_name] return self.cleaned_data['ship_' + field_name] field = forms.CharField(max_length=30) return field.clean(self.cleaned_data['ship_' + field_name])
class SimplePayShipForm(forms.Form): shipping = forms.ChoiceField(widget=forms.RadioSelect(), required=False) discount = forms.CharField(max_length=30, required=False) def __init__(self, request, paymentmodule, *args, **kwargs): super(SimplePayShipForm, self).__init__(*args, **kwargs) self.tempCart = Cart.objects.get(id=request.session['cart']) self.tempContact = Contact.from_request(request) shipping_choices, shipping_dict = _get_shipping_choices( paymentmodule, self.tempCart, self.tempContact) self.fields['shipping'].choices = shipping_choices self.shipping_dict = shipping_dict def clean_shipping(self): shipping = self.cleaned_data['shipping'] if not shipping and self.tempCart.is_shippable: raise forms.ValidationError(_('This field is required.')) return shipping def clean_discount(self): """ Check if discount exists and is valid. """ data = self.cleaned_data['discount'] if data: try: discount = Discount.objects.get(code=data, active=True) except Discount.DoesNotExist: raise forms.ValidationError(_('Invalid discount.')) valid, msg = discount.isValid(self.tempCart) if not valid: raise forms.ValidationError(msg) # TODO: validate that it can work with these products return data