diff --git a/pylucid_project/pylucid_plugins/design/__init__.py b/pylucid_project/pylucid_plugins/design/__init__.py new file mode 100644 index 000000000..429f97159 --- /dev/null +++ b/pylucid_project/pylucid_plugins/design/__init__.py @@ -0,0 +1,24 @@ +# coding: utf-8 + +""" + PyLucid design plugin + ~~~~~~~~~~~~~~~~~~~~~~ + + connect signals + + Last commit info: + ~~~~~~~~~ + $LastChangedDate: 2009-08-11 15:39:06 +0200 (Di, 11 Aug 2009) $ + $Rev: 2264 $ + $Author: JensDiemer $ + + :copyleft: 2009-2010 by the PyLucid team, see AUTHORS for more details. + :license: GNU GPL v3 or above, see LICENSE for more details +""" + +from pylucid_project.apps.pylucid.signals import pre_render_global_template + +from design.signal_receiver import pre_render_global_template_handler + + +pre_render_global_template.connect(pre_render_global_template_handler) diff --git a/pylucid_project/pylucid_plugins/design/admin_urls.py b/pylucid_project/pylucid_plugins/design/admin_urls.py new file mode 100644 index 000000000..20165827a --- /dev/null +++ b/pylucid_project/pylucid_plugins/design/admin_urls.py @@ -0,0 +1,18 @@ +# coding: utf-8 + +""" + PyLucid admin views url patterns + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + :copyleft: 2010 by the PyLucid team, see AUTHORS for more details. + :license: GNU GPL v3 or above, see LICENSE for more details. +""" + +from django.conf.urls.defaults import patterns, url + +from design import admin_views + +urlpatterns = patterns('', + url(r'^switch/$', admin_views.switch, name='Design-switch'), +) + diff --git a/pylucid_project/pylucid_plugins/design/admin_views.py b/pylucid_project/pylucid_plugins/design/admin_views.py new file mode 100644 index 000000000..cdf2f4089 --- /dev/null +++ b/pylucid_project/pylucid_plugins/design/admin_views.py @@ -0,0 +1,84 @@ +# coding: utf-8 + +""" + PyLucid admin views + ~~~~~~~~~~~~~~~~~~~ + + :copyleft: 2010 by the PyLucid team, see AUTHORS for more details. + :license: GNU GPL v3 or above, see LICENSE for more details. +""" + + +from django import http +from django.utils.translation import ugettext as _ + +from pylucid_project.apps.pylucid.decorators import check_permissions, render_to + +from pylucid_project.apps.pylucid_admin.admin_menu import AdminMenu + +from design.forms import SelectDesign +from pylucid_project.apps.pylucid.models import Design + + +def install(request): + """ insert PyLucid admin views into PageTree """ + output = [] + + admin_menu = AdminMenu(request, output) + menu_section_entry = admin_menu.get_or_create_section("edit look") + admin_menu.add_menu_entry( + parent=menu_section_entry, url_name="Design-switch", + name="switch design", title="Switch the page design, temporary.", + ) + + return "\n".join(output) + + +@check_permissions(superuser_only=False, permissions=("pylucid.change_design",)) +@render_to("design/switch.html") +def switch(request): + """ + 'switch' the design. + Save design ID in request.session["design_switch_pk"] + This value would be used in design.signal_reveiver + """ + context = { + "title": _("Switch a PyLucid page design"), + "form_url": request.path, + } + + if "design_switch_pk" in request.session: + design_id = request.session["design_switch_pk"] + try: + context["design_switch"] = Design.on_site.get(id=design_id) + except Design.DoesNotExist, err: + request.page_msg.error(_( + "Error: Design with ID %(id)r doesn't exist: %(err)s" + ) % {"id":design_id, "err": err} + ) + del request.session["design_switch_pk"] + design_id = 0 + else: + design_id = 0 + + if request.method == "POST": + form = SelectDesign(request.POST) + if form.is_valid(): + design_id = int(form.cleaned_data["design"]) + if design_id == 0: + # reset to automatic selection by pagetree association + if "design_switch_pk" in request.session: + del request.session["design_switch_pk"] + request.page_msg( + _("delete 'design switch', turn to automatic mode.") + ) + else: + request.page_msg(_("Save design ID %r") % design_id) + request.session["design_switch_pk"] = design_id + return http.HttpResponseRedirect(request.path) + else: + form = SelectDesign(initial={"design": design_id}) + + context["form"] = form + return context + diff --git a/pylucid_project/pylucid_plugins/design/forms.py b/pylucid_project/pylucid_plugins/design/forms.py new file mode 100644 index 000000000..2ca1ba32f --- /dev/null +++ b/pylucid_project/pylucid_plugins/design/forms.py @@ -0,0 +1,19 @@ +# coding:utf-8 + +from django import forms +from django.utils.translation import ugettext_lazy as _ + +from pylucid_project.apps.pylucid.models import Design + + +class SelectDesign(forms.Form): + design = forms.ChoiceField( + # choices= Set in __init__, so the Queryset would not execute at startup + required=False, initial=None, + help_text=_("Select the PyLucid page design") + ) + + def __init__(self, *args, **kwargs): + super(SelectDesign, self).__init__(*args, **kwargs) + designs = Design.on_site.all().values_list("id", "name") + self.fields["design"].choices = [(0, "")] + list(designs) diff --git a/pylucid_project/pylucid_plugins/design/signal_receiver.py b/pylucid_project/pylucid_plugins/design/signal_receiver.py new file mode 100644 index 000000000..8bdf7f3bd --- /dev/null +++ b/pylucid_project/pylucid_plugins/design/signal_receiver.py @@ -0,0 +1,38 @@ +# coding: utf-8 + +""" + PyLucid design plugin + ~~~~~~~~~~~~~~~~~~~~~ + + signal receiver, connected in design.__init__.py + + switch design, if "design_switch_pk" in request.session + + :copyleft: 2010 by the PyLucid team, see AUTHORS for more details. + :license: GNU GPL v3 or above, see LICENSE for more details +""" + +from django.conf import settings +from django.utils.safestring import mark_safe +from django.utils.translation import ugettext as _ +from django.template.loader import render_to_string + + +def pre_render_global_template_handler(**kwargs): + """ + Handle the 'pre_render_global_template' signal. + """ + request = kwargs["request"] + if "design_switch_pk" not in request.session: + # The user has not switch the design + return + + from pylucid_project.apps.pylucid.models import Design # import here, agains import loops + + pagetree = request.PYLUCID.pagetree + print "old design:", pagetree.design + + design_id = request.session["design_switch_pk"] + pagetree.design = Design.on_site.get(id=design_id) + + print "use design:", pagetree.design diff --git a/pylucid_project/pylucid_plugins/design/templates/design/switch.html b/pylucid_project/pylucid_plugins/design/templates/design/switch.html new file mode 100644 index 000000000..c1b9d43a7 --- /dev/null +++ b/pylucid_project/pylucid_plugins/design/templates/design/switch.html @@ -0,0 +1,27 @@ +{% extends "admin/base_site.html" %} + +{% block content %} + +{% if design_switch %} +

+ The current page design is switched to: {{ design_switch }}.
+ You will see all cms pages in this design. +

+{% else %} +

+ No 'design switch' active.
+ You will see all cms pages in the design associated by the PageTree. +

+{% endif %} + +
+ {% include "admin/pylucid/includes/form_fieldset_errorlist.html" %} + {% include "admin/pylucid/includes/markup_preview_fieldset.html" %} +
+ {% include "admin/pylucid/includes/pylucid_formset.html" %} +
+ +
+
+
+{% endblock %}