Create Sadj Project Example use for the sadjadmin script.

The Sadj distribution comes with a utility to quickly generate a new Sadj project, with a frame and a menu structure of your choice. You can then use this as your new application start-point.

The examples below use the sadjadmin.py utility script located in the /scripts folder.

Basic Example

Run the script from the command line, passing the name of the project you want to create, for example:

./scripts/sadjadmin.py -a createproject -n apple

This will create a new folder named apple in the current folder, and populate it with a new Sadj project. You can test the new project was created correctly by running Django with the usual python manage.py runserver command from the new folder.

You can then access the main http://127.0.0.1:8000/ url, which should display something like the screenshot shown. The default menu structure is two submenus each with five menu items, all using a default template page, containing a basic container layout to help get your new application pages started.

Sadj new project

Project Architecture

By default the script will create an outline multi-page application. You can control the type of project created with two optional arguments:

  • -s or --spa - if this argument is present, create an outline single-page application; otherwise, create a multi-page application
  • -m or --mixed - create a mixed-mode (SPA and MPA) project. If this is specified, the --spa argument is ignored

A mixed project will contain both 'spa' and 'mpa' Django apps with the top-level page templates, which include the content from shared 'sabase' or 'sadjdemo' apps as required.

If the project is not mixed, it will contain either an 'mpa' or 'spa' app, which will hold both the page-wrapper and content templates.

Specifying the Menu

You can set up nested menus, using content from the SmartAdmin base Django app and the Sadj demo app, in any combination you wish, as the following examples illustrate. This is controlled by a series of '-p' or '--page' arguments; you can supply as many as you wish.

Page arguments should be of the form app.page:page_name, or app.page:page_name*5 for 5 copies, where 'ap' is 'sa' for SmartAdmin pges, and 'demo' for Sadj demo pages. Alternatively, if you supply a single string, a blank page template is used and the string used as the page name.

Submenus can be specified by wrapping multiple page entries in brackets, separated by semicolons, and preceded by the menu name, like this: menu_name(app.page:page_name;app.page:page_name)

Examples

Example: to create a new multi-page-app project called 'mango' with blank pages called 'home' and 'about':

sadjadmin.py -n 'mango' -p 'home' 'about'

Example: to create a project with the 'live_charts' page from the demo app copied across twice and given two different names:

sadjadmin.py -n 'pear' -p 'demo.charts:live_charts' 'demo.live:live_charts2'

Example: to create a project with five renamed pages from the demo app:

sadjadmin.py -n 'orange' -p 'demo.charts:live_charts*5'

Example: to create a project with two submenus of five blank templates each (i.e. the script default):

sadjadmin.py -n 'plum' -p 'submenu1(plum_page*5)' 'submenu2(plum_page*5)'

Example: to create a project with blank pages called 'home' and 'about' and additional specific SmartAdmin pages:

sadjadmin.py -n 'kiwi' -p 'home' 'about' 'sa.ui_modal:modal' 'sa.ui_navbars:navbars'

Other Script Arguments

Further control over the script operation is given by:

  • -l, --location - directory in which to create the new project
  • -v, --verbosity - increase output verbosity, set as -v, -vv etc.
  • -fr FRAME, --frame - application frame choice: full or slim. If 'full', the SmartAdmin demo frame is used, which you can then cut back as you wish for your application. If 'slim' (the default), a much smaller frame is used, with the main menu and a basic header and footer, to which you can add as required. Most applications are best built by adding to the slim frame.

Running the script

You may wish to just run this script directly from the command line, but in line with Python best practice it is recommended that you use a virtual environment of your choice. Below are sample commands to create and use a virtualenv in a folder named 'venv' within the Sadj distribution on Linux, assuming you are starting in the distribution root folder:

  • python -m venv ./venv - create a virtualenv
  • source ./venv/bin/activate - activate the virtualenv
  • pip install -r ./scripts/requirements.txt - install argparse, django
  • ./scripts/sadjadmin.py -h - diplay help.