Commit 38467ccc authored by okhin's avatar okhin

Merge branch 'data_model' into 'master'

Data model

First version of Campaign manager django project with 3 applications:
- organization : to manage organization and related users
- campaign : to manage campaign and contacts to be reach
- feedback : to store call feedback

Mostly a data model to be used with django admin UI

See merge request !1
parents 12e5eb05 51b73cce
Campaign Manager for PiPhone project
# Installation
## Create a python virtual environment en activate it
virtualenv .env
source .env/bin/activate
## Install package
python setup.py install
# Configuration
Edit settings.py according to what type of database you want to use
and others settings related to your environment.
## Synchronize database
./manage.py syncdb
it will ask for creation of a superuser
If syncdb ran previously, commands are:
./manage.py makemigrations
./manage.py syncdb
## Test
./manage.py runserver
Then open your browser to http://127.0.0.1/admin
\ No newline at end of file
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "picampaign.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
# -*- coding: utf-8 -*-
try:
import pkg_resources
pkg_resources.declare_namespace(__name__)
except ImportError:
import pkgutil
__path__ = pkgutil.extend_path(__path__, __name__)
from django.contrib import admin
from picampaign.campaign.models import (Campaign, Contact, CampaignContact,
Argumentary)
admin.site.register(Campaign)
admin.site.register(Contact)
admin.site.register(CampaignContact)
admin.site.register(Argumentary)
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
LANGUAGES = map(lambda (k, v): (k, _(v)), settings.LANGUAGES)
class Contact(models.Model):
"""Contact model. Person to be called by users"""
id = models.AutoField(primary_key=True)
first_name = models.CharField(max_length=64)
last_name = models.CharField(max_length=64)
phone = models.CharField(max_length=32)
twitter = models.CharField(max_length=64, blank=True)
mail = models.CharField(max_length=255, blank=True)
def __unicode__(self):
return '%s %s' % (self.first_name, self.last_name)
class Campaign(models.Model):
"""Campaign model, describe what have to be achieved"""
id = models.AutoField(primary_key=True)
title = models.CharField(max_length=255)
description = models.CharField(max_length=512, blank=True)
start_date = models.DateField()
end_date = models.DateField()
default_lang = models.CharField(max_length=5,
choices=LANGUAGES,
verbose_name=_('language'))
def __unicode__(self):
return self.title
class Argumentary(models.Model):
"""Argumentary in a given language for a campaign"""
id = models.AutoField(primary_key=True)
campaign = models.ForeignKey(Campaign)
lang = models.CharField(max_length=5,
choices=LANGUAGES,
verbose_name=_('language'))
text = models.TextField(null=True)
def __unicode__(self):
return 'Argumentary in %s for %s' % (self.lang, self.campaign.title)
class CampaignContact(models.Model):
"""List contact related to a campaign with a given weight"""
id = models.AutoField(primary_key=True)
campaign = models.ForeignKey(Campaign)
contact = models.ForeignKey(Contact)
weight = models.IntegerField(default=0)
def __unicode__(self):
return 'Contact %s on %s' % (self.contact, self.campaign.title)
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render
# Create your views here.
from django.contrib import admin
from picampaign.feedback.models import Feedback
admin.site.register(Feedback)
from django.db import models
from picampaign.campaign.models import CampaignContact
from picampaign.organization.models import FeedbackCategory
class Feedback(models.Model):
id = models.AutoField(primary_key=True)
callee = models.ForeignKey(CampaignContact)
category = models.ForeignKey(FeedbackCategory)
comment = models.CharField(max_length=512, blank=True)
def __unicode__(self):
return 'feedback for %s on %s' % (self.callee.contact,
self.callee.campaign.title)
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render
# Create your views here.
from django.contrib import admin
from picampaign.organization.models import (Organization, Group,
FeedbackCategory)
admin.site.register(Organization)
admin.site.register(Group)
admin.site.register(FeedbackCategory)
from django.db import models
from django.contrib.auth.models import User
from picampaign.campaign.models import Contact
class Organization(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=64)
sip_key = models.CharField(max_length=255)
users = models.ManyToManyField(User, null=True, blank=True)
def __unicode__(self):
return self.name
class Group(models.Model):
"""Group model to qualify contacts"""
id = models.AutoField(primary_key=True)
organisation = models.ForeignKey(Organization)
name = models.CharField(max_length=64)
type = models.CharField(max_length=255, blank=True)
media = models.CharField(max_length=255, blank=True)
contacts = models.ManyToManyField(Contact, null=True, blank=True)
def __unicode__(self):
return self.name
class FeedbackCategory(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=64)
def __unicode__(self):
return self.name
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render
# Create your views here.
"""
Django settings for campaign project.
For more information on this file, see
https://docs.djangoproject.com/en/1.7/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.7/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '@q8%6uzh(bku)zmkl$&*_8m3(!f^rpw+d=&zi7llu=fjps!f_x'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'picampaign.campaign',
'picampaign.organization',
'picampaign.feedback',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'picampaign.urls'
WSGI_APPLICATION = 'picampaign.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/
STATIC_URL = '/static/'
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'campaign.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
)
"""
WSGI config for campaign project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/
"""
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "picampaign.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
import os
from setuptools import setup, find_packages
here = os.path.abspath(os.path.dirname(__file__))
README = open(os.path.join(here, 'README')).read()
requires = [
'django',
]
setup(name='picampaign',
namespace_packages=['picampaign'],
version='0.0.1',
description='PiPhone Campaign Manager.',
long_description=README,
classifiers=["Programming Language :: Python"],
author='',
author_email='',
url='',
keywords='web django application',
packages=find_packages(),
include_package_data=True,
zip_safe=False,
install_requires=requires,
tests_require=requires,
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment