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 DistanceForm(forms.Form): ocean = forms.IntegerField(min_value=1, max_value=100, widget=forms.TextInput(attrs={ 'maxlength': 3, 'size': 3 })) group = forms.IntegerField(min_value=1, max_value=100, widget=forms.TextInput(attrs={ 'maxlength': 3, 'size': 3 })) isle_num = forms.IntegerField(min_value=1, max_value=25, widget=forms.TextInput(attrs={ 'maxlength': 2, 'size': 3 })) rulerless = forms.BooleanField(required=False, label="Rulerless", initial=True) weak = forms.BooleanField( required=False, label="Ruled by Weak Players (Really? Pick on the newbs?)") threshold = forms.IntegerField(required=False, min_value=0, initial=2500, label='...with a score threshold of')
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()
class CustomChargeForm(forms.Form): orderitem = forms.IntegerField(required=True, widget=forms.HiddenInput()) amount = forms.DecimalField(label=_('New price'), required=False) shipping = forms.DecimalField(label=_('Shipping adjustment'), required=False) notes = forms.CharField(_("Notes"), required=False, initial="Your custom item is ready.")
def formfield(self, **kwargs): defaults = { 'required': not self.blank, 'label': capfirst(self.verbose_name), 'help_text': self.help_text } defaults.update(kwargs) return forms.IntegerField(**defaults)
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 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 MoveMoneyForm(forms.Form): def __init__(self, data=None, from_account=None, *arg, **kwarg): self.base_fields['account'].queryset = Account.objects\ .filter(balance_currency=from_account.balance_currency)\ .exclude(number__exact=from_account.number) super(MoveMoneyForm, self).__init__(data, *arg, **kwarg) account = forms.ModelChoiceField(None) amount = forms.DecimalField(max_digits=12, decimal_places=2, min_value=0) tag = forms.IntegerField(widget=forms.Select(choices=add_empty_label(TX_TAG_CHOICES)), required=False) description = forms.CharField(widget=forms.Textarea())
class AnalysisForm(forms.Form): FORMAT="%Y-%m-%d %H:%M:%S" td=datetime.datetime.utcnow() NOW=td.strftime(FORMAT) yd = datetime.datetime.utcnow() - datetime.timedelta(1) YESTERDAY=yd.strftime(FORMAT) starttime = forms.DateTimeField( label="Start Time", initial=YESTERDAY) endtime = forms.DateTimeField( label="End Time", initial=NOW) sitename = forms.ChoiceField(label="Site Name", choices=SITE_CHOICES) format = forms.ChoiceField(label="Output Format", choices=FORMAT_CHOICES, initial="txt") datatype = forms.ChoiceField(label="Data Type" , choices=ATYPE_CHOICES, initial="counts") filtertype = forms.ChoiceField(label="Processing Type", choices=FILTER_CHOICES, initial="avg") interval = forms.IntegerField(label="Averaging Interval (minutes)", initial=30)
class AnnotationForm(forms.Form): explanation = forms.CharField( min_length=16, max_length=8192, widget=forms.Textarea, label=_('Annotation'), help_text= _('Annotation text for this issue. "textile"-style markup is permitted here, or simply free form text.' )) timetrack = forms.IntegerField( initial=0, label=_('Time Taken'), help_text= _('The time in hours taken responding to this request, if appropriate.' ))
#------------------------------------------------------------------------------ class ReportsForm(forms.Form): "Класс формы для отчета" report_kind = forms.ChoiceField(label="Вид отчета", choices=REPORT_KINDS, help_text="Выберите вид отчета") # device = forms.ModelChoiceField(queryset=Device.objects.filter()) interval_begin = forms.DateTimeField(label="Начало периода", widget=forms.TextInput(attrs={"class" : "vDateField"}), help_text="гггг-мм-дд чч:мм:сс") interval_end = forms.DateTimeField(label="Конец периода", widget=forms.TextInput(attrs={"class" : "vDateField"}), help_text="гггг-мм-дд чч:мм:сс") speed_limit = forms.IntegerField(label="Ограничение скорости", initial=72, help_text="скорость в км/ч") def __init__(self, account, *args, **kwargs): """ Конструктор переопределен для создания поля "device", список значений для которого фильтруется в соответствии с текущим Аккаунтом """ super(ReportsForm, self).__init__(*args, **kwargs)
class DistanceForm(forms.Form): ocean = forms.IntegerField(min_value=1, max_value=100, widget=forms.TextInput(attrs={'maxlength':3, 'size':3} )) group = forms.IntegerField(min_value=1, max_value=100, widget=forms.TextInput(attrs={'maxlength':3, 'size':3} )) isle_num = forms.IntegerField(min_value=1, max_value=25, widget=forms.TextInput(attrs={'maxlength':2, 'size':3} )) rulerless = forms.BooleanField(required=False, label="Rulerless", initial=True) low_score = forms.BooleanField(required=False, label='...with a score less than') threshold = forms.IntegerField(required=False, min_value=0, initial=2500 ) weak_alliance = forms.BooleanField(required=False, label='...in an alliance with a score less than') alliance_threshold = forms.IntegerField(required=False, min_value=0, initial=2500) low_island_count = forms.BooleanField(required=False, label='...with an island count less than') max_num_islands = forms.IntegerField(required=False, min_value=0, initial=6)
def __init__(self, *args, **kwargs): products = kwargs.pop('products', None) super(InventoryForm, self).__init__(*args, **kwargs) if not products: products = Product.objects.all().order_by('slug') for product in products: subtypes = product.get_subtypes() qtyclasses = ('text', 'qty') + subtypes qtyclasses = " ".join(qtyclasses) kw = { 'label': product.slug, 'help_text': product.name, 'initial': product.items_in_stock, 'widget': forms.TextInput(attrs={'class': qtyclasses}) } qty = forms.IntegerField(**kw) self.fields['qty__%s' % product.slug] = qty qty.slug = product.slug qty.product_id = product.id qty.subtypes = " ".join(subtypes) kw['initial'] = product.unit_price kw['required'] = False kw['widget'] = forms.TextInput(attrs={'class': "text price"}) price = forms.DecimalField(**kw) price.slug = product.slug self.fields['price__%s' % product.slug] = price kw['initial'] = product.active kw['widget'] = forms.CheckboxInput( attrs={'class': "checkbox active"}) active = forms.BooleanField(**kw) active.slug = product.slug self.fields['active__%s' % product.slug] = active kw['initial'] = product.featured kw['widget'] = forms.CheckboxInput( attrs={'class': "checkbox featured"}) featured = forms.BooleanField(**kw) featured.slug = product.slug self.fields['featured__%s' % product.slug] = featured
class PatternForm(forms.Form): length = forms.IntegerField(maxlength=100)
class TransactionForm(forms.Form): amount = forms.DecimalField(max_digits=12, decimal_places=2, min_value=0) tag = forms.IntegerField(widget=forms.Select(choices=add_empty_label(TX_TAG_CHOICES)), required=False) description = forms.CharField(widget=forms.Textarea())
class CreditPayShipForm(forms.Form): credit_type = forms.ChoiceField() credit_number = forms.CharField(max_length=20) month_expires = forms.ChoiceField(choices=[(month, month) for month in range(1, 13)]) year_expires = forms.ChoiceField() ccv = forms.IntegerField() # find min_length shipping = forms.ChoiceField(widget=forms.RadioSelect(), required=False) discount = forms.CharField(max_length=30, required=False) def __init__(self, request, paymentmodule, *args, **kwargs): creditchoices = paymentmodule.CREDITCHOICES.choice_values super(CreditPayShipForm, self).__init__(*args, **kwargs) self.fields['credit_type'].choices = creditchoices year_now = datetime.date.today().year self.fields['year_expires'].choices = [ (year, year) for year in range(year_now, year_now + 6) ] 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_credit_number(self): """ Check if credit card is valid. """ credit_number = self.cleaned_data['credit_number'] card = CreditCard(credit_number, self.cleaned_data['credit_type']) results, msg = card.verifyCardTypeandNumber() if not results: raise forms.ValidationError(msg) return credit_number def clean_month_expires(self): return int(self.cleaned_data['month_expires']) def clean_year_expires(self): """ Check if credit card has expired. """ month = self.cleaned_data['month_expires'] year = int(self.cleaned_data['year_expires']) max_day = calendar.monthrange(year, month)[1] if datetime.date.today() > datetime.date( year=year, month=month, day=max_day): raise forms.ValidationError(_('Your card has expired.')) return year 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 if it applies to these products """ data = self.cleaned_data['discount'] if data: discount = Discount.objects.filter(code=data).filter(active=True) if discount.count() == 0: raise forms.ValidationError(_('Invalid discount.')) valid, msg = discount[0].isValid(self.tempCart) if not valid: raise forms.ValidationError(msg) return data
class PostForm(forms.Form): comment = forms.CharField(widget=forms.Textarea) next = forms.CharField(widget=forms.HiddenInput) markup = forms.IntegerField(widget=forms.HiddenInput)
class EditForm(forms.Form): name = forms.CharField() adminUrl = forms.URLField(required=False) memberUrl = forms.URLField(required=False) worklist_limit = forms.IntegerField(required=False)