Sample Configuration

This is a sample configuration to get you started. It should contain all you need to create a basic set-up.

Newfies-Dialer configuration file is by default located at /usr/share/newfies-dialer/newfies_dialer/

The Configuration Module

Some of the more important parts of the configuration module for the Newfies,, are explained below:

import os.path
APPLICATION_DIR = os.path.dirname(globals()['__file__'])

APPLICATION_DIR now contains the full path of your project folder and can be used elsewhere in the module so that your project may be moved around the system without you having to worry about changing any troublesome hard-coded paths.

DEBUG = True

turns on debug mode allowing the browser user to see project settings and temporary variables.

ADMINS = ( ('xyz', '') )

sends all errors from the production server to the admin’s email address.

DATABASE_ENGINE = 'django.db.backends.postgresql_psycopg2'
DATABASE_NAME = 'newfies_dialer_db'
DATABASE_HOST = 'db-host'

sets up the options required for Django to connect to your database. Only Postgresql is supported.

MEDIA_ROOT = os.path.join(APPLICATION_DIR, 'static')

tells Django where to find your media files such as images that the HTML templates might use.


tells Django to start finding URL matches at in the module in the newfies project folder.

TEMPLATE_DIRS = ( os.path.join(APPLICATION_DIR, 'templates'), )

tells Django where to find your HTML template files.


tells Django which applications (custom and external) to use in your project. The custom applications, dialer_gateway, dialer_campaign etc. are stored in the project folder along with these custom applications.

The URLs modules

The defined URL patterns for the CPI Pilot project are divided into URL patterns specific to the project and URL patterns specific to the applications. For more information on how the pattern matching syntax work or how to write your own url patterns please consult Django’s URL Dispatcher documentation.

Project specific URL patterns

The URL patterns specific to the project are applied in the file that is stored in the project directory newfies. The code segments that add these URL patterns aren’t lengthy and are shown below:

urlpatterns = patterns('',
  # redirect
  ('^$', 'django.views.generic.simple.redirect_to', {'url': '/dialer_campaign/'}),
  (r'^admin/', include(,
  (r'^api/dialer_campaign/', include('dialer_campaign.api.urls')),
  (r'^dialer_campaign/', include('dialer_campaign.urls')),
  (r'^static/(?P<path>.*)$', 'django.views.static.serve',
      {'document_root': settings.STATIC_ROOT}),

Application specific URL patterns

The URL patterns specific to the dialer_campaign application are applied in the /dialer_campaign/ file in the dialer_campaign application folder. The code segment that adds these URL patterns isn’t lengthy either and is shown below:

urlpatterns = patterns('dialer_campaign.views',
  (r'^phonebook/$', 'phonebook_list'),
  (r'^phonebook/add/$', 'phonebook_add'),
  (r'^phonebook/(.+)/$', 'phonebook_change'),

The Views module

The functions defined in represent the logic behind the webpages. The view functions (called through the URL matching) decide which data structures need to be constructed and sent through to the HTML templates. To do this, each view function uses Django’s object relational model (ORM) to query the database picking out what is needed for any particular page.

def phonebook_add(request):
    Add new Phonebook
    form = PhonebookForm()
    if request.method == 'POST':
        form = PhonebookForm(request.POST)
        if form.is_valid():
            obj =
            obj.user = User.objects.get(username=request.user)
            request.session["msg"] = _('"%s" is added.' %\
            return HttpResponseRedirect('/dialer_campaign/phonebook/')
    template = 'dialer_campaign/phonebook/change.html'
    data = {
       'form': form,
       'action': 'add',
    return render_to_response(template, data,

The Admin Module

The classes defined in tell Django what attributes are visible and modifiable from the admin site.


def get_urls(self):
    urls = super(VoiceAppAdmin, self).get_urls()
    my_urls = patterns('',
        (r'^add/$', self.admin_site.admin_view(self.add_view)),
    return my_urls + urls

def add_view(self, request, extra_context=None):
    ctx = {
        'app_label': _('Voice'),
        'title': _('Add Voice'),
    return super(VoiceAppAdmin, self)\
           .add_view(request, extra_context=ctx)