Skip to content

How to create a new integrated application

ilyakh edited this page Dec 7, 2012 · 9 revisions

When the installation is complete, there is a choice either to work on a part of the existing code base, or to create your own isolated application that can be merged into the code base once stable. If you go for the latter, and decide to call your application devilry_component do following:

  1. ./src/

    1. Create the folder structure for your application (remember to replace the name):
      1. create folder ./src/devilry_component/devilry_component
      2. create folder ./src/devilry_component/devilry_component/static/
      3. create folder ./src/devilry_component/devilry_component/templates/
  2. ./src/devilry_component/devilry_component/ (easilly done with touch-command)

    1. create __init__.py
    2. create urls.py
    3. create models.py

The purpose of this folder structure is to force django to recognize it as a python module and a django application. Later, you can add all necessary files for it to function properly.

The next step is to integrate the application into devilry:

  1. ./buildout_base.cfg

    1. Under [eggs] add devilry_component at the same indent-level as other names
    2. Under [sources] devilry_component = fs devilry_component (fs prefix tells buildout to fetch the source from the filesystem)
  2. ./devenv/settings/default_settings.py

    1. add devilry_component to INSTALLED_APPS
  3. ./devenv/settings/deafult_urls.py

    1. make (r'^devilry_component/', include('devilry_component.urls')), a part of the tuple devilry_urls. (don't forget the comma after the last element!)

When the last step is complete, your application will be a formal component of devilry.

  1. ./devenv/

    1. run ./bin/buildout-command
    2. if you have added the models to model models.py: run django_dev.py syncdb
    3. if you have added static files: run django_dev.py collectstatic -l (drop the -l-parameter on windows)
  2. Run ./devenv/bin/django_dev.py runserver

Your application is live on http://localhost:8000/devilry_component/ Set up a minimal version of urls.py for your application:

  1. ./src/devilry_component/devilry_component/urls.py
  2. ./src/devilry_componen/setup.py
  3. ./src/devilry_componen/README.rst
# -*- coding: utf-8 -*-

from django.conf.urls.defaults import patterns, include, url
from django.contrib.auth.decorators import login_required
from django.views.i18n import javascript_catalog
from django.views.decorators.csrf import csrf_protect, ensure_csrf_cookie

from devilry_settings.i18n import get_javascript_catalog_packages
from .views import AppView


i18n_packages = get_javascript_catalog_packages(
    'devilry_stats', 'devilry_header', 'devilry_extjsextras', 'devilry.apps.core'
)


@login_required
def emptyview(request):
    from django.http import HttpResponse
    return HttpResponse('Logged in')


urlpatterns = patterns('devilry_stats',
                       url('^emptytestview', emptyview), # NOTE: Only used for testing
                )

Move onto developing your ReST API or the Ext.js part of the application in the static-folder and don't forget to check the errors in the javascript console!

Clone this wiki locally