Permalink
Browse files

ajax data for post added

  • Loading branch information...
1 parent cbcb1c1 commit 201596e977c6d42fad12d0a952122cc519a5761f @digi604 committed May 3, 2013
Showing with 14 additions and 9 deletions.
  1. +1 −1 cms/admin/pageadmin.py
  2. +1 −2 cms/cms_toolbar.py
  3. +1 −1 cms/templates/cms/toolbar/menu/item.html
  4. +2 −2 cms/tests/toolbar.py
  5. +9 −3 cms/toolbar/items.py
View
@@ -655,7 +655,7 @@ def change_template(self, request, object_id):
if not page.has_change_permission(request):
return HttpResponseForbidden(_("You do not have permission to change the template"))
- to_template = request.GET.get("template", None)
+ to_template = request.POST.get("template", None)
if to_template not in dict(get_cms_setting('TEMPLATES')):
return HttpResponseBadRequest(_("Template not valid"))
View
@@ -83,14 +83,13 @@ def get_template_menu(self):
menu_items = List("#", _("Template"))
url = reverse('admin:cms_page_change_template', args=(self.request.current_page.pk,))
for path, name in get_cms_setting('TEMPLATES'):
- args = urllib.urlencode({'template': path})
active = False
if self.request.current_page.get_template() == path:
active = True
if path == "INHERIT":
menu_items.items.append(Break())
menu_items.items.append(
- Item('%s?%s' % (url, args), name, ajax=True, active=active),
+ Item(url, name, ajax=True, ajax_data={'template': path}, active=active),
)
return menu_items
@@ -1 +1 @@
-<li{% if active %} class="active" {% endif %}{% if disabled %} class="cms_toolbar-item_navigation-disabled"{% endif %}><a href="{{ url }}"{% if type %} rel="{{ type }}"{% endif %}{% if question %}data-text="{{ question }}"{% endif %}>{{ title }}</a></li>
+<li{% if active %} class="active" {% endif %}{% if disabled %} class="cms_toolbar-item_navigation-disabled"{% endif %}><a href="{{ url }}"{% if type %} rel="{{ type }}"{% endif %}{% if question %}data-text="{{ question }}"{% endif %}{% if data %} data="{{ data }}"{% endif %}>{{ title }}</a></li>
digi604
digi604 May 3, 2013 Owner

@FinalAngel the

  • tags have now an optional data attribute with escaped json that should be the POST data sent via ajax.

  • View
    @@ -157,7 +157,7 @@ def test_toolbar_publish_button(self):
    toolbar = CMSToolbar(request)
    self.assertTrue(toolbar.edit_mode)
    items = toolbar.items
    - self.assertEqual(len(items), 6)
    + self.assertEqual(len(items), 7)
    def test_toolbar_no_publish_button(self):
    page = create_page('test', 'nav_playground.html', 'en', published=True)
    @@ -168,7 +168,7 @@ def test_toolbar_no_publish_button(self):
    self.assertTrue(toolbar.edit_mode)
    items = toolbar.items
    # Logo + edit-mode + templates + page-menu + admin-menu + logout
    - self.assertEqual(len(items), 5)
    + self.assertEqual(len(items), 6)
    def test_toolbar_no_change_button(self):
    page = create_page('test', 'nav_playground.html', 'en', published=True)
    View
    @@ -1,4 +1,5 @@
    from django.template.loader import render_to_string
    +from django.utils import simplejson
    class BaseItem(object):
    @@ -32,8 +33,8 @@ def __repr__(self):
    class Item(BaseItem):
    template = "cms/toolbar/menu/item.html"
    - def __init__(self, url, title, load_side_frame=False, ajax=False, active=False, question="", right=False,
    - load_modal=True, disabled=False):
    + def __init__(self, url, title, load_side_frame=False, ajax=False, ajax_data=None, active=False, question="",
    + right=False, load_modal=True, disabled=False):
    super(Item, self).__init__(right)
    if load_side_frame and ajax:
    raise Exception("load_side_frame and ajax can not both be True.")
    @@ -45,6 +46,7 @@ def __init__(self, url, title, load_side_frame=False, ajax=False, active=False,
    self.active = active
    self.question = question
    self.disabled = disabled
    + self.ajax_data = ajax_data
    def get_context(self):
    mod = None
    @@ -56,13 +58,17 @@ def get_context(self):
    mod = "dialogue"
    elif self.load_modal:
    mod = "modal"
    + data = None
    + if self.ajax_data:
    + data = simplejson.dumps(self.ajax_data)
    return {
    'url': self.url,
    'title': self.title,
    'type': mod,
    'active': self.active,
    'question': self.question,
    - 'disabled': self.disabled
    + 'disabled': self.disabled,
    + 'data': data,
    }
    def __repr__(self):

    0 comments on commit 201596e

    Please sign in to comment.