-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the ability to create an arbitrary schema for rendering elsewhere #403
base: master
Are you sure you want to change the base?
Changes from 1 commit
5615c49
6654fe6
49ebdc2
54bf426
507efcd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
scheming_version: 2 | ||
schema_id: ckanext_notifier | ||
about: An example of a config schema for a fictional extension | ||
|
||
fields: | ||
- field_name: ckanext.ckanext_notifier.enable_notifications | ||
label: Enable notifications | ||
validators: default(true) boolean_validator | ||
preset: select | ||
required: true | ||
choices: | ||
- value: true | ||
label: Enable | ||
- value: false | ||
label: Disable | ||
|
||
- field_name: ckanext.ckanext_notifier.notify_to_email | ||
label: Notification email | ||
validators: unicode_safe email_validator | ||
required: true | ||
help_text: Specify the email address to which the notification will be sent | ||
|
||
- field_name: ckanext.ckanext_notifier.frequency | ||
label: Notification frequency in seconds | ||
validators: default(3600) int_validator | ||
required: true | ||
input_type: number |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{#} | ||
fields - a list of scheming field dictionaries | ||
data - form data fields | ||
errors - A dict of errors for the fields | ||
entity_type - entity type | ||
object_type - object type | ||
set_fields_defaults - flag to set the default field values | ||
{#} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is cute but doing comments like this could lead to confusion about where the comment starts and ends There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
|
||
{% for field in fields if field.form_snippet is not none %} | ||
{% if field.field_name not in data and set_fields_defaults %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the other templates are indented with 2 spaces. Better to be consistent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, thanks |
||
{# Set the field default value before rendering but only if | ||
it doesn't already exist in data which would mean the form | ||
has been submitted. #} | ||
{% if field.default_jinja2 %} | ||
{% do data.__setitem__(field.field_name, h.scheming_render_from_string(field.default_jinja2)) %} | ||
{% elif field.default %} | ||
{% do data.__setitem__(field.field_name, field.default) %} | ||
{% endif %} | ||
{% endif %} | ||
|
||
{% snippet 'scheming/snippets/form_field.html', | ||
field=field, | ||
data=data, | ||
errors=errors, | ||
licenses=licenses, | ||
entity_type=entity_type, | ||
object_type=object_type | ||
%} | ||
{% endfor %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import pytest | ||
from flask import render_template | ||
from bs4 import BeautifulSoup | ||
|
||
from ckanext.scheming.helpers import scheming_get_arbitrary_schema | ||
|
||
|
||
class TestArbitrarySchema: | ||
def test_arbitrary_schema_structure(self): | ||
schema = scheming_get_arbitrary_schema("ckanext_notifier") | ||
|
||
assert schema["scheming_version"] | ||
assert schema["schema_id"] == "ckanext_notifier" | ||
assert schema["about"] | ||
assert isinstance(schema["fields"], list) | ||
|
||
@pytest.mark.usefixtures("with_request_context") | ||
def test_render_arbitrary_schema(self, app): | ||
schema = scheming_get_arbitrary_schema("ckanext_notifier") | ||
|
||
result = render_template( | ||
"scheming/snippets/render_fields.html", | ||
fields=schema["fields"], | ||
data={}, | ||
errors={}, | ||
) | ||
|
||
soup = BeautifulSoup(result) | ||
|
||
assert len(soup.select("div.form-group")) == 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like licenses isn't passed through here or in the resource_form
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed