Form definitions are now specified in a list instead of a dict. This preserves their order when listing the forms.

pull/7/head
Ferry Boender 9 years ago
parent 67b9405202
commit 34c9cac1a7
  1. 6
      README.md
  2. 28
      doc/MANUAL.md
  3. 10
      examples/auth/auth.json
  4. 17
      examples/output_types/output.json
  5. 10
      examples/simple/simple.json
  6. 7
      examples/validate/validate.json
  7. 5
      src/scriptform.py

@ -54,8 +54,8 @@ Form configuration file: `test_server.json`
{
"title": "Test server",
"forms": {
"add_user": {
"forms": [
"name": "add_user",
"title": "Add user",
"description": "Add a user to the htpasswd file",
"submit_title": "Add user",
@ -66,7 +66,7 @@ Form configuration file: `test_server.json`
{"name": "password2", "title": "Repeat password", "type": "password"}
]
}
}
]
}
The script `job_add_user.sh`:

@ -113,12 +113,16 @@ Structurally, they are made up of the following elements:
- **`title`**: Text to show at the top of each page. **Required**, **String**.
- **`forms`**: Dictionary where the key is the form id and the value is a
dictionary that is the definition for a single form. **Required**, **Dictionary**.
- **`forms`**: A list of dictionaries of form definitions. **Required**, **List
of dictionaries**.
- **`name`**: Name for the form. This must be unique. **Required**,
**String**, **Unique**.
- **`title`**: Title for the form. **Required**, **String**.
- **`description`**: A description of the form. May include HTML tags. **Required**, **String**.
- **`description`**: A description of the form. May include HTML tags.
**Required**, **String**.
- **`submit_title`**: The text on the submit button of the form. The
default value is '`Submit`'. **Optional**, **String**.
@ -162,8 +166,8 @@ For example, here's a form config file that contains two forms:
{
"title": "Test server",
"forms": {
"import": {
"forms": [
"name": "import",
"title": "Import data",
"description": "Import SQL into a database",
"submit_title": "Import",
@ -185,7 +189,8 @@ For example, here's a form config file that contains two forms:
}
]
},
"add_user": {
{
"name": "add_user",
"title": "Add user",
"description": "Add a user to the htaccess file or change their password",
"submit_title": "Add user",
@ -208,7 +213,7 @@ For example, here's a form config file that contains two forms:
}
]
}
}
]
}
Many more examples can be found in the `examples` directory in the source code.
@ -310,7 +315,8 @@ Scripts can have a few different output types. The output type is specified in
the **`output`** field of the form definition. For example, the following form
definition has a `raw` output type.:
"display_image" {
{
"name": "display_image",
"title": "Show an image",
"description": "Show an image",
"script: "job_display_image.sh",
@ -415,8 +421,8 @@ view the form 'only_some_users'.
"test": "2bb80d537b1da3e38bd30361aa855686bde0eacd7162fef6a25fe97bf527a25b",
"test2": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8"
},
"forms": {
"only_some_users": {
"forms": [
"name": "only_some_users",
"title": "Only some users",
"description": "You should only see this if you're user 'test2'",
"submit_title": "Do nothing",
@ -424,7 +430,7 @@ view the form 'only_some_users'.
"allowed_users": ["test2"],
"fields": []
}
}
]
}
### <a name="users_passwords">Passwords</a>

@ -4,8 +4,9 @@
"test": "2bb80d537b1da3e38bd30361aa855686bde0eacd7162fef6a25fe97bf527a25b",
"test2": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8"
},
"forms": {
"do_nothing": {
"forms": [
{
"name": "do_nothing",
"title": "Test form",
"description": "You should only see this if you've entered the correct password",
"submit_title": "Do nothing",
@ -13,7 +14,8 @@
"fields": [
]
},
"only_some_users": {
{
"name": "only_some_users",
"title": "Only some users",
"description": "You should only see this if you're user 'test2'",
"submit_title": "Do nothing",
@ -22,5 +24,5 @@
"fields": [
]
}
}
]
}

@ -1,7 +1,8 @@
{
"title": "Output type callback examples",
"forms": {
"show_image": {
"forms": [
{
"name": "show_image",
"title": "Show an image",
"description": "Shows you an image. This is a 'raw' output type where the script writes a complete HTTP response to stdout, which is directly streamed to the browser by scriptform.",
"submit_title": "Show",
@ -9,7 +10,8 @@
"output": "raw",
"fields": {}
},
"large_bin": {
{
"name": "large_bin",
"title": "Download large binary file",
"description": "Download a large (100mb) binary file. This demonstrated streaming directly to the client of large files.",
"submit_title": "Download",
@ -17,7 +19,8 @@
"output": "raw",
"fields": {}
},
"some_html": {
{
"name": "some_html",
"title": "Show some HTML",
"description": "This is the 'html' output type, which allows HTML in the output of scripts. This can be useful to refer to another form after this form is completed, for instance.",
"submit_title": "Show HTML",
@ -25,7 +28,8 @@
"output": "html",
"fields": {}
},
"escaped": {
{
"name": "escaped",
"title": "Escaped contents (default)",
"description": "This is the 'escaped' output type. It is the default. The HTML entities in the output are escaped properly, and is wrapped in PRE elements.",
"submit_title": "Show HTML",
@ -33,6 +37,5 @@
"output": "escaped",
"fields": {}
}
}
]
}

@ -1,7 +1,8 @@
{
"title": "Test server",
"forms": {
"import": {
"forms": [
{
"name": "import",
"title": "Import data",
"description": "Import SQL into a database",
"submit_title": "Import",
@ -23,7 +24,8 @@
}
]
},
"add_user": {
{
"name": "add_user",
"title": "Add user",
"description": "Add a user to the htaccess file or change their password",
"submit_title": "Add user",
@ -46,5 +48,5 @@
}
]
}
}
]
}

@ -1,7 +1,8 @@
{
"title": "Validation example",
"forms": {
"validate": {
"forms": [
{
"name": "validate",
"title": "Validated form",
"description": "This form is heavily validated",
"submit_title": "Validate it",
@ -76,5 +77,5 @@
}
]
}
}
]
}

@ -7,7 +7,7 @@
# - Default values for input fields.
# - If there are errors in the form, its values are empties.
# - Send responses using self.send_ if possible
# - Complain about no registered callback on startup instead of serving.
# - Maintain order of forms in form configuration.
import sys
import optparse
@ -190,7 +190,8 @@ class ScriptForm:
if 'users' in config:
users = config['users']
for form_name, form in config['forms'].items():
for form in config['forms']:
form_name = form['name']
if 'script' in form:
script = os.path.join(self.basepath, form['script'])
else:

Loading…
Cancel
Save