welco/welco/views.py

74 lines
2.5 KiB
Python
Raw Normal View History

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/>.
from django.contrib.auth import logout as auth_logout
from django.contrib.auth import views as auth_views
from django.http import HttpResponseRedirect
from django.shortcuts import resolve_url
from django import template
from django.template import RequestContext
2015-07-02 16:16:57 +02:00
from django.views.generic import TemplateView
try:
from mellon.utils import get_idps
except ImportError:
get_idps = lambda: []
from sources.mail.views import Home as MailHome
from .forms import QualificationForm
2015-07-02 16:16:57 +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)
class Qualification(object):
def __init__(self, request):
self.request = request
def render(self):
context = RequestContext(self.request)
context['form'] = QualificationForm()
tmpl = template.loader.get_template('welco/qualification.html')
return tmpl.render(context)
2015-07-02 16:16:57 +02:00
class Home(TemplateView):
template_name = 'welco/home.html'
def get_context_data(self, **kwargs):
context = super(Home, self).get_context_data(**kwargs)
context['source'] = MailHome(self.request)
context['qualification'] = Qualification(self.request)
return context
2015-07-02 16:16:57 +02:00
home = Home.as_view()