zengine.forms package¶
- Zengine’s Forms module contains two form classes and a custom field;
zengine.forms.fields module¶
zengine.forms.json_form module¶
This module contains JsonForm class which extends ModelForm to achieve three main goals:
- Allow custom forms.
- Allow attaching of additional fields and buttons to existing Forms.
- Implement JSON serialization compatible with Ulakbus-UI API.
-
class
zengine.forms.json_form.
FormCache
(form_id=None)[source]¶ Bases:
zengine.lib.cache.Cache
Caches various properties of serialized form to validate incoming form data
Parameters: form_id – Unique form id
-
class
zengine.forms.json_form.
JsonForm
(*args, **kwargs)[source]¶ Bases:
zengine.forms.model_form.ModelForm
A base class for building customizable forms with pyoko fields and models. Has some fake methods and attributes to simulate model API
from zengine.forms import fields, JsonForm class TestForm(JsonForm): class Meta: title = 'Form Title' help_text = "Form help text" code = fields.String("Code Field") no = fields.Integer('Part No', required=False) save = fields.Button("Save", cmd="save_it", flow="goto_finish") class SomeFoos(ListNode): foo = fields.String('Foo Field') hid = fields.String(hidden=True)
-
class
Meta
¶ Bases:
object
ModelForm Meta class holds config data that modifies the behaviour of form objects.
Variables: - title (str) – Title text to be shown top of the form.
- help_text (str) – Help text to be shown under the title.
- customize_types (dict) –
Override field types. A dict that maps fields names with desired field types.
>>> customize_types={"user_password": "password"}
- include ([]) – List of field names to be included. If given, all other fields will be excluded.
- exclude ([]) – List of field names to be excluded. If given, all other fields will be included.
- constraints (dict) –
Form constraints to be enforced by both client side and backend form processors.
See Ulakbus-UI API docs for possible constraints.
constraints = [ { 'cons': [{'id': 'field2_id', 'cond': 'exists'}], 'do': 'change_fields', 'fields': [{'field2_id': None}] }, { 'cons': [{'id': 'field2_id', 'cond': 'exists'}], 'do': 'change_fields', 'fields': [{'field1_id': None}] } ]
-
get_links
(**kw)[source]¶ Prepare links of form by mimicing pyoko’s get_links method’s result
Parameters: **kw – Returns: list of link dicts
-
serialize
()[source]¶ Converts the form/model into JSON ready dicts/lists compatible with Ulakbus-UI API.
Example
{ "forms": { "constraints": {}, "model": { "code": null, "name": null, "save_edit": null, }, "grouping": {}, "form": [ { "helpvalue": null, "type": "help" }, "name", "code", "save_edit" ], "schema": { "required": [ "name", "code", "save_edit" ], "type": "object", "properties": { "code": { "type": "string", "title": "Code Name" }, "name": { "type": "string", "title": "Name" }, "save_edit": { "cmd": "save::add_edit_form", "type": "button", "title": "Save" } }, "title": "Add Permission" } } }
-
class
zengine.forms.model_form module¶
this module holds methods that responsible for form generation both from models or standalone forms
-
class
zengine.forms.model_form.
ModelForm
(model=None, exclude=None, include=None, types=None, title=None, **kwargs)[source]¶ Bases:
object
Serializes / Deserializes pyoko models.
-
class
Meta
[source]¶ ModelForm Meta class holds config data that modifies the behaviour of form objects.
Variables: - title (str) – Title text to be shown top of the form.
- help_text (str) – Help text to be shown under the title.
- customize_types (dict) –
Override field types. A dict that maps fields names with desired field types.
>>> customize_types={"user_password": "password"}
- include ([]) – List of field names to be included. If given, all other fields will be excluded.
- exclude ([]) – List of field names to be excluded. If given, all other fields will be included.
- constraints (dict) –
Form constraints to be enforced by both client side and backend form processors.
See Ulakbus-UI API docs for possible constraints.
constraints = [ { 'cons': [{'id': 'field2_id', 'cond': 'exists'}], 'do': 'change_fields', 'fields': [{'field2_id': None}] }, { 'cons': [{'id': 'field2_id', 'cond': 'exists'}], 'do': 'change_fields', 'fields': [{'field1_id': None}] } ]
-
always_blank
= True¶
-
constraints
= {}¶
-
customize_types
= {}¶
-
exclude
= []¶
-
grouping
= []¶
-
help_text
= None¶
-
include
= []¶
-
title
= None¶
-
__init__
(model=None, exclude=None, include=None, types=None, title=None, **kwargs)[source]¶ Note
include and exclude does not support fields that placed in nodes.
Parameters: - model – A pyoko model instance, may be empty
- exclude ([]) – list of fields to be excluded from serialization
- include ([]) – list of fields to be included into serialization
- types (dict) – override type of fields
-
catalog_data_manager
= None¶
-
class