Skip to content

Creating Application

Alexander Makeev edited this page Jun 24, 2013 · 4 revisions

<< Back

To start adapting PyCDB for specific facility or software you need to create new django application. It is recomended to create one django application for one facility being configured. For example, LIA acceleration facility needs one django application called, for example, lia_tools, that contain all needed GUI tools and export scripts.

1. Creating django application

1.1. Create a folder in root PyCDB path (near such applications as portal and graph_db), named, for example, facility_tools

1.2. Make it a python lib by adding empty __init__.py file to application folder.

1.3. Register application to PyCDB configuration. Go to conf/local_[installation_name].py and add value to INSTALL_APPS list:

common.INSTALLED_APPS += [
    'facility_tools'
]

2. Creating urls mapping

2.1. Create urls file by adding urls.py file to it. The content is a list of views mapped to the URLs, the list will be empty for now:

from django.conf.urls.defaults import patterns, include, url

urlpatterns = patterns('',
##########################################
# URLs mappings will be here:
#    url(r'^facility$', 'facility_tools.devices_connector.index', name="facility-devices-connector"),
##########################################
)

2.2. Install urls.py to root urls.py. Add mapping pattern to process application urls.py file to PyCDB root urls.py file:

...
urlpatterns = patterns('',
    ...
    url(r'^facility/', include('facility.urls')),
)

3. Creating menu tree

3.1. Create menu file by adding menu.py file to application folder. The content of it is a tree of menu items, the tree will be empty for now:

from django.core.urlresolvers import reverse

MENU_ITEMS = [
##########################################
# MENU items will be here:
#    {
#        "title" : "Facility",
#        "url" : reverse("index"),
#        "subitems" : [
#            {
#                "title" : "Devices Connector",
#                "url" : reverse("facility-devices-connector")
#            }
#        ]
#    }
##########################################
]

3.2. Register menu in PyCDB configuration. Go to conf/local_[installation_name].py and add value to MENU_SOURCES list:

common.MENU_SOURCES += [
    "facility_tools.menu.MENU_ITEMS",
    ...
]

Optionally you could create:

  • templates folder to store html and text templates that you want to use in your GUI or export scripts. Remember, that all templates folders are being merged by django. So, to prevent templates names collisions use templates sub-folder named as your application (templates/facility_tools).
  • static folder to store css, js or other static data needed by GUI. This folder is also being merged by django, see templates point above.
  • For full django documentation use this: Django DOCs

Clone this wiki locally