Comments (11)
I'll take a look tomorrow, but I imagine so.
from django-fobi.
Started on this at https://github.com/Psykar/django-fobi/tree/feature/drf_json_schema
Unfortunately (for my work on this at least) the project I'm on has decided they're OK editing the json schema by hand. Personally this makes me a little happier and my work easier, but I likely won't have the time to complete this work, so if that WIP commit is useful as a starting point *shrug
from django-fobi.
I pulled your changes into drf-json-schema branch, where I'll work on it further.
Thanks!
from django-fobi.
Out of curiosity, why isn't the OPTIONS method just returning the same as the json export of a form?
from django-fobi.
Scratch that... kind of.
Seems we get the metadata via OPTIONS
but the initial data via GET
Fair I suppose, although vaguely annoying having to do two HTTP requests.
Exposing the json export of a form on the API somehow would be awesome still though.
from django-fobi.
You're totally right. That's what I was thinking of within the last couple of days (as I'm busy studying React at the moment; there are plans to write a react-integration app).
What you want is quite simple and is definitely gonna land in fobi soon (like, in a week of time) along with other useful information (such as max_value, min_value and even things like placeholders are planned to be covered) - all of that will become available in OPTIONS.
from django-fobi.
from django-fobi.
Fine. I was planning to use JSON schema for it, but didn't dive into it yet. Since you're doing that anyway, it would be great if you could write an overview of all meta-data that should land in the OPTIONS; per plugin.
Presentational fields
- content_image
- content_image_url
- content_text
- content_video
Form fields
- boolean
- checkbox_select_multiple
- date
- date_drop_down
- datetime
- decimal
- file
- float
- hidden (in terms of the Django REST framework - a read-only field)
- input (some sort of a copy of
text
plugin) - integer
- ip_address
- null_boolean
- password (some sort of a copy of
text
plugin) - radio
- range_select
- regex
- select
- select_multiple
- select_multiple_with_max
- slider (just a copy of range_select, for compatibility with main package)
- slug
- text
- textarea (some sort of a copy of
text
plugin) - time
- url
Could you do that?
from django-fobi.
Initial solution been implemented in 0.11.12.
See the test DRF form and same form in DRF integration app with most of the fields that do have additional metadata.
OPTIONS call produces the following response:
OPTIONS /api/fobi-form-entry/test-drf-form/
HTTP 200 OK
Allow: GET, PUT, PATCH, OPTIONS
Content-Type: application/json
Vary: Accept
{
"name": "Fobi Form Entry Instance",
"description": "FormEntry view set.",
"renders": [
"application/json",
"text/html"
],
"parses": [
"application/json",
"application/x-www-form-urlencoded",
"multipart/form-data"
],
"actions": {
"PUT": {
"test_integer": {
"type": "integer",
"required": false,
"read_only": false,
"label": "Test integer",
"min_value": 1,
"max_value": 20,
"initial": 10
},
"test_email": {
"type": "email",
"required": true,
"read_only": false,
"label": "Test email",
"help_text": "Donec mollis hendrerit risus. Phasellus a est. Nam ipsum risus, rutrum vitae, vestibulum eu, molestie vel, lacus. Praesent nec nisl a purus blandit viverra. Cras id dui.",
"max_length": 255,
"placeholder": "[email protected]"
},
"test_text": {
"type": "string",
"required": false,
"read_only": false,
"label": "Test text",
"help_text": "Sed lectus. Phasellus gravida semper nisi. Curabitur at lacus ac velit ornare lobortis. Mauris turpis nunc, blandit et, volutpat molestie, porta ut, ligula. Lorem ipsum dolor sit amet, consectetuer adipiscing elit.",
"max_length": 255,
"placeholder": "Lorem ipsum dolor sit amet"
},
"test_url": {
"type": "url",
"required": false,
"read_only": false,
"label": "Test URL",
"max_length": 255,
"initial": "http://github.com"
},
"test_decimal_field": {
"type": "decimal",
"required": false,
"read_only": false,
"label": "Test decimal field",
"min_value": 1.0,
"max_value": 25.0,
"initial": 10.0,
"placeholder": "3.14",
"max_digits": 5,
"decimal_places": 2
},
"test_float_field": {
"type": "float",
"required": false,
"read_only": false,
"label": "Test float field",
"min_value": 1.0,
"max_value": 10.0,
"initial": 3.14
},
"test_ip_address": {
"type": "string",
"required": false,
"read_only": false,
"label": "Test IP address",
"max_length": 255,
"placeholder": "127,0.0.1"
},
"test_password_field": {
"type": "string",
"required": false,
"read_only": false,
"label": "Test password field",
"max_length": 255,
"placeholder": "your-secret-password"
},
"test_regex_field": {
"type": "regex",
"required": false,
"read_only": false,
"label": "Test regex field",
"max_length": 255,
"regex": "^([a-zA-Z])+$"
},
"test_slug_field": {
"type": "slug",
"required": false,
"read_only": false,
"label": "Test slug field",
"max_length": 255,
"placeholder": "lorem-ipsum-dolor-sit-amet"
},
"test_textarea_field": {
"type": "string",
"required": false,
"read_only": false,
"label": "Test textarea field",
"placeholder": "Pellentesque habitant morbi tristique."
},
"test_input_field": {
"type": "string",
"required": false,
"read_only": true,
"label": "Test input field",
"max_length": 255,
"autofocus": "autofocus",
"autocomplete": "on",
"disabled": "disabled"
},
"content_image_url_b0996b16-9f1c-430d-a6c7-0a722f4c2177": {
"type": "content",
"required": false,
"read_only": true,
"initial": "\n <p>\n \n <img src=\"http://delusionalinsanity.com/foreverchild.for.cats/uploads/gallery/2012-11-22-9-1-22.jpg\" alt=\"n.n.\" width=\"600\"/>\n \n </p>\n",
"contenttype": "image",
"raw_data": {
"url": "http://delusionalinsanity.com/foreverchild.for.cats/uploads/gallery/2012-11-22-9-1-22.jpg",
"alt": "n.n.",
"fit_method": "fit_width",
"size": "600x600"
},
"content": "\n <p>\n \n <img src=\"http://delusionalinsanity.com/foreverchild.for.cats/uploads/gallery/2012-11-22-9-1-22.jpg\" alt=\"n.n.\" width=\"600\"/>\n \n </p>\n"
},
"content_text_de4d69b2-99e1-479d-8c61-1534dea7c981": {
"type": "content",
"required": false,
"read_only": true,
"initial": "<p>Pellentesque posuere. Quisque id mi. Duis arcu tortor, suscipit eget, imperdiet nec, imperdiet iaculis, ipsum. Phasellus a est. In turpis.</p>",
"contenttype": "text",
"raw_data": {
"text": "Pellentesque posuere. Quisque id mi. Duis arcu tortor, suscipit eget, imperdiet nec, imperdiet iaculis, ipsum. Phasellus a est. In turpis."
},
"content": "<p>Pellentesque posuere. Quisque id mi. Duis arcu tortor, suscipit eget, imperdiet nec, imperdiet iaculis, ipsum. Phasellus a est. In turpis.</p>"
},
"content_video_f4799aca-9a0b-4f1a-8069-dda611858ef4": {
"type": "content",
"required": false,
"read_only": true,
"initial": "\n <iframe src=\"//www.youtube.com/embed/8GVIui0JK0M\" width=\"500\" height=\"400\" frameborder=\"0\" allowfullscreen></iframe>\n ",
"contenttype": "video",
"raw_data": {
"title": "Delusional Insanity - To far beyond...",
"url": "https://www.youtube.com/watch?v=8GVIui0JK0M&t=1s",
"size": "500x400"
},
"content": "\n <iframe src=\"//www.youtube.com/embed/8GVIui0JK0M\" width=\"500\" height=\"400\" frameborder=\"0\" allowfullscreen></iframe>\n "
}
}
}
}
Some insights:
Meta-data is passed to the DRFIntegrationFormElementPluginProcessor
as field_metadata
argument, which is supposed to be a dict.
I have checked the JSON schema.
See the sample below.
{
"$schema": "http://json-schema.org/draft-04/schema#",
"additionalProperties": true,
"definitions": {},
"id": "http://example.com/example.json",
"properties": {
"checked": {
"default": false,
"description": "An explanation about the purpose of this instance.",
"id": "/properties/checked",
"title": "The Checked Schema",
"type": "boolean"
},
"id": {
"default": 1,
"description": "An explanation about the purpose of this instance.",
"exclusiveMaximum": false,
"exclusiveMinimum": false,
"id": "/properties/id",
"maximum": 300,
"minimum": 50,
"title": "The Id Schema",
"type": "integer"
},
"name": {
"default": "A green door",
"description": "An explanation about the purpose of this instance.",
"id": "/properties/name",
"maxLength": 200,
"minLength": 10,
"title": "The Name Schema",
"type": "string"
},
"price": {
"default": 12.5,
"description": "An explanation about the purpose of this instance.",
"exclusiveMaximum": false,
"exclusiveMinimum": false,
"id": "/properties/price",
"maximum": 300,
"minimum": 50,
"title": "The Price Schema",
"type": "number"
},
"tags": {
"additionalItems": true,
"id": "/properties/tags",
"items": {
"default": "home",
"description": "An explanation about the purpose of this instance.",
"id": "/properties/tags/items",
"maxLength": 200,
"minLength": 10,
"title": "The Empty Schema",
"type": "string"
},
"type": "array",
"uniqueItems": false
}
},
"required": [
"price",
"tags",
"checked",
"id",
"name"
],
"type": "object"
}
I think it might make sense to keep things as they are, but I do want to support JSON schema as well. At the moment, how I see it, the best approach would be to make an alternative FobiJSONSchemaMetaData
class here and let devs choose which one they want.
Would you be interested to work on that part? Pull requests are welcome.
from django-fobi.
Yeah, that's definitely useful.
-
100% complete meta-data in OPTIONS call.
-
Support JSON schema in OPTIONS call (make it configurable so that devs can choose whether to use classical metadata or JSON schema metadata).
from django-fobi.
I've just synced the drf-json-schema branch with master. Any work on this shall be done there. Your help is highly appreciated.
from django-fobi.
Related Issues (20)
- Migrate to GitHub actions HOT 1
- is the project still maintained ? HOT 1
- missing locale HOT 1
- Support Django 4.0 HOT 2
- Input field desabled HOT 14
- Consolidate docs
- can only concatenate list (not "tuple") to list on python 3.10.6 and django 4.1 HOT 2
- Django 4.1 support HOT 6
- securing file uploads HOT 2
- Add DRF views for viewing submitted form data
- Class based view dashboard can be reached by anonymous HOT 3
- example data/migrations missing in quickstart and no demo site HOT 1
- The live demo is not working HOT 1
- Checkbox (select multiple) rendered incorrectly from form creation page HOT 13
- FileMultiple field HOT 1
- email and email confirm HOT 21
- RTL support HOT 3
- Bootstrap5 support HOT 4
- It seems to read a form name and form elements I need to make 2 API calls: one OPTIONS and one GET
- Is this project still active ? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-fobi.