Permalink
Browse files

update model choices

  • Loading branch information...
1 parent e340dfd commit b509d96ec533786c2a4b678f6cacc4e0fa7f31ad Zenobius Jiricek committed Feb 8, 2012
Showing with 85 additions and 83 deletions.
  1. +39 −38 cmsplugin_embeddedmenu/cms_plugins.py
  2. +1 −4 cmsplugin_embeddedmenu/lib/choices.py
  3. +45 −41 cmsplugin_embeddedmenu/models.py
@@ -6,60 +6,61 @@
from cms.menu_bases import CMSAttachMenu
from menus.base import (
- Menu,
- Modifier,
- NavigationNode
+ Menu,
+ Modifier,
+ NavigationNode
)
from menus.menu_pool import menu_pool
from menus.templatetags.menu_tags import (
- cut_levels,
- cut_after,
- flatten,
+ cut_levels,
+ cut_after,
+ flatten,
)
from models import (
- MenuPluginSettings,
- TEMPLATE_PATH,
+ ApplicationSettings,
+ MenuPluginSettings,
+ TEMPLATE_PATH,
)
class MenuPlugin(CMSPluginBase):
- model = MenuPluginSettings
- name = _("Embedded Menu")
- render_template = "cmsplugin_embeddedmenu/base.html"
- admin_preview = False
+ model = MenuPluginSettings
+ name = _("Embedded Menu")
+ render_template = "cmsplugin_embeddedmenu/base.html"
+ admin_preview = False
- def render(self, context, instance, placeholder):
+ def render(self, context, instance, placeholder):
- try:
- # If there's an exception (500), default context_processors may not be called.
- request = context['request']
- except KeyError:
- return "There is no `request` object in the context."
+ try:
+ # If there's an exception (500), default context_processors may not be called.
+ request = context['request']
+ except KeyError:
+ return "There is no `request` object in the context."
- root_page = instance.root
- root_page_url = root_page.get_absolute_url()
- from_level = instance.start_level
- to_level = instance.depth
+ root_page = instance.root
+ root_page_url = root_page.get_absolute_url()
+ from_level = instance.start_level
+ to_level = instance.depth
- nodes = menu_pool.get_nodes(request)
+ nodes = menu_pool.get_nodes(request)
- children = list()
- root_node = None
+ children = list()
+ root_node = None
- # Find the root node
- for node in nodes:
- if not root_node and node.url == root_page_url:
- root_node = node
+ # Find the root node
+ for node in nodes:
+ if not root_node and node.url == root_page_url:
+ root_node = node
- if root_node:
- if instance.include_root :
- children += (root_node, )
- else:
- children += root_node.children
+ if root_node:
+ if instance.include_root :
+ children += (root_node, )
+ else:
+ children += root_node.children
- context.update({
- 'MenuItems' : children,
- })
- return context
+ context.update({
+ 'MenuItems' : children,
+ })
+ return context
plugin_pool.register_plugin(MenuPlugin)
@@ -95,14 +95,11 @@ def __init__(self, path=None, include=None,
self.default_file = default_file
def generate(self, *args, **kwargs):
- choices = list()
- choices += ( (os.path.join(self.path,self.default_file), "Default"),)
-
+ choices = ( (os.path.join(self.path,self.default_file), "Default"), )
for template_dir in app_template_dirs:
results = self.walkdir(os.path.join(template_dir, self.path))
if results:
choices += results
-
return choices
def walkdir(self, path=None):
@@ -2,50 +2,54 @@
from django.db import models
from cms.models.pluginmodel import CMSPlugin
+from appconf import AppConf
from .lib.choices import (
- DynamicTemplateChoices,
- PageAttributeDynamicChoices,
+ DynamicTemplateChoices,
)
-TEMPLATE_PATH = os.path.join("cmsplugin_embeddedmenu", "layouts")
-CONTAINER_TEMPLATE_PATH = os.path.join(TEMPLATE_PATH, "containers")
-MENU_TEMPLATE_PATH = os.path.join(TEMPLATE_PATH, "menus")
-ITEM_TEMPLATE_PATH = os.path.join(TEMPLATE_PATH, "items")
+class ApplicationSettings(AppConf):
+ TEMPLATE_PATH = os.path.join("cmsplugin_embeddedmenu", "layouts")
+ CONTAINER_TEMPLATE_PATH = os.path.join(TEMPLATE_PATH, "containers")
+ MENU_TEMPLATE_PATH = os.path.join(TEMPLATE_PATH, "menus")
+ ITEM_TEMPLATE_PATH = os.path.join(TEMPLATE_PATH, "items")
class MenuPluginSettings(CMSPlugin):
- """ Stores options for cmsplugin that Embeds a menu
- """
-
- container_template = models.CharField("Container Template",
- choices = DynamicTemplateChoices(
- path=CONTAINER_TEMPLATE_PATH,
- include='.html',
- exclude='default'), max_length=256,
- help_text="""Use this template to render the menu container""")
-
- tree_template = models.CharField("Menu Template",
- choices = DynamicTemplateChoices(
- path=MENU_TEMPLATE_PATH,
- include='.html',
- exclude='default'), max_length=256,
- help_text="""Use this template to render a menu branch""")
-
- item_template = models.CharField("Menu Item Template",
- choices = DynamicTemplateChoices(
- path=ITEM_TEMPLATE_PATH,
- include='.html',
- exclude='default'), max_length=256,
- help_text="""Use this template to render the menu item.""")
-
- root = models.ForeignKey("cms.Page", default=1,
- help_text="""Menu tree starts from this page.""")
-
- include_root = models.BooleanField("Include Root", default=True,
- help_text="""Shall the menu also include the root menu item specified?""")
-
- start_level = models.IntegerField(default=0,
- help_text="""Should the root page also be included in the output?""")
-
- depth = models.IntegerField(default=0,
- help_text="""How many levels deep to look for menu items to show?""")
+ """ Stores options for cmsplugin that Embeds a menu
+ """
+# title = models.CharField(max_length=128, blank=True, null=True)
+
+ container_template = models.CharField("Plugin Template",
+ choices = DynamicTemplateChoices(
+ path = ApplicationSettings.CONTAINER_TEMPLATE_PATH,
+ include = '.html'),
+ max_length = 256,
+ help_text = """Use this template to render the menu container""")
+
+ tree_template = models.CharField("Tree Template",
+ choices = DynamicTemplateChoices(
+ path = ApplicationSettings.MENU_TEMPLATE_PATH,
+ include = '.html'),
+ max_length = 256,
+ help_text = """Use this template to render a menu branch""")
+
+ item_template = models.CharField("Leaf Template",
+ choices = DynamicTemplateChoices(
+ path = ApplicationSettings.ITEM_TEMPLATE_PATH,
+ include = '.html'),
+ max_length = 256,
+ help_text = """Use this template to render a leaf(a menu item) of a menu branch.""")
+
+ root = models.ForeignKey("cms.Page",
+ default = 1,
+ help_text = """Menu tree starts from this page.""")
+
+ include_root = models.BooleanField("Include Root",
+ default = True,
+ help_text = """Shall the menu also include the root menu item specified?""")
+
+ start_level = models.IntegerField(default = 0,
+ help_text = """Should the root page also be included in the output?""")
+
+ depth = models.IntegerField(default = 0,
+ help_text = """How many levels deep to look for menu items to show?""")

0 comments on commit b509d96

Please sign in to comment.