add support for counter channel (#9012)

This commit is contained in:
Frédéric Péters 2015-11-26 14:46:50 +01:00
parent 300e991ae3
commit ae6c192579
12 changed files with 218 additions and 0 deletions

View File

@ -44,6 +44,7 @@ INSTALLED_APPS = (
'ckeditor',
'haystack',
'reversion',
'welco.sources.counter',
'welco.sources.mail',
'welco.sources.phone',
'welco.qualif',
@ -176,8 +177,14 @@ AUTHENTIC_AUTH_TUPLE = ('username', 'password')
CHANNEL_ROLES = {
'mail': [],
'phone': [],
'counter': [],
}
# useful links for counter
COUNTER_LINKS = [
{'label': 'Wikipedia', 'url': 'https://fr.wikipedia.org'}
]
local_settings_file = os.environ.get('WELCO_SETTINGS_FILE',
os.path.join(os.path.dirname(__file__), 'local_settings.py'))
if os.path.exists(local_settings_file):

View File

View File

@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
]
operations = [
migrations.CreateModel(
name='CounterPresence',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('status', models.CharField(max_length=50, verbose_name='Status', blank=True)),
('contact_id', models.CharField(max_length=50, null=True)),
('creation_timestamp', models.DateTimeField(auto_now_add=True)),
('last_update_timestamp', models.DateTimeField(auto_now=True)),
],
options={
'verbose_name': 'Counter Presence',
},
bases=(models.Model,),
),
]

View File

@ -0,0 +1,48 @@
# welco - multichannel request processing
# Copyright (C) 2015 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.contrib.contenttypes import generic
from django.core.urlresolvers import reverse
from django.db import models
from django.utils.translation import ugettext_lazy as _
from welco.qualif.models import Association
class CounterPresence(models.Model):
class Meta:
verbose_name = _('Counter Presence')
# common to all source types:
status = models.CharField(_('Status'), blank=True, max_length=50)
contact_id = models.CharField(max_length=50, null=True)
associations = generic.GenericRelation(Association,
content_type_field='source_type', object_id_field='source_pk')
creation_timestamp = models.DateTimeField(auto_now_add=True)
last_update_timestamp = models.DateTimeField(auto_now=True)
@classmethod
def get_qualification_form_class(cls):
return None
def get_qualification_form(self):
return None
def get_source_context(self, request):
return {
'channel': 'counter',
}

View File

@ -0,0 +1,22 @@
{% load i18n %}
<h2>{% trans 'Counter' %}</h2>
<div data-source-type="{{ source_type.id }}" data-zone-url="{% url 'counter-zone' %}">
<div class="counter active" data-source-pk="{{source_pk}}">
<a class="button" href=".">{% trans 'New Person' %}</a>
{% if useful_links %}
<div class="useful-links">
<h3>{% trans 'Useful links' %}</h3>
<ul>
{% for link in useful_links %}
<li><a href="{{link.url}}">{{link.label}}</a></li>
{% endfor %}
</ul>
</div>
{% endif %}
</div>
</div>

View File

@ -0,0 +1,24 @@
# welco - multichannel request processing
# Copyright (C) 2015 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.conf.urls import patterns, url
from . import views
urlpatterns = patterns(
'',
url(r'^ajax/counter/zone/$', views.zone, name='counter-zone'),
)

View File

@ -0,0 +1,64 @@
# welco - multichannel request processing
# Copyright (C) 2015 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import json
from django import template
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.template import RequestContext
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseBadRequest, HttpResponse
from django.views.generic import TemplateView
from .models import CounterPresence
class Home(object):
source_key = 'counter'
def __init__(self, request):
self.request = request
def render(self):
zone = CounterZone()
zone.request = self.request
context = RequestContext(self.request)
context.update(zone.get_context_data())
tmpl = template.loader.get_template('welco/counter_home.html')
return tmpl.render(context)
class CounterZone(TemplateView):
template_name = 'welco/counter_home.html'
def get_context_data(self, **kwargs):
context = super(CounterZone, self).get_context_data(**kwargs)
context['source_type'] = ContentType.objects.get_for_model(CounterPresence)
new_source = CounterPresence()
new_source.save()
context['source_pk'] = new_source.id
context['useful_links'] = settings.COUNTER_LINKS
return context
zone = csrf_exempt(CounterZone.as_view())
@csrf_exempt
@login_required
def next(request):
return HttpResponse(json.dumps({'err': 0}), content_type='application/json')

View File

@ -521,3 +521,16 @@ div.ui-dialog form.contact-add p input {
display: inline-block;
width: 20em;
}
div.counter {
padding: 2em;
}
div.counter a.button {
text-align: center;
display: block;
}
div.useful-links {
margin-top: 2em;
}

View File

@ -494,4 +494,8 @@ $(function() {
return false;
});
if ($('.counter.active').length) {
refresh_bottom_cells();
}
});

View File

@ -25,7 +25,9 @@ urlpatterns = patterns('',
url(r'^$', 'welco.views.home', name='home'),
url(r'^mail/$', 'welco.views.home_mail', name='home-mail'),
url(r'^phone/$', 'welco.views.home_phone', name='home-phone'),
url(r'^counter/$', 'welco.views.home_counter', name='home-counter'),
url(r'^', include('welco.sources.phone.urls')),
url(r'^', include('welco.sources.counter.urls')),
url(r'^ajax/qualification$', 'welco.views.qualification', name='qualif-zone'),
url(r'^ajax/qualification-done$', 'welco.views.qualification_done', name='qualif-done'),
url(r'^ajax/remove-association/(?P<pk>\w+)$',

View File

@ -40,6 +40,7 @@ except ImportError:
from sources.mail.views import Home as MailHome
from sources.phone.views import Home as PhoneHome
from sources.counter.views import Home as CounterHome
from .qualif.models import Association
from .kb.views import HomeZone as KbHomeZone
from .contacts.views import HomeZone as ContactsHomeZone
@ -145,6 +146,11 @@ class HomeMail(ChannelHome):
home_mail = login_required(HomeMail.as_view())
class HomeCounter(ChannelHome):
source_klass = CounterHome
home_counter = login_required(HomeCounter.as_view())
@csrf_exempt
@ -220,6 +226,7 @@ def menu_json(request):
labels = {
'mail': _('Mails'),
'phone': _('Phone Calls'),
'counter': _('Counter'),
}
for channel in settings.CHANNEL_ROLES:
channel_groups = set(settings.CHANNEL_ROLES[channel])