Utils (feincms3.utils)#


The utils module is meant purely for feincms3’s internal use. Utilities may be added and removed without prior warning and without a deprecation period.

If you depend on some functionality from this module copy the code into your project (according to the very permissive license of course).

class feincms3.utils.ChoicesCharField(*args, **kwargs)[source]#

models.CharField with choices, which makes the migration framework always ignore changes to choices, ever.


Return enough information to recreate the field as a 4-tuple:

  • The name of the field on the model, if contribute_to_class() has been run.

  • The import path of the field, including the class, e.g. django.db.models.IntegerField. This should be the most portable version, so less specific may be better.

  • A list of positional arguments.

  • A dict of keyword arguments.

Note that the positional or keyword arguments must contain values of the following types (including inner values of collection types):

  • None, bool, str, int, float, complex, set, frozenset, list, tuple, dict

  • UUID

  • datetime.datetime (naive), datetime.date

  • top-level classes, top-level functions - will be referenced by their full import path

  • Storage instances - these have their own deconstruct() method

This is because the values here must be serialized into a text format (possibly new Python code, possibly JSON) and these are the only types with encoding handlers defined.

There’s no need to return the exact way the field was instantiated this time, just ensure that the resulting field is the same - prefer keyword arguments over positional ones, and omit parameters with their default values.

Return whether an URL is a first-party link or not.

First parties are defined by ALLOWED_HOSTS and can be overridden by passing an alternative list of hosts. The wildcard ["*"] isn’t recognized.

NOTE! first_party_hosts should not contain port numbers even if using a non-standard port, the same is true for Django’s ALLOWED_HOSTS setting.

One template tag is available to help with ensuring off-site links open in a new window (if you need this…). The template tag does not allow specifying the list of first party hosts (it always uses ALLOWED_HOSTS):

{% load feincms3 %}
<a href="{{ url }}" {% maybe_target_blank url %}>text</a>
feincms3.utils.validation_error(error, *, field, exclude, **kwargs)[source]#

Return a validation error that is associated with a particular field if it isn’t excluded from validation.

See https://github.com/django/django/commit/e8c056c31 for some background.