wcs/wcs/views.py

68 lines
2.5 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 django.http import HttpResponse
from quixote import get_publisher, get_request, get_response
from . import compat
from .qommon import template
class Backoffice(compat.TemplateWithFallbackView):
template_name = 'wcs/backoffice-legacy.html'
template_names = None
def post(self, request, *args, **kwargs):
return self.get(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
_request = None
with compat.request(self.request):
get_request().response.filter = {'admin_ezt': True}
body = get_publisher().try_publish(get_request())
if isinstance(body, template.QommonTemplateResponse):
body.add_media()
if body.is_django_native:
_request = get_request()
self.template_names = body.templates
context.update(body.context)
else:
body = template.render(body.templates, body.context)
self.template_names = None
get_publisher().session_manager.finish_successful_request()
self.quixote_response = get_request().response
context.update(template.get_decorate_vars(body, get_response(), generate_breadcrumb=True))
# restore request for django mode
if _request is not None:
get_publisher()._set_request(_request)
return context
def get_template_names(self):
return self.template_names or [self.template_name]
backoffice = Backoffice.as_view()
def robots_txt(request, *args, **kwargs):
return HttpResponse(
get_publisher().get_site_option('robots_txt', 'variables') or '', content_type='text/plain'
)