Commit 38467ccc authored by okhin's avatar okhin
Browse files

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
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