Move document sidebar entries extraction to document.View
This way other modules can benefit from the same logic. Also make use
of the sidebar.getSidebarMenu method so that getMenusForScope is no
longer specific to full menu's.
Patch by: Sverre Rabbelier
--- a/app/soc/views/models/document.py Sun Dec 07 17:01:44 2008 +0000
+++ b/app/soc/views/models/document.py Sun Dec 07 17:02:10 2008 +0000
@@ -33,6 +33,7 @@
from soc.logic.models import user as user_logic
from soc.views import helper
from soc.views.helper import access
+from soc.views.helper import redirects
from soc.views.models import base
import soc.models.document
@@ -142,6 +143,37 @@
super(View, self)._editGet(request, entity, form)
+ def getMenusForScope(self, entity, params):
+ """Returns the featured menu items for one specifc entity.
+
+ A link to the home page of the specified entity is also included.
+
+ Args:
+ entity: the entity for which the entry should be constructed
+ params: a dict with params for this View.
+ """
+
+ filter = {
+ 'scope_path': entity.key().name(),
+ 'is_featured': True,
+ }
+
+ entities = self._logic.getForFields(filter)
+
+ submenus = []
+
+ # add a link to the home page
+ submenu = (redirects.getPublicRedirect(entity, params), "Home", 'public')
+ submenus.append(submenu)
+
+ # add a link to all featured documents
+ for entity in entities:
+ submenu = (redirects.getPublicRedirect(entity, self._params),
+ entity.short_name, 'public')
+ submenus.append(submenu)
+
+ return submenus
+
view = View()
create = view.create
--- a/app/soc/views/models/program.py Sun Dec 07 17:01:44 2008 +0000
+++ b/app/soc/views/models/program.py Sun Dec 07 17:02:10 2008 +0000
@@ -30,13 +30,13 @@
from soc.logic import cleaning
from soc.logic import dicts
from soc.logic.models import sponsor as sponsor_logic
-from soc.logic.models import document as document_logic
from soc.views import helper
from soc.views.helper import access
from soc.views.helper import redirects
from soc.views.models import base
from soc.views.models import sponsor as sponsor_view
from soc.views.models import document as document_view
+from soc.views.sitemap import sidebar
import soc.logic.models.program
@@ -82,39 +82,6 @@
super(View, self).__init__(params=params)
- def _getItemsForProgram(self, entity, params):
- """Returns the menu items for one specifc program
-
- Args:
- entity: the program for which the entry should be constructed
- params: a dict with params for this View.
- """
-
- filter = {
- 'scope_path': entity.key().name(),
- 'is_featured': True,
- }
-
- doc_params = document_view.view.getParams()
- entities = document_logic.logic.getForFields(filter)
-
- submenus = []
-
- # add a link to the home page
- submenu = {}
- submenu['title'] = "Home"
- submenu['url'] = redirects.getPublicRedirect(entity, params)
- submenus.append(submenu)
-
- # add a link to all featured documents
- for entity in entities:
- submenu = {}
- submenu['title'] = entity.short_name
- submenu['url'] = redirects.getPublicRedirect(entity, doc_params)
- submenus.append(submenu)
-
- return submenus
-
def getExtraMenus(self, request, params=None):
"""Returns the extra menu's for this view.
@@ -137,7 +104,8 @@
for entity in entities:
menu = {}
menu['heading'] = entity.short_name
- menu['items'] = self._getItemsForProgram(entity, params)
+ items = document_view.view.getMenusForScope(entity, params)
+ menu['items'] = sidebar.getSidebarMenu(request, items, params=params)
menus.append(menu)
return menus