From f5a438cf9faec9a7506ed77b5bbff14eebbe53e8 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Sat, 24 Nov 2012 01:42:10 +0100 Subject: [PATCH] cleanup in utils --- openslides/utils/template.py | 24 ++++-------------------- openslides/utils/utils.py | 20 +++++++++++++------- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/openslides/utils/template.py b/openslides/utils/template.py index c3b16b630..f87de2e09 100644 --- a/openslides/utils/template.py +++ b/openslides/utils/template.py @@ -24,6 +24,10 @@ class Tab(object): self.url = url +## All following function are only needed to render a block from a template +## and could be removed, if the template worked with an include-statement instead. +## Its only used for ajax-request from the projector. + def get_template(template): if isinstance(template, (tuple, list)): return loader.select_template(template) @@ -77,23 +81,3 @@ def render_block_to_string(template_name, block, dictionary=None, context_instance = Context(dictionary) t.render(context_instance) return render_template_block(t, block, context_instance) - - -def direct_block_to_template(request, template, block, extra_context=None, - mimetype=None, **kwargs): - """ - Render a given block in a given template with any extra URL parameters in - the context as ``{{ params }}``. - """ - if extra_context is None: - extra_context = {} - dictionary = {'params': kwargs} - for key, value in extra_context.items(): - if callable(value): - dictionary[key] = value() - else: - dictionary[key] = value - c = RequestContext(request, dictionary) - t = get_template(template) - t.render(c) - return HttpResponse(render_template_block(t, block, c), mimetype=mimetype) diff --git a/openslides/utils/utils.py b/openslides/utils/utils.py index 41aaf7544..8f7ff1674 100644 --- a/openslides/utils/utils.py +++ b/openslides/utils/utils.py @@ -67,12 +67,12 @@ def del_confirm_form(request, object, name=None, delete_link=None): % html_strong(name), delete_link) -def render_response(req, *args, **kwargs): - kwargs['context_instance'] = RequestContext(req) - return render_to_response(*args, **kwargs) - - def template(template_name): + """ + Decorator to set a template for a view. + + Deprecated. Use class based views instead. + """ def renderer(func): def wrapper(request, *args, **kwargs): output = func(request, *args, **kwargs) @@ -95,6 +95,8 @@ def permission_required(perm, login_url=None): """ Decorator for views that checks whether a user has a particular permission enabled, redirecting to the log-in page if necessary. + + Deprecated. """ def renderer(func): def wrapper(request, *args, **kw): @@ -108,7 +110,9 @@ def permission_required(perm, login_url=None): def render_to_forbidden(request, error= - ugettext_lazy("Sorry, you have no rights to see this page.")): + ugettext_lazy("Sorry, you have no rights to see this page.")): + # TODO: Integrate this function into the PermissionMixin once the + # above function is deleted. return HttpResponseForbidden(render_to_string('403.html', {'error': error}, context_instance=RequestContext(request))) @@ -127,7 +131,9 @@ def delete_default_permissions(**kwargs): def ajax_request(data): """ generates a HTTPResponse-Object with json-Data for a - ajax response + ajax response. + + Deprecated. """ return HttpResponse(json.dumps(data))