parsers.models

Parsers model graph

Model graph for the Parser base class and its subclasses.

Defines a Parser mixin for obtaining matches for regular expressions.

class parsers.models.FieldParser(*args, **kwargs)[source]

Bases: parsers.models.Parser

A FieldParser is a Parser designed to parse objects that contain fields accessible through dictionary keys. It extends the Parser class with the source_fields attribute:

Attribute:
source_fields: comma-separated field names from a dictionary that will
be used to assemble a value for a field in a custom object (defined by a DataField). For example, ‘user.screen_name,id_str’ may be used to construct a link to a tweet.
class Meta[source]

Bases: object

abstract = False
ordering = ['name']
clean()[source]

Adds custom validations to the model’s clean() method.

get_method_display(**morekwargs)
process(value)[source]

Takes a dictionary and returns a parsed result from the dictionary.

source_fields

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class parsers.models.Parser(*args, **kwargs)[source]

Bases: django.db.models.base.Model

An abstract base class for parsing a value from an object, such as a string or dictionary.

formatter

a template that will be used to format the parsed value, For example, ‘https://twitter.com/{}/’ may be used to construct a link to a Twitter profile.

regex

a string representing a pattern to be compiled as a regular expression

method

a string specifying the form of a result to be obtained from a regex search, e.g., the number of matches, presence/absence of a match, or the value of a substring from the first match

METHOD_CHOICES = (('COPY', 'Copy'), ('COUNT', 'Number of Occurrences'), ('DATE', 'Date from string'), ('P/A', 'Presence/Absence'), ('SUBSTRING', 'Substring'))
class Meta[source]

Bases: object

Metadata options.

abstract = False
ordering = ['name']
clean()[source]

Hook for doing any extra model-wide validation after clean() has been called on every field by self.clean_fields. Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.

formatter

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

get_method_display(**morekwargs)
method

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

process(value)[source]

Takes a value and returns a parsed result.

regex

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class parsers.models.StringParser(*args, **kwargs)[source]

Bases: parsers.models.Parser

A StringParser provides proper validation for parsing and formatting strings.

class Meta[source]

Bases: object

abstract = False
ordering = ['name']
clean()[source]

Adds custom validations to the model’s clean() method.

get_method_display(**morekwargs)