From 994199f09619cf7a24435389a0d927c874258363 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Tue, 13 May 2014 01:00:38 +0530 Subject: [PATCH] Cleanup menu generation using templates --- LICENSES | 1 - menu.py | 39 ++++------------------- templates/base.html | 11 +++---- templates/login_nav.html | 15 +++++++-- templates/menu.html | 36 +++++++++++++++++++++ themes/default/js/menu.js | 67 --------------------------------------- util.py | 16 ++-------- 7 files changed, 61 insertions(+), 124 deletions(-) create mode 100644 templates/menu.html delete mode 100644 themes/default/js/menu.js diff --git a/LICENSES b/LICENSES index e4a1d8a0e..f967fb292 100644 --- a/LICENSES +++ b/LICENSES @@ -108,7 +108,6 @@ specified and linked otherwise. - themes/default/img/glyphicons-halflings.png :: - - themes/default/img/glyphicons-halflings-white.png :: - - themes/default/js/functions.js :: - -- themes/default/js/menu.js :: - - themes/default/js/plinth.js :: - - themes/default/js/plugins.js :: [[file:themes/default/js/plugins.js::/%20paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/][CC0]] - themes/default/js/libs/jquery.min.js :: Symlink to external target: [[file:themes/default/js/libs/jquery.min.js::*%20Dual%20licensed%20under%20the%20MIT%20or%20GPL%20Version%202%20licenses.][MIT/GPL2]] diff --git a/menu.py b/menu.py index 93860dcdb..84b26c19d 100644 --- a/menu.py +++ b/menu.py @@ -1,19 +1,16 @@ from urlparse import urlparse -try: - import simplejson as json -except ImportError: - import json import cherrypy import cfg + class Menu(): """One menu item.""" def __init__(self, label="", icon="", url="#", order=50): """label is the text that is displayed on the menu. - icon is the icon to be displayed next to the label. - Choose from the Glyphicon set: - http://twitter.github.com/bootstrap/base-css.html#icons + icon is the icon to be displayed next to the label. + Choose from the Glyphicon set: + http://twitter.github.com/bootstrap/base-css.html#icons url is the url location that will be activated when the menu item is selected. @@ -35,11 +32,13 @@ class Menu(): def sort_items(self): """Sort the items in self.items by order.""" self.items = sorted(self.items, key=lambda x: x.order, reverse=False) + def add_item(self, label, icon, url, order=50, basehref=True): """This method creates a menu item with the parameters, adds that menu item to this menu, and returns the item. - If BASEHREF is true and url start with a slash, prepend the cfg.server_dir to it""" + If BASEHREF is true and url start with a slash, prepend the + cfg.server_dir to it""" if basehref and url.startswith("/"): url = cfg.server_dir + url @@ -62,27 +61,3 @@ class Menu(): for item in self.items: if path.startswith(item.url): return item - - def serializable(self, render_subs=False): - """Return the items in self.items as a serializable object we can pass to json. - Note: this doesn't serialize all the data in this object.""" - - so = [] - for item in self.items: - i = { 'label':item.label, 'icon':item.icon, 'url':item.url} - if item.active_p(): - i['active']=True - if item.items and render_subs: - i['subs'] = item.serializable() - so.append(i) - return so - def encode(self, name="", render_subs=False): - """return a string containing a javascript data structure - assigned to the menu name - - if render_subs is True, we render submenus too""" - - return ('') diff --git a/templates/base.html b/templates/base.html index 55552c0da..9f381dd8b 100644 --- a/templates/base.html +++ b/templates/base.html @@ -47,10 +47,7 @@ {{ css|safe }} - - {{ main_menu_js|safe }} - {{ sub_menu_js|safe }} @@ -72,13 +69,13 @@
- {% if nav or sidebar_right or sidebar_left %} + {% if submenu or sidebar_right or sidebar_left %}
- {% if nav %} + {% if submenu %} - {% endif %} + {% endif %} {% if sidebar_left %}