dj_angles.attributes

Module Contents

dj_angles.attributes.VALID_ATTRIBUTE_TOKEN_COUNT = 2
class dj_angles.attributes.Attribute(attribute: str)

Encapsulates an attribute in an element. Attributes are a key-value pair, but the value can be None.

Examples

  • <dj-include ‘partial.html’> has 1 attribute: ‘partial.html’. The value is None.

  • <dj-include ‘partial.html’ shadow> has 2 attributes: ‘partial.html’ and shadow. The value is None.

  • <dj-include ‘partial.html’ shadow test=True> has 3 attributes: ‘partial.html’, shadow, test. The first 2 attributes have a value of None, but test has a value of True.

key: str

Key of the attribute. Always defined.

value: str | None = None

Optional value of the attribute. Defaults to None.

has_value: bool = False

Whether or not the attribute has a value.

class dj_angles.attributes.Attributes(template_tag_args: str)

Bases: collections.abc.Sequence

A list of attributes, usually inside a Tag.

template_tag_args: str

The original attributes as an unparsed string.

parse()

Parse the attributes string to generate a list of Attribute objects.

get(name: str) Attribute | None

Get an Attribute by name. Returns None if the attribute is missing.

Parameters:
  • name (param) – The name of the attribute.

  • default (param) – What to return if the attribute is not available. Defaults to None.

remove(key: str) None

Removes an attribute from the list.

Parameters:

key (param) – The key of the attribute to remove.

Raises:

MissingAttributeError – If the attribute is missing.

pop(index: SupportsIndex) Attribute

Remove and return the last attribute.

prepend(attribute_string: str) None

Parse the attribute string as an Attribute and add it to the beginning of the list of attributes.

Parameters:

attribute_string (param) – The attribute as a string.

Raises:

DuplicateAttributeError – If the attribute conflicts with an existing attribute.

append(attribute_string: str) None

Parse the attribute string as an Attribute and add it to the end of the list of attributes.

Parameters:

attribute_string (param) – The attribute as a string.

Raises:

DuplicateAttributeError – If the attribute conflicts with an existing attribute.