#

Creating a portal app

THIS IS A LEGACY DOCUMENT LEFT HERE AS A COURTESY - PLEASE CONTACT RC BEFORE RELYING ON THIS INFORMATION IN PRODUCTION

This page describes the process for developing portal applications.

Portal apps are Django apps that work within the portal project

The RC web portal is a Django project that contains a set of common web application elements (login forms, error pages, etc.) along with a number of individual apps that provide specific functionality (e.g. submitting tickets). To make sure a new app will work with the RC portal, a number of steps must be followed.

Checkout the portal repository

You'll need a copy of the portal repository in your work environment. In order to ensure that your app will work in the proper context, you'll want to develop it within the portal project.

$ git clone git@gitint.rc.fas.harvard.edu:/var/lib/git/portal.git

Create your app as a separate repository

As you would any stand alone application, create a new git repository for your app. You code should not be managed by the portal repository. This is to avoid excessive branching during app development.

Initialize your Django app

Use the normal method for initializing a Django app so that all of your app stuff is under an app-specific directory.

$ django-admin.py startproject app4portal

By linking your app into the portal project, you'll be able to use the portal framework elements while you're developing. Don't link the entire app project into the portal, just the app directory.

$ cd portal
$ ln -s ../app4portal/app4portal .

Update the portal .gitignore file to ignore your app directory

Update and check in the .gitignore file in the root of the portal to ensure that it will skip your app directory.

Update your app settings.py file to use the *LIST variables

Django uses a number of tuples in the settings.py file to establish things like middleware, static file locations, and the set of installed apps. Because tuples are immutable, these settings cannot be dynamically set by your app. Therefore a number of lists have been setup that allow your app to modify many of these general settings; they are later converted into the tuples that Django needs. The LISTS and their corresponding tuple variable name are shown below:

LIST variable Django tuple
INSTALLED_APPS_LIST INSTALLED_APPS
STATICFILES_DIRS_LIST STATICFILES_DIRS
STATICFILES_FINDERS_LIST STATICFILES_FINDERS
TEMPLATE_LOADERS_LIST TEMPLATE_LOADERS
MIDDLEWARE_CLASSES_LIST MIDDLEWARE_CLASSES
TEMPLATE_DIRS_LIST TEMPLATE_DIRS

Add to them in your app settings.py file like so:

INSTALLED_APPS_LIST += ['rcrt']

Setup urls.py and the url_namespace variable

The master urls.py file in the portal project combines the urlpatterns that you define in your app urls.py file with a namespace identifier so that your URLs can be clearly separated from others in the portal. For example, the RC Ticket app uses "rcrt" as the namespace identifier so that "submit_ticket" URL becomes "rcrt/submit_ticket" in the portal. This is defined by setting the url_namespace variable in your urls.py file.

url_namespace = 'rcrt'

urlpatterns = patterns('rcrt.views',
url(r'tickets/$', 'tickets', name='tickets'), # rcrt/tickets
url(r'tickets/(?P<ticketid>d+)/$', 'detail', name='detail'), # rcrt/tickets/1
url(r'submit_ticket/', 'submit_ticket', name='submit_ticket'), # rcrt/submit_ticket/
url(r'submit_comment/', 'submit_comment', name='submit_comment'), # rcrt/submit_comment/
)

Add a LOGGING entry for your app

The main LOGGING dict is defined in the portal settings.py. However, you can easily add your own logger to it.

LOGGING['loggers']['rcrt'] = {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': True,
}

Import your app settings using the correct module designation

Remember that the settings file for your app is not in the project root, but rather, under the symlink you established in the portal project. As a result, using your app settings requires a correctly qualified import. Variables provided by the portal settings.py file are imported from the root file

from rcrt.settings import RT_USER
from settings import INSTALLED_APPS

Allow the portal to manage logins

The portal has forms and views established for login and logout screens. Use @login_required decorations for your views, but you don't need to create separate login forms or views.

CC BY-NC 4.0 This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. Permissions beyond the scope of this license may be available at Attribution.