eulcommon.djangoextras – Extensions and additions to django

auth - Customized permission decorators

formfields - Custom form fields & widgets

Custom generic form fields for use with Django forms.


class eulcommon.djangoextras.formfields.W3CDateField(max_length=None, min_length=None, *args, **kwargs)

W3C date field that uses a W3CDateWidget for presentation and uses a simple regular expression to do basic validation on the input (but does not actually test that it is a valid date).

widget

alias of W3CDateWidget

class eulcommon.djangoextras.formfields.W3CDateWidget(attrs=None)

Multi-part date widget that generates three text input boxes for year, month, and day. Expects and generates dates in any of these W3C formats, depending on which fields are filled in: YYYY-MM-DD, YYYY-MM, or YYYY.

create_textinput(name, field, value, **extra_attrs)

Generate and render a django.forms.widgets.TextInput for a single year, month, or day input.

If size is specified in the extra attributes, it will also be used to set the maximum length of the field.

Parameters:
  • name – base name of the input field
  • field – pattern for this field (used with name to generate input name)
  • value – initial value for the field
  • extra_attrs – any extra widget attributes
Returns:

rendered HTML output for the text input

render(name, value, attrs=None)

Render the widget as HTML inputs for display on a form.

Parameters:
  • name – form field base name
  • value – date value
  • attrs
    • unused
Returns:

HTML text with three inputs for year/month/day

value_from_datadict(data, files, name)

Generate a single value from multi-part form data. Constructs a W3C date based on values that are set, leaving out day and month if they are not present.

Parameters:
  • data – dictionary of data submitted by the form
  • files
    • unused
  • name – base name of the form field
Returns:

string value

class eulcommon.djangoextras.formfields.DynamicChoiceField(choices=None, widget=None, *args, **kwargs)

A django.forms.ChoiceField whose choices are not static, but instead generated dynamically when referenced.

Parameters:choices – callable; this will be called to generate choices each time they are referenced
widget

alias of DynamicSelect

class eulcommon.djangoextras.formfields.DynamicSelect(attrs=None, choices=None)

A Select widget whose choices are not static, but instead generated dynamically when referenced.

Parameters:choices – callable; this will be called to generate choices each time they are referenced.

http - Content Negotiation for Django views