crits/crits — pull request #109 by mgoffin (2014-06-19 18:58:44+00:00)
Title: Allow for custom service runtime forms.

Runtime forms were always based on the configuration options provided
for the Control Panel. This change allows you to fully customize the
service runtime form, including having your own template so you can
include javascript and such to make the form more interactive.

If you wish to leverage this capability, your service now needs to have
a "generate_runtime_form()" which should take the following as
arguments:

- self
- analyst
- name
- crits_type
- identifier

You don't need to use any of that information if it's not necessary, but
it will be passed along by services (for the time being). This function
needs to return two things:

- a Django form object
- HTML of the rendered form

The former can be None if there is no Django-style form to generate. The
latter should be the rendered HTML form (you can use render_to_string()
with your own custom form template). If you want your own template,
create it in the "templates" directory of your service, give it a unique
name, and reference it appropriately in your function.

If you want to test this out, I did the following:

* copy `services_run_form.html` to `pyew/templates/pyew_run_form.html`for the Pyew service.
* edit the `pyew_run_form.html` file and change `form.as_table` to `form`
* add the following method to the Service class in `pyew/__init__.py`:

```python
def generate_runtime_form(self, analyst, name, crits_type, identifier):
form = render_to_string("pyew_run_form.html",
{'form': "

This is a form!

",
'name': name,
'crits_type': crits_type,
'identifier': identifier})
return None, form
```

Once you restart your web server (or run server) you should be able to go to any Sample, and on the Analysis tab click on "Pyew". Normally it wouldn't do anything, but with these changes you should get a form popup that says "This is a form!".