This repository has been archived by the owner on Aug 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add design plugin with "design switch" view.
- Loading branch information
Showing
6 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'), | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, "<automatic>")] + list(designs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
27 changes: 27 additions & 0 deletions
27
pylucid_project/pylucid_plugins/design/templates/design/switch.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{% extends "admin/base_site.html" %} | ||
|
||
{% block content %} | ||
|
||
{% if design_switch %} | ||
<p> | ||
The current page design is switched to: <strong>{{ design_switch }}</strong>.<br/> | ||
You will see all cms pages in this design. | ||
</p> | ||
{% else %} | ||
<p> | ||
No 'design switch' active.<br/> | ||
You will see all cms pages in the design associated by the PageTree. | ||
</p> | ||
{% endif %} | ||
|
||
<form action="{{ form_url }}" method="post" id="find_and_replace_form" class="pylucid_form"> | ||
{% include "admin/pylucid/includes/form_fieldset_errorlist.html" %} | ||
{% include "admin/pylucid/includes/markup_preview_fieldset.html" %} | ||
<fieldset> | ||
{% include "admin/pylucid/includes/pylucid_formset.html" %} | ||
<div class="helper_buttons"> | ||
<input type="submit" name="save" value="{% trans 'switch design' %}" /> | ||
</div> | ||
</fieldset> | ||
</form> | ||
{% endblock %} |
65bda3f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: The "switched design" has no effects on PluginPages...