Package: wagtail-jsonschema-forms
Wagtail JsonSchema Forms is a simple Django app to Generate JsonSchema Forms from Wagtail’s forms and validate it.This app allows the generation of a JsonSchema form from a Wagtail’s form in order to use JsonSchema technology.
In addition, it allows you to parse the response and validate it. After the validation, the wagtail form is
submitted.For example, you can retrieve the jsonschema from through an api, then validate the submitted data and finally
submit de wagtail form.InstallationYou can install “wagtail_jsonschema_forms” viapipfromAPSL GitHub:pip install git+https://github.com/APSL/wagtail_jsonschema_forms.git#egg=wagtail_jsonschema_formsAnd then you have to addwagtail_jsonschema_formsto yourINSTALLED_APPS.Utilities providedThis app offers two python classes to generate the jsonschema and to submit the json response.JsonSchemaGeneratorThis first class has a methodwagtail_form_to_json_schemathat goes over
all the fields of the form and generate its jsonschema representation, if they are suported.Every suported field type has a method that generate the representation, which is called during the generation.
If the field is required, it will be indicated too.JsonSchemaParserThis second class provides two main methods:validate_json:method that validates the json recieved under the schema a return a dict with the possible errors.
If there are no error, a empty dict will be returned.process_form_submission:method that accepts form instance with submitted data and page and creates submission instance.
Inside of this method, another one is called to format the data submited in order to create the
submission instance.UsageAs was explained before, this django app generates jsonschema forms from Wagtail’s form and validate it.
Wagtail’s forms offers a very rich set of form field types. However, not all of them are suported on
JsonSchema and has not been covered on this app. For that reason, when you declare yourFormFieldclass on your models.py you should override the field_type field and theFORM_FIELD_CHOICESvariable:FORM_FIELD_CHOICES=(('singleline',_('Single line text')),('multiline',_('Multi-line text')),('email',_('Email')),('number',_('Number')),('url',_('URL')),('checkbox',_('Checkbox')),('dropdown',_('Drop down')),('date',_('Date')),('datetime',_('Date/time')),)field_type=models.CharField(verbose_name=_('field type'),max_length=16,choices=FORM_FIELD_CHOICES)There are two ways to use wagtail_json_schema_forms: you can choose between using the mixins or the abstract
models provided.MixinsIf you choose to use the mixins, the first thing thant you have to do is to add a newTextFieldatribute
to your wagtail form page called ‘json_schema’. This field will be used to save the JsonSchema representation
of the form.Two mixins are provided:JsonSchemaFormMixinandJsonSchemaEmailFormMixin, which inherit from the first one.JsonSchemaFormMixinoverrides the save method in order to generate the json schema before every time the
wagtail page is saved. This mixin uses the generator class explained above to prepare the jsonschema from the form.It’s also overrided the methodprocess_form_submission, where it’s checked if the form has been submited as
a usual wagtail form or using jsonschema. If jsonschema has been used for submition, the parser class is used
to register the form submission.As said, theJsonSchemaEmailFormMixininherits fromJsonSchemaFormMixin. The diference between them is in
the process of the form submission. This second mixin tries to send an email after the form submission, if theto_addressattribute of the wagtail page has been filed.Abstract ModelsAgain, there are two abstract models provided to allow to add the jsonschema functionality to a plain WagtailForm
and a EmailWagtailForm:AbstractJsonSchemaFormandAbstractJsonSchemaEmailForm.These abstract models inherit from the mixins explained above and theAbstractFormorAbstractEmailForm.
They also add the newTextFieldatribute required. Then, Wagtail Pages implementing a form that need to
generate a JsonSchema (and to send and email) should inherit from it.ContributingContributions are very welcome. Please open a pull request orfile an issue.
Tests will be ready as soon as posible, please ensure the coverage at least stays the same
before you submit a pull request.LicenseDistributed under the terms of theMITlicense, “wagtail_jsonschema_forms” is free and open source softwareIssuesIf you encounter any problems, pleasefile an issuealong with a detailed description.