core.bones.code

Classes

CodeBone

Stores source code with optional language-specific syntax validation.

LogicsBone

Validates its value as a Logics expression (https://github.com/viur-framework/logics).

JinjaBone

Validates its value as a Jinja2 template.

PythonBone

Validates its value as Python source code.

Module Contents

class core.bones.code.CodeBone(*, indexed=False, languages=None, multiple=False, syntax=None, type_suffix='', validate=True, **kwargs)

Bases: viur.core.bones.raw.RawBone

Stores source code with optional language-specific syntax validation.

The syntax parameter sets the type suffix used by the frontend for syntax highlighting, e.g. syntax="python" yields type = "raw.code.python". type_suffix can override this to an arbitrary suffix.

Neither multiple nor languages are supported. Setting validate=False disables any syntax validation in subclasses.

Initializes a new Bone.

Parameters:
  • indexed (bool)

  • multiple (bool)

  • syntax (str | None)

  • type_suffix (str)

  • validate (bool)

type = 'raw.code'
syntax = None
validate = True
class core.bones.code.LogicsBone(*, syntax='logics', **kwargs)

Bases: CodeBone

Validates its value as a Logics expression (https://github.com/viur-framework/logics). Uses Python syntax highlighting in the frontend.

Initializes a new Bone.

Parameters:

syntax (str)

singleValueFromClient(value, skel, bone_name, client_data)

Load a single value from a client

Parameters:
  • value – The single value which should be loaded.

  • skel – The SkeletonInstance where the value should be loaded into.

  • bone_name – The bone name of this bone in the SkeletonInstance.

  • client_data – The data taken from the client, a dictionary with usually bone names as key

Returns:

A tuple. If the value is valid, the first element is the parsed value and the second is None. If the value is invalid or not parseable, the first element is a empty value and the second a list of ReadFromClientError.

isInvalid(value)

Checks if the current value of the bone in the given skeleton is invalid. Returns None if the value would be valid for this bone, an error-message otherwise.

class core.bones.code.JinjaBone(*, syntax='jinja2', **kwargs)

Bases: CodeBone

Validates its value as a Jinja2 template.

Initializes a new Bone.

Parameters:

syntax (str)

isInvalid(value)

Checks if the current value of the bone in the given skeleton is invalid. Returns None if the value would be valid for this bone, an error-message otherwise.

class core.bones.code.PythonBone(*, syntax='python', **kwargs)

Bases: CodeBone

Validates its value as Python source code.

Initializes a new Bone.

Parameters:

syntax (str)

isInvalid(value)

Checks if the current value of the bone in the given skeleton is invalid. Returns None if the value would be valid for this bone, an error-message otherwise.