UI Best Practices
the best practices for openplans ui design
- Alphabet Search Widget
- Searching using Advanced Query
- List Pagination
String InterpolationUse string interpolation over adding strings:
"%s/%s" %(name, name)
name + "/" + name
is better than:
python: obj.absolute_url() + "/viewname"
1. define a form in a template. do the following::
at the top::
define="global fdata view/handle_request;">
This could be used to return a variety of template friendly info
regarding the processing of the form
for the form action, have it submit back to itself::
<form name="create_form" method="post" class="enableUnloadProtection"
for the submit button, make it look something like this::
2. define a view class that looks like this::
from opencore.nui.base import BaseView, button
"""an abstract base"""
# do form submit stuff
3. Bind your class to your template in zcml
How does it work?
It's braindead as can be. 'button' merely causes handle_request to be skipped if 'add' is not in the request. the template always calls handle_request. the view class defines handle_request. Only one view is declared and all requests go through it. if we need multiple button dispatch, we probably should bite the formlib bullet for actions (ie ignore the form generation stuff except for the naming conventions).
Forms should submit to themselves
It's a general principle(as well as the default action for a form) mainly for POST forms. and generally, the pattern makes things simpler:
render form and errors
Normally, rendering the form will be the same template logic and submission would be required again on error. Redirect only occurs when any business concerning the form is done. The browser then can maintain state for form, back button works, etc. REST principles dictate you have one location for actions effecting the state of a site and separate urls for viewing results.
The search forms are a bit different, since the initial search takes you to a searching page. Eventually, this would be an internalized version of the same pattern as above, but using ajax to render and submit. Currently, it bounces you away(which is ok but not great). GET requests are better for this sort of stuff, because they can be bookmarked (ala results)