wcs/wcs/views.py

64 lines
2.2 KiB
Python

# w.c.s. - web application for online forms
# Copyright (C) 2005-2013 Entr'ouvert
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
from quixote import get_publisher, get_request, get_response
from .forms.root import RootDirectory as FormsRootDirectory
from .qommon.admin.texts import TextsDirectory
from .qommon.template import get_decorate_vars
from . import compat
class Home(compat.TemplateWithFallbackView):
template_name = 'home.html'
def get_context_data(self, **kwargs):
context = super(Home, self).get_context_data(**kwargs)
with compat.request(self.request):
user = get_request().user
if user:
context['message'] = TextsDirectory.get_html_text('welcome-logged')
else:
context['message'] = TextsDirectory.get_html_text('welcome-unlogged')
root_directory = FormsRootDirectory()
context['forms'] = root_directory.get_context()
return context
home = Home.as_view()
class Backoffice(compat.TemplateWithFallbackView):
template_name = 'wcs/backoffice.html'
def post(self, request, *args, **kwargs):
return self.get(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super(Backoffice, self).get_context_data(**kwargs)
with compat.request(self.request):
get_request().response.filter = {'admin_ezt': True}
body = get_publisher().try_publish(get_request())
self.quixote_response = get_request().response
context.update(get_decorate_vars(body, get_response(), generate_breadcrumb=True))
return context
backoffice = Backoffice.as_view()