Fields for Models and Forms¶
This module contains custom field types for Django models and forms.
Custom Django field and formfield types (for models and forms.
-
openquake.engine.db.fields.
ARRAY_RE
= <_sre.SRE_Pattern object>¶ regex for splitting string lists on whitespace and/or commas
-
class
openquake.engine.db.fields.
CharArrayField
(verbose_name=None, name=None, primary_key=False, max_length=None, unique=False, blank=False, null=False, db_index=False, rel=None, default=<class django.db.models.fields.NOT_PROVIDED>, editable=True, serialize=True, unique_for_date=None, unique_for_month=None, unique_for_year=None, choices=None, help_text=u'', db_column=None, db_tablespace=None, auto_created=False, validators=[], error_messages=None)[source]¶ Bases:
django.db.models.fields.Field
This field models a postgres varchar array.
-
formfield
(**kwargs)[source]¶ Specify a custom form field type so forms know how to handle fields of this type.
-
get_prep_value
(value)[source]¶ Return data in a format that has been prepared for use as a parameter in a query.
Parameters: value (list or tuple) – sequence of string values to be saved in a varchar[] field >>> caf = CharArrayField() >>> caf.get_prep_value(['foo', 'bar', 'baz123']) '{"foo", "bar", "baz123"}'
-
-
class
openquake.engine.db.fields.
DictField
(verbose_name=None, name=None, primary_key=False, max_length=None, unique=False, blank=False, null=False, db_index=False, rel=None, default=<class django.db.models.fields.NOT_PROVIDED>, editable=True, serialize=True, unique_for_date=None, unique_for_month=None, unique_for_year=None, choices=None, help_text=u'', db_column=None, db_tablespace=None, auto_created=False, validators=[], error_messages=None)[source]¶ Bases:
openquake.engine.db.fields.PickleField
Field for storing Python dict objects (or a JSON text representation.
-
contribute_to_class
(cls, name, **kwargs)¶
-
-
class
openquake.engine.db.fields.
FloatArrayField
(verbose_name=None, name=None, primary_key=False, max_length=None, unique=False, blank=False, null=False, db_index=False, rel=None, default=<class django.db.models.fields.NOT_PROVIDED>, editable=True, serialize=True, unique_for_date=None, unique_for_month=None, unique_for_year=None, choices=None, help_text=u'', db_column=None, db_tablespace=None, auto_created=False, validators=[], error_messages=None)[source]¶ Bases:
django.db.models.fields.Field
This field models a postgres float array.
-
class
openquake.engine.db.fields.
FloatArrayFormField
(required=True, widget=None, label=None, initial=None, help_text=u'', error_messages=None, show_hidden_initial=False, validators=[], localize=False, label_suffix=None)[source]¶ Bases:
openquake.engine.db.fields.StringArrayFormField
Form field for properly handling float arrays/lists.
-
cast
¶ alias of
float
-
value_type
= 'float'¶
-
-
class
openquake.engine.db.fields.
GzippedField
(verbose_name=None, name=None, primary_key=False, max_length=None, unique=False, blank=False, null=False, db_index=False, rel=None, default=<class django.db.models.fields.NOT_PROVIDED>, editable=True, serialize=True, unique_for_date=None, unique_for_month=None, unique_for_year=None, choices=None, help_text=u'', db_column=None, db_tablespace=None, auto_created=False, validators=[], error_messages=None)[source]¶ Bases:
django.db.models.fields.Field
Automatically stores gzipped text as a bytearray
-
contribute_to_class
(cls, name, **kwargs)¶
-
-
class
openquake.engine.db.fields.
IntArrayField
(verbose_name=None, name=None, primary_key=False, max_length=None, unique=False, blank=False, null=False, db_index=False, rel=None, default=<class django.db.models.fields.NOT_PROVIDED>, editable=True, serialize=True, unique_for_date=None, unique_for_month=None, unique_for_year=None, choices=None, help_text=u'', db_column=None, db_tablespace=None, auto_created=False, validators=[], error_messages=None)[source]¶ Bases:
django.db.models.fields.Field
This field models a postgresql int array
-
class
openquake.engine.db.fields.
LiteralField
(verbose_name=None, name=None, primary_key=False, max_length=None, unique=False, blank=False, null=False, db_index=False, rel=None, default=<class django.db.models.fields.NOT_PROVIDED>, editable=True, serialize=True, unique_for_date=None, unique_for_month=None, unique_for_year=None, choices=None, help_text=u'', db_column=None, db_tablespace=None, auto_created=False, validators=[], error_messages=None)[source]¶ Bases:
django.db.models.fields.Field
Convert from Postgres TEXT to Python objects and viceversa by using ast.literal_eval and repr.
-
contribute_to_class
(cls, name, **kwargs)¶
-
-
class
openquake.engine.db.fields.
NullCharField
(max_length=None, min_length=None, *args, **kwargs)[source]¶ Bases:
django.forms.fields.CharField
-
class
openquake.engine.db.fields.
NullFloatField
(verbose_name=None, name=None, primary_key=False, max_length=None, unique=False, blank=False, null=False, db_index=False, rel=None, default=<class django.db.models.fields.NOT_PROVIDED>, editable=True, serialize=True, unique_for_date=None, unique_for_month=None, unique_for_year=None, choices=None, help_text=u'', db_column=None, db_tablespace=None, auto_created=False, validators=[], error_messages=None)[source]¶ Bases:
django.db.models.fields.FloatField
A nullable float field that handles blank input values properly.
-
class
openquake.engine.db.fields.
NullTextField
(**kwargs)[source]¶ Bases:
django.db.models.fields.TextField
-
class
openquake.engine.db.fields.
NumpyListField
(verbose_name=None, name=None, primary_key=False, max_length=None, unique=False, blank=False, null=False, db_index=False, rel=None, default=<class django.db.models.fields.NOT_PROVIDED>, editable=True, serialize=True, unique_for_date=None, unique_for_month=None, unique_for_year=None, choices=None, help_text=u'', db_column=None, db_tablespace=None, auto_created=False, validators=[], error_messages=None)[source]¶ Bases:
openquake.engine.db.fields.PickleField
Field for storing numpy arrays as pickled blobs. The actual blob stored in the database is simply a pickled list. When the field is instantiated, the value is converted back to a numpy array.
-
contribute_to_class
(cls, name, **kwargs)¶
-
-
class
openquake.engine.db.fields.
OqNullBooleanField
(*args, **kwargs)[source]¶ Bases:
django.db.models.fields.NullBooleanField
A NullBooleanField that can convert meaningful strings to boolean values (in the case of config file parameters).
-
class
openquake.engine.db.fields.
PickleField
(verbose_name=None, name=None, primary_key=False, max_length=None, unique=False, blank=False, null=False, db_index=False, rel=None, default=<class django.db.models.fields.NOT_PROVIDED>, editable=True, serialize=True, unique_for_date=None, unique_for_month=None, unique_for_year=None, choices=None, help_text=u'', db_column=None, db_tablespace=None, auto_created=False, validators=[], error_messages=None)[source]¶ Bases:
django.db.models.fields.Field
Field for transparent pickling and unpickling of python objects.
-
SUPPORTED_BACKENDS
= set(['django.db.backends.postgresql_psycopg2', 'django.contrib.gis.db.backends.postgis'])¶
-
contribute_to_class
(cls, name, **kwargs)¶
-
-
class
openquake.engine.db.fields.
PickleFormField
(required=True, widget=None, label=None, initial=None, help_text=u'', error_messages=None, show_hidden_initial=False, validators=[], localize=False, label_suffix=None)[source]¶ Bases:
django.forms.fields.Field
Form field for Python objects which are pickle and saved to the database.
-
class
openquake.engine.db.fields.
StringArrayFormField
(required=True, widget=None, label=None, initial=None, help_text=u'', error_messages=None, show_hidden_initial=False, validators=[], localize=False, label_suffix=None)[source]¶ Bases:
django.forms.fields.Field
Base class containing general functionality for handling list-like parameters.
-
cast
¶ alias of
str
-
clean
(value)[source]¶ Try to coerce either a string list of values (separated by whitespace and/or commas or a list/tuple of values to a list of floats. If unsuccessful, raise a
django.forms.ValidationError
-
value_type
= 'str'¶
-