Creating a fresh application
For the purpose of this we will create a demographics application with data collection as done is USA.
The end result is available at http://github.com/dreaswar/Au-Pluggables
After activating the virtual environment run
$ python manage.py startapp aushadha_demographics_us --template AuShadha/app_template
This will generate the application scaffold and populate it with basic import stubs. The folder structure will be as described in the PART 1.
1. Creating the model, views and urls.py
The models will be derived based on the US Demographics requirements here: Demographics
The model class inherits from AuShadhaBaseModel and the model form class will inherit from AuShadhaBaseModelForm class, which gives them some useful methods which they inherit.
Additionally, the AuShadhaModelForm class generates Dijits for display. The Dijits have to be configured in the dijit_widgets_constants.py file which is a python dictionary. This is will give the necessary Dijit declarative directives for generating the form widgets.
Once the models are done, the views and urls.py have nothing AuShadha specific about them. Basically we need views to add, edit, delete, view, json export the objects. The same can be represented in the urls.py
2. Determining the registration of roles
The aushadha.py file registers the role of a particular class in the application. Roles are purely arbitrarily made up by the developer. However, if he needs to register a class for a particualr role that has already been registered, he will need to use the same name so as to override the preexisting class.
For eg> a PatientRegistration model may do the role of Patient Registration in the application. Hence this can be registered for that role. AuShadhaUI class generates an instance per server run and this registers the classes for a particular role on startup.
Registration can be accomplished inside aushadha.py as
UI.register(<class_name>, <role_name_as_string> )
3. Finalise the UI layout with PyYAML
Earlier in AuShadha developement, Django Template with HTML, CSS, and JS was used to generate the layout. This sometimes requires extensive Dijit declarative HTML markup that was not easy on the eye. Additionally interspersed JS and CSS didnt help.
The required PyYAML file is located in the dijit_widgets directory. The pane.yaml and pane.py creates the necessary JSON
PyYAML directives are almost the same as Dijit declarative HTML markup except for the quotations and angled bracket distractions. I will devout an entire tutorial on this and how the JS file parses this. This is very early in AuShadha development so the markup, directive may change, but the principle is the same.
4. Study need for additional JS files
The add-on modules will have a media directory with sub-directories of js, styles, images to house modules of JS, CSS and images. Dojo has the new AMD loader that encourages modular design and the dojoConfig variable can be changed at runtime allowing full flexibility to add modules as needed. This is demonstrated by the grids in the application (Contact, Phone and Guardian grid). The relevent module that should be called by the loader is specified in the pane.yaml under the grid directives as gridStrModule.
5. Integerate or install the application
The application itself needs to be added to the INSTALLED_APPS. Integrating the application (or installing ) requires changes in the settings.py to set the paths for templates, scripts, styles and media. The Root urls.py needs to include the application as well. After the settings are done run syncdb to install the changes.
In case of Stock modules that clash with add-on modules, the stock modules will have to be removed, changes made to settings.py and urls.py to reflect this. This has to be done before syncdb is done.
The fully developed application for US demographics collection is at http://github.com/dreaswar/Au-Pluggables
Part 3 will deal with PyYAML and auto building the Dijit UI Widgets with PyYAML and Dojo