2015-07-02 16:16:57 +02:00
|
|
|
# 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/>.
|
|
|
|
|
2015-07-15 16:40:37 +02:00
|
|
|
import json
|
|
|
|
|
2015-07-08 10:42:34 +02:00
|
|
|
from django.contrib.auth import logout as auth_logout
|
|
|
|
from django.contrib.auth import views as auth_views
|
2015-07-08 21:36:05 +02:00
|
|
|
from django.contrib.contenttypes.models import ContentType
|
|
|
|
from django.core.urlresolvers import reverse
|
2015-07-15 16:40:37 +02:00
|
|
|
from django.http import HttpResponse, HttpResponseRedirect
|
2015-07-08 10:42:34 +02:00
|
|
|
from django.shortcuts import resolve_url
|
2015-07-08 15:04:54 +02:00
|
|
|
from django import template
|
|
|
|
from django.template import RequestContext
|
2015-07-08 21:36:05 +02:00
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
2015-07-02 16:16:57 +02:00
|
|
|
from django.views.generic import TemplateView
|
|
|
|
|
2015-07-08 10:42:34 +02:00
|
|
|
try:
|
|
|
|
from mellon.utils import get_idps
|
|
|
|
except ImportError:
|
|
|
|
get_idps = lambda: []
|
|
|
|
|
2015-07-03 11:48:16 +02:00
|
|
|
from sources.mail.views import Home as MailHome
|
2015-09-24 15:15:10 +02:00
|
|
|
from sources.phone.views import Home as PhoneHome
|
2015-07-08 21:36:05 +02:00
|
|
|
from .qualif.models import Association, FormdefReference
|
2015-07-14 12:40:07 +02:00
|
|
|
from .kb.views import HomeZone as KbHomeZone
|
2015-07-18 20:33:48 +02:00
|
|
|
from .contacts.views import HomeZone as ContactsHomeZone
|
2015-07-08 15:04:54 +02:00
|
|
|
from .forms import QualificationForm
|
2015-07-02 16:16:57 +02:00
|
|
|
|
2015-07-08 10:42:34 +02:00
|
|
|
|
|
|
|
def login(request, *args, **kwargs):
|
|
|
|
if any(get_idps()):
|
|
|
|
if not 'next' in request.GET:
|
|
|
|
return HttpResponseRedirect(resolve_url('mellon_login'))
|
|
|
|
return HttpResponseRedirect(resolve_url('mellon_login') + '?next='
|
|
|
|
+ urllib.quote(request.GET.get('next')))
|
|
|
|
return auth_views.login(request, *args, **kwargs)
|
|
|
|
|
|
|
|
def logout(request, next_page=None):
|
|
|
|
if any(get_idps()):
|
|
|
|
return HttpResponseRedirect(resolve_url('mellon_logout'))
|
|
|
|
auth_logout(request)
|
|
|
|
if next_page is not None:
|
|
|
|
next_page = resolve_url(next_page)
|
|
|
|
else:
|
|
|
|
next_page = '/'
|
|
|
|
return HttpResponseRedirect(next_page)
|
|
|
|
|
|
|
|
|
2015-07-08 17:19:24 +02:00
|
|
|
class Qualification(TemplateView):
|
|
|
|
template_name = 'welco/qualification.html'
|
2015-07-08 15:04:54 +02:00
|
|
|
|
2015-07-08 17:19:24 +02:00
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(Qualification, self).get_context_data(**kwargs)
|
2015-07-08 15:04:54 +02:00
|
|
|
context['form'] = QualificationForm()
|
2015-08-31 15:45:37 +02:00
|
|
|
source_type = ContentType.objects.get(id=self.request.GET['source_type'])
|
2015-09-24 15:15:10 +02:00
|
|
|
if source_type.model_class().get_qualification_form_class():
|
|
|
|
source_object = source_type.model_class().objects.get(id=self.request.GET['source_pk'])
|
|
|
|
context['source_form'] = source_object.get_qualification_form()
|
|
|
|
context['source_form_url'] = source_type.model_class().get_qualification_form_submit_url()
|
|
|
|
try:
|
|
|
|
context['association'] = Association.objects.get(
|
|
|
|
source_type=ContentType.objects.get(id=self.request.GET['source_type']),
|
|
|
|
source_pk=self.request.GET['source_pk'])
|
|
|
|
except Association.DoesNotExist:
|
|
|
|
pass
|
2015-07-08 17:19:24 +02:00
|
|
|
return context
|
|
|
|
|
2015-07-08 21:36:05 +02:00
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
|
association, created = Association.objects.get_or_create(
|
|
|
|
source_type=ContentType.objects.get(id=request.POST['source_type']),
|
|
|
|
source_pk=request.POST['source_pk'])
|
|
|
|
if created:
|
|
|
|
association.save()
|
|
|
|
formdef_ref, created = FormdefReference.objects.get_or_create(
|
|
|
|
reference=request.POST['formdef_reference'])
|
|
|
|
if created:
|
|
|
|
formdef_ref.save()
|
|
|
|
association.formdefs.add(formdef_ref)
|
|
|
|
request.GET = request.POST
|
|
|
|
return self.get(request)
|
|
|
|
|
|
|
|
qualification = csrf_exempt(Qualification.as_view())
|
2015-07-08 15:04:54 +02:00
|
|
|
|
|
|
|
|
2015-07-02 16:16:57 +02:00
|
|
|
class Home(TemplateView):
|
|
|
|
template_name = 'welco/home.html'
|
2015-09-24 15:15:10 +02:00
|
|
|
source_klass = MailHome
|
2015-07-02 16:16:57 +02:00
|
|
|
|
2015-07-03 11:48:16 +02:00
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(Home, self).get_context_data(**kwargs)
|
2015-09-24 15:15:10 +02:00
|
|
|
context['source'] = self.source_klass(self.request)
|
2015-07-14 12:40:07 +02:00
|
|
|
context['kb'] = KbHomeZone(self.request)
|
2015-07-18 20:33:48 +02:00
|
|
|
context['contacts'] = ContactsHomeZone(self.request)
|
2015-07-03 11:48:16 +02:00
|
|
|
return context
|
|
|
|
|
2015-07-02 16:16:57 +02:00
|
|
|
home = Home.as_view()
|
2015-07-15 16:40:37 +02:00
|
|
|
|
|
|
|
|
2015-09-24 15:15:10 +02:00
|
|
|
class HomePhone(Home):
|
|
|
|
source_klass = PhoneHome
|
|
|
|
|
|
|
|
home_phone = HomePhone.as_view()
|
|
|
|
|
|
|
|
|
2015-07-15 16:40:37 +02:00
|
|
|
@csrf_exempt
|
|
|
|
def qualification_done(request):
|
|
|
|
association = Association.objects.get(
|
|
|
|
source_type=ContentType.objects.get(id=request.POST['source_type']),
|
|
|
|
source_pk=request.POST['source_pk'])
|
|
|
|
association.triaged = True
|
|
|
|
association.save()
|
|
|
|
response = HttpResponse(content_type='application/json')
|
|
|
|
json.dump({'result': 'ok'}, response, indent=2)
|
|
|
|
return response
|