Utils Forms

inyoka.utils.forms

This file contains extensions for the django forms like special form fields.

copyright:
  1. 2007-2025 by the Inyoka Team, see AUTHORS for more details.

license:

BSD, see LICENSE for more details.

class inyoka.utils.forms.CaptchaField(session, *args, **kwargs)

Allows adding a captcha to a form. It consists of two fields:

  • a field to insert the value of the captcha. It also includes the captcha image.

  • a hidden field intended to catch some bots that simply fill every field with some content.

Instantiate a CaptchaField in the __init__ of the form, because this field needs the current user session as an init-parameter.

_session_cache_key() str

Returns a unique cache key. The key is scoped to the portal.

_session_hash() str

Returns a unique checksum for the current session. It is used for a unique cache key.

compress(data_list) bool

Returns, whether the captcha was filled valid. If all fields are valid, both should return True.

In case of an error, ImageCaptchaField and HiddenCaptchaField raise a ValidationError themselves.

delete_cached_captcha() None

Allows views to rotate the captcha (e.g., if it was successfully used or the user requests another one).

This will just remove the captcha of the associated session. Thus, on the next request a new captcha is created.

class inyoka.utils.forms.CaptchaWidget(captcha_img, attrs=None)

Custom widget for CaptchaField.

decompress(value)

Decompress always defaults to empty, as the user should enter the captcha (like a password) and the hidden input should always be empty.

property media

Media for a multiwidget is the combination of all media of the subwidgets.

class inyoka.utils.forms.EmailField(**kwargs)
clean(value)

Validate the given value and return its “cleaned” value as an appropriate Python object. Raise ValidationError for any errors.

class inyoka.utils.forms.ForumMulitpleChoiceField(*args, **kwargs)
is_category = False
class inyoka.utils.forms.HiddenCaptchaField(*args, **kwargs)

A hidden field intended to catch some bots that simply fill every field with some content.

clean(value)

Validate the given value and return its “cleaned” value as an appropriate Python object. Raise ValidationError for any errors.

widget

alias of HiddenInput

class inyoka.utils.forms.ImageCaptchaField(captcha_solution, *args, **kwargs)

Field that checks if the entered value fits the captcha solution.

clean(value)

Validate the given value and return its “cleaned” value as an appropriate Python object. Raise ValidationError for any errors.

class inyoka.utils.forms.ImageCaptchaWidget(captcha_img, *args, **kwargs)

A text input where users enter the captcha value of the associated captcha image. The Latter is also rendered in this class.

class Media
css = {'all': ['style/captcha.css']}
get_context(name, value, attrs)
property media
template_name = 'forms/widgets/image_captcha.html'
class inyoka.utils.forms.JabberFormField(*args, **kwargs)
_jabber_re = re.compile('(?xi)(?:[a-z0-9!$\\(\\)*+,;=\\[\\\\\\]\\^`{|}\\-._~]+)@', re.IGNORECASE|re.VERBOSE)
class inyoka.utils.forms.MultiField(fields=(), *args, **kwargs)

This field validates a bunch of values using zero, one or more fields. If the value is just one string, a list is created.

clean(value)

Validates that the value is a list or a tuple.

widget

alias of SelectMultiple

class inyoka.utils.forms.NativeDateInput

Uses <input type=”date”>. Thus, the default format is also changed to ISO-like 2017-01-01 (year-month-day).

If browsers do not support the input-type, the fallback will be the default of DateInput: <input type=”text”>.

date_format = '%Y-%m-%d'
property media
class inyoka.utils.forms.NativeSplitDateTimeWidget

Uses <input type=”time”> for the time field and <input type=”date”> for the date field. See NativeDateInput and NativeTimeInput for some details.

Note that the field in the form needs to be a SplitDateTimeField.

property media

Media for a multiwidget is the combination of all media of the subwidgets.

time_step = 1
class inyoka.utils.forms.NativeTimeInput

Uses <input type=”time”>. Thus, the default format is also changed to 12:37:31 (hour:minute:second).

If browsers do not support the input-type, the fallback will be the default of TimeInput: <input type=”text”>.

property media
step = 1
time_format = '%H:%M:%S'
class inyoka.utils.forms.SlugField(*, max_length=None, min_length=None, strip=True, empty_value='', **kwargs)
clean(value)

Validate the given value and return its “cleaned” value as an appropriate Python object. Raise ValidationError for any errors.

class inyoka.utils.forms.StrippedCharField(*, max_length=None, min_length=None, strip=True, empty_value='', **kwargs)
default_validators = [<function validate_empty_text>]
class inyoka.utils.forms.TopicField(*, max_length=None, min_length=None, strip=True, empty_value='', **kwargs)
clean(value)

Validate the given value and return its “cleaned” value as an appropriate Python object. Raise ValidationError for any errors.

label = 'URL of the topic'
class inyoka.utils.forms.UserField(*, max_length=None, min_length=None, strip=True, empty_value='', **kwargs)

Allows to enter a username as text and validates if the given user exists.

prepare_value(data)

Returns the username from the given data.

data can be: - a string, then it has to be the username, - None, then the field is empty, - a user object, then the username of this user is returned or - a user id, then the user is fetched from the database.

to_python(value)

Return a string.

inyoka.utils.forms.clear_surge_protection(request, form)

Clean errors in parent form so that submitting inherited forms don’t raise any errors.

This function also cleanup the surge protection timer so that we get no nasty hiccups by just submitting an inherited form and sending the whole form afterwards.

inyoka.utils.forms.validate_empty_text(value)
inyoka.utils.forms.validate_gpgkey(value)
inyoka.utils.forms.validate_signature(signature)

Parse a signature and check if it’s valid.