Exemplo n.º 1
0
class SettingsForm(forms.ModelForm):
	start = forms.DateField(input_formats=('%d.%m.%Y',), error_messages=RU_ERRORS, widget=forms.DateInput(attrs={'class': 'input-small form-control'}))
	finish = forms.DateField(input_formats=('%d.%m.%Y',), error_messages=RU_ERRORS, widget=forms.DateInput(attrs={'class': 'input-small form-control'}))
	time = forms.TimeField(input_formats=('%H:%M',), error_messages=RU_ERRORS, widget=forms.TimeInput(attrs={'class': 'form-control', 'id': 'alert-time-display', 'value': '12:00'}))
	email = forms.EmailField(required=False, error_messages=RU_ERRORS, widget=forms.EmailInput(attrs={'class': 'form-control', 'placeholder': u'Укажите email для оповещений'}))
	phone = forms.RegexField(r'^\+79\d{9}$', '^\+79\d{9}$', required=False, error_messages=RU_ERRORS, widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': u'+79123456789'}))
	user_time = forms.CharField(widget=forms.HiddenInput())

	class Meta:
		model = Alert
		widgets = {
			'alert_email': forms.CheckboxInput(attrs={'id': 'email-alert'}),
			'alert_sms': forms.CheckboxInput(attrs={'id': 'sms-alert'}),
			'period': forms.Select(attrs={'class': 'form-control'}),
		}
		exclude = ['user', 'alert_server_time']

	def clean(self):
		cleaned_data = super(SettingsForm, self).clean()

		if cleaned_data.get('alert_email') and cleaned_data.get('email') == '':
			raise forms.ValidationError(u'Введите email')

		if cleaned_data.get('alert_sms') and cleaned_data.get('phone') == '':
			raise forms.ValidationError(u'Введите номер телефона')
	
		return cleaned_data
Exemplo n.º 2
0
class AllFieldsForm(forms.Form):
    boolean = forms.BooleanField()
    char = forms.CharField(max_length=50)
    choices = forms.ChoiceField(choices=ALPHA_CHOICES)
    date = forms.DateField()
    datetime = forms.DateTimeField()
    decimal = forms.DecimalField(decimal_places=2, max_digits=4)
    email = forms.EmailField()
    file_field = forms.FileField()
    file_path = forms.FilePathField(path='uploads/')
    float_field = forms.FloatField()
    generic_ip_address = forms.GenericIPAddressField()
    image = forms.ImageField()
    integer = forms.IntegerField()
    ip_address = forms.IPAddressField()
    multiple_choices = forms.MultipleChoiceField(choices=ALPHA_CHOICES)
    null_boolean = forms.NullBooleanField()
    regex_field = forms.RegexField(regex='^\w+$', js_regex='^[a-zA-Z]+$')
    slug = forms.SlugField()
    split_datetime = forms.SplitDateTimeField()
    time = forms.TimeField()
    typed_choices = forms.TypedChoiceField(choices=NUMERIC_CHOICES, coerce=int)
    typed_multiple_choices = forms.TypedMultipleChoiceField(
        choices=NUMERIC_CHOICES, coerce=int)
    url = forms.URLField()

    # GIS fields.
    if gis_forms:
        osm_point = gis.PointField(
            widget=mixin(gis.PointWidget, gis.BaseOsmWidget))
        osm_multipoint = gis.MultiPointField(
            widget=mixin(gis.MultiPointWidget, gis.BaseOsmWidget))
        osm_linestring = gis.LineStringField(
            widget=mixin(gis.LineStringWidget, gis.BaseOsmWidget))
        osm_multilinestring = gis.MultiLineStringField(
            widget=mixin(gis.MultiLineStringWidget, gis.BaseOsmWidget))
        osm_polygon = gis.PolygonField(
            widget=mixin(gis.PolygonWidget, gis.BaseOsmWidget))
        osm_multipolygon = gis.MultiPolygonField(
            widget=mixin(gis.MultiPolygonWidget, gis.BaseOsmWidget))

        gmap_point = gis.PointField(
            widget=mixin(gis.PointWidget, BaseGMapWidget))
        gmap_multipoint = gis.MultiPointField(
            widget=mixin(gis.MultiPointWidget, BaseGMapWidget))
        gmap_linestring = gis.LineStringField(
            widget=mixin(gis.LineStringWidget, BaseGMapWidget))
        gmap_multilinestring = gis.MultiLineStringField(
            widget=mixin(gis.MultiLineStringWidget, BaseGMapWidget))
        gmap_polygon = gis.PolygonField(
            widget=mixin(gis.PolygonWidget, BaseGMapWidget))
        gmap_multipolygon = gis.MultiPolygonField(
            widget=mixin(gis.MultiPolygonWidget, BaseGMapWidget))
Exemplo n.º 3
0
class ContactForm(forms.ModelForm):

    def __init__(self, *args, **kwargs):
        user = kwargs.pop('request_user') 
        super(ContactForm, self).__init__(*args, **kwargs)
        self.fields['roles'].queryset = Role.objects.filter(owner=user.groups.all()[0])

    telephone_mobile = forms.RegexField(label=('Mobile Telephone'), max_length=25, regex=r'^[\+]?\d{2}(?: ?\d+)*$', error_message=("Please enter a valid phone number."),)

    class Meta:
        model = Contact
        exclude = ('owner',)
Exemplo n.º 4
0
class FloppyUserChangeForm(UserChangeForm):
    username = floppyforms.RegexField(
        label=_("Username"),
        max_length=30,
        regex=r"^[\w.@+-]+$",
        help_text=_("Required. 30 characters or fewer. Letters, digits and "
                    "@/./+/-/_ only."),
        error_messages={
            'invalid':
            _("This value may contain only letters, numbers and "
              "@/./+/-/_ characters.")
        })
Exemplo n.º 5
0
class FloppyUserCreationForm(UserCreationForm):
    username = floppyforms.RegexField(
        label=_("Username"),
        max_length=30,
        regex=r'^[\w.@+-]+$',
        help_text=_("Required. 30 characters or fewer. Letters, digits and "
                    "@/./+/-/_ only."),
        error_messages={
            'invalid':
            _("This value may contain only letters, numbers and "
              "@/./+/-/_ characters.")
        })
    password1 = floppyforms.CharField(label=_("Password"),
                                      widget=floppyforms.PasswordInput)
    password2 = floppyforms.CharField(
        label=_("Password confirmation"),
        widget=floppyforms.PasswordInput,
        help_text=_("Enter the same password as above, for verification."))
Exemplo n.º 6
0
class SetUsernameForm(forms.ModelForm):
    """A form for a user with an auto-username to pick one."""
    username = forms.RegexField(
        regex=r'^[\w.@+-]+$',
        max_length=30,
        label="Username",
        error_messages={
            "invalid": ("This value must contain only letters, "
                        "numbers and underscores.")
        },
    )

    class Meta:
        model = model.User
        fields = ["username"]

    def __init__(self, *args, **kwargs):
        """Clear the initial value of the username field."""
        super(SetUsernameForm, self).__init__(*args, **kwargs)

        self.initial["username"] = ""
Exemplo n.º 7
0
 class RegexForm(forms.Form):
     re_field = forms.RegexField(r'^\d{3}-[a-z]+$', '\d{3}-[a-z]+')
     re_field_ = forms.RegexField(r'^[a-z]{2}$')