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 10 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", "title": "Test server",
"forms": { "forms": [
"add_user": { "name": "add_user",
"title": "Add user", "title": "Add user",
"description": "Add a user to the htpasswd file", "description": "Add a user to the htpasswd file",
"submit_title": "Add user", "submit_title": "Add user",
@ -66,7 +66,7 @@ Form configuration file: `test_server.json`
{"name": "password2", "title": "Repeat password", "type": "password"} {"name": "password2", "title": "Repeat password", "type": "password"}
] ]
} }
} ]
} }
The script `job_add_user.sh`: 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**. - **`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 - **`forms`**: A list of dictionaries of form definitions. **Required**, **List
dictionary that is the definition for a single form. **Required**, **Dictionary**. of dictionaries**.
- **`name`**: Name for the form. This must be unique. **Required**,
**String**, **Unique**.
- **`title`**: Title for the form. **Required**, **String**. - **`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 - **`submit_title`**: The text on the submit button of the form. The
default value is '`Submit`'. **Optional**, **String**. 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", "title": "Test server",
"forms": { "forms": [
"import": { "name": "import",
"title": "Import data", "title": "Import data",
"description": "Import SQL into a database", "description": "Import SQL into a database",
"submit_title": "Import", "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", "title": "Add user",
"description": "Add a user to the htaccess file or change their password", "description": "Add a user to the htaccess file or change their password",
"submit_title": "Add user", "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. 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 the **`output`** field of the form definition. For example, the following form
definition has a `raw` output type.: definition has a `raw` output type.:
"display_image" { {
"name": "display_image",
"title": "Show an image", "title": "Show an image",
"description": "Show an image", "description": "Show an image",
"script: "job_display_image.sh", "script: "job_display_image.sh",
@ -415,8 +421,8 @@ view the form 'only_some_users'.
"test": "2bb80d537b1da3e38bd30361aa855686bde0eacd7162fef6a25fe97bf527a25b", "test": "2bb80d537b1da3e38bd30361aa855686bde0eacd7162fef6a25fe97bf527a25b",
"test2": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8" "test2": "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8"
}, },
"forms": { "forms": [
"only_some_users": { "name": "only_some_users",
"title": "Only some users", "title": "Only some users",
"description": "You should only see this if you're user 'test2'", "description": "You should only see this if you're user 'test2'",
"submit_title": "Do nothing", "submit_title": "Do nothing",
@ -424,7 +430,7 @@ view the form 'only_some_users'.
"allowed_users": ["test2"], "allowed_users": ["test2"],
"fields": [] "fields": []
} }
} ]
} }
### <a name="users_passwords">Passwords</a> ### <a name="users_passwords">Passwords</a>

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

@ -1,7 +1,8 @@
{ {
"title": "Output type callback examples", "title": "Output type callback examples",
"forms": { "forms": [
"show_image": { {
"name": "show_image",
"title": "Show an 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.", "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", "submit_title": "Show",
@ -9,7 +10,8 @@
"output": "raw", "output": "raw",
"fields": {} "fields": {}
}, },
"large_bin": { {
"name": "large_bin",
"title": "Download large binary file", "title": "Download large binary file",
"description": "Download a large (100mb) binary file. This demonstrated streaming directly to the client of large files.", "description": "Download a large (100mb) binary file. This demonstrated streaming directly to the client of large files.",
"submit_title": "Download", "submit_title": "Download",
@ -17,7 +19,8 @@
"output": "raw", "output": "raw",
"fields": {} "fields": {}
}, },
"some_html": { {
"name": "some_html",
"title": "Show 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.", "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", "submit_title": "Show HTML",
@ -25,7 +28,8 @@
"output": "html", "output": "html",
"fields": {} "fields": {}
}, },
"escaped": { {
"name": "escaped",
"title": "Escaped contents (default)", "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.", "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", "submit_title": "Show HTML",
@ -33,6 +37,5 @@
"output": "escaped", "output": "escaped",
"fields": {} "fields": {}
} }
]
}
} }

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

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

@ -7,7 +7,7 @@
# - Default values for input fields. # - Default values for input fields.
# - If there are errors in the form, its values are empties. # - If there are errors in the form, its values are empties.
# - Send responses using self.send_ if possible # - 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 sys
import optparse import optparse
@ -190,7 +190,8 @@ class ScriptForm:
if 'users' in config: if 'users' in config:
users = config['users'] users = config['users']
for form_name, form in config['forms'].items(): for form in config['forms']:
form_name = form['name']
if 'script' in form: if 'script' in form:
script = os.path.join(self.basepath, form['script']) script = os.path.join(self.basepath, form['script'])
else: else:

Loading…
Cancel
Save