# HG changeset patch # User Todd Larsen # Date 1222224412 0 # Node ID 089a86d84067ebb131331495ba023ad3dd006d6e # Parent 086282e1999593491d0b5ef4289ceed6bf896474 Make views.helpers.html_menu MenuItem classes and logic.menu MenuItem classes more closely related. This is part of some refactoring in my working copy to keep soc/logic/site/sidebar.py from having to deal with html_menu classes (which is like having view code in the controller, which is bad). diff -r 086282e19995 -r 089a86d84067 app/soc/logic/menu.py --- a/app/soc/logic/menu.py Wed Sep 24 02:36:47 2008 +0000 +++ b/app/soc/logic/menu.py Wed Sep 24 02:46:52 2008 +0000 @@ -70,16 +70,23 @@ """Provides menu item properties as easily-accessible attributes. """ - def __init__(self, name, selected=False, sub_menu=None): + def __init__(self, name, value=None, selected=False, annotation=None, + sub_menu=None): """Initializes the menu item attributes from supplied arguments. Args: name: name of the menu item + value: optional value associated with the menu item; + default is None selected: Boolean indicating if this menu item is selected; default is False + annotation: optional annotation associated with the menu item; + default is None sub_menu: a Menu of sub-items to display below this menu item; default is None, indicating no sub-menu """ self.name = name + self.value = value self.selected = selected + self.annotation = annotation self.sub_menu = sub_menu diff -r 086282e19995 -r 089a86d84067 app/soc/views/helpers/html_menu.py --- a/app/soc/views/helpers/html_menu.py Wed Sep 24 02:36:47 2008 +0000 +++ b/app/soc/views/helpers/html_menu.py Wed Sep 24 02:46:52 2008 +0000 @@ -65,22 +65,21 @@ """Provides HTML menu item properties as attributes as an link. """ - def __init__(self, text, url=None, selected=False, help_text=None, + def __init__(self, text, value=None, selected=False, annotation=None, sub_menu=None): """Initializes the menu item attributes from supplied arguments. Args: text: text displayed for the menu item link anchor - url: optional URL to be placed in the menu item link href; + value: optional URL to be placed in the menu item link href; default is None selected: Boolean indicating if this menu item is selected; default is False - help_text: optional help text associated with the menu item + annotation: optional help text associated with the menu item sub_menu: see menu.MenuItem.__init__() """ - menu.MenuItem.__init__(self, text, selected=selected, sub_menu=sub_menu) - self.url = url - self.help_text = help_text + menu.MenuItem.__init__(self, text, value=value, selected=selected, + annotation=annotation, sub_menu=sub_menu) def getHtmlTags(self, indent): """Returns list of HTML tags for a menu item (and possibly its sub-menus). @@ -92,7 +91,7 @@ Returns: a list of strings that can be joined with '\n' into a single string to produce an ... link, or just the MenuItem.name - as plain text if there was no AHrefMenuItem.url; may also append + as plain text if there was no AHrefMenuItem.value URL; may also append arbitrarily nested sub-menus """ tags = [] @@ -100,14 +99,15 @@ # TODO(tlarsen): user-supplied content *must* be escaped to prevent XSS # TODO(tlarsen): implement "selected" style - if self.url: + if self.value: + # URL supplied, so make an self.name link tags.append('%s%s' % (self.url, self.name)) + tags.append('"%s">%s' % (self.value, self.name)) else: - # if no URL, then not a link, so just display text - tags.append(item.name) + # if no URL, then not a link, so just display self.name as text + tags.append(self.name) - # TODO(tlarsen): implement the mouse-over support for item.help_text + # TODO(tlarsen): implement the mouse-over support for item.annotation if self.sub_menu: tags.extend(self.sub_menu.getHtmlTags(indent + ' ')) @@ -122,16 +122,16 @@ """Provides HTML menu item properties as attributes as an
  • list item. """ - def __init__(self, text, url=None, selected=False, help_text=None, + def __init__(self, text, value=None, selected=False, annotation=None, sub_menu=None): """Initializes the menu item attributes from supplied arguments. Args: - text, url, selected, help_text, sub_menu: + text, value, selected, annotation, sub_menu: see AHrefMenuItem.__init__() """ - AHrefMenuItem.__init__(self, text, url=url, selected=selected, - help_text=help_text, sub_menu=sub_menu) + AHrefMenuItem.__init__(self, text, value=value, selected=selected, + annotation=annotation, sub_menu=sub_menu) def getHtmlTags(self, indent): """Returns link wrapped as an
  • list item.