Skip to content

Commit

Permalink
Added improved method to set defaults in extension module information
Browse files Browse the repository at this point in the history
  • Loading branch information
rshk committed Nov 28, 2011
1 parent d226923 commit a3e929c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 36 deletions.
18 changes: 13 additions & 5 deletions web2py/applications/w2cms/modules/cms_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
'''

__all__ = [
'cms_component',
'ExtensionsManager',
'CustomController',
'NodeTypeManager',
'DynamicBlock',
'ExtensionsManager',
'cms_component',
]
]


from gluon import current
import os
Expand Down Expand Up @@ -71,6 +72,7 @@ def load_module(self, name):
:type name: string
"""
import imp
from helpers import recursive_update

## Find the module in the search path
## Returns (file, pathname, description)
Expand All @@ -90,7 +92,11 @@ def load_module(self, name):
package = 'Misc',
),
)
module_info.update(module.cms_module_info)

#module_info.update(module.cms_module_info)
recursive_update(module_info, module.cms_module_info)

## Retrieve components
components = {}
for m_object in dir(module):
obj = getattr(module, m_object)
Expand All @@ -99,6 +105,8 @@ def load_module(self, name):
if not components.has_key(c_info['type']):
components[c_info['type']] = {}
components[c_info['type']][m_object] = obj

## Return information about the module
return dict(
name=name,
module=module,
Expand Down Expand Up @@ -169,7 +177,7 @@ def disable(self, name):
self.enable(name, False)

def get_components(self, c_type):
"""Get all components of a given type from enabled modules.
"""Get all components of a given type from the enabled modules.
:param c_type: The type of interesting component
:return: A list of tuples: ``('module/component', ComponentObject)``
Expand Down
70 changes: 39 additions & 31 deletions web2py/applications/w2cms/modules/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,44 +29,52 @@ def get_region_content(region_name, custom_db=None, request_context=None):
'my_example_region'
:param request_context: The ``request`` object. Defaults to current.request
"""

if request_context is None:
request_context = current.request

if custom_db is None and 'db' in globals():
custom_db = db

blocks = db(db.block.region==region_name).select(db.block.ALL, orderby=db.block.weight)

if blocks:
return XML("\n".join([
current.response.render('generic/block.html', dict(block=block))
for block in blocks
]))

return ''
raise DeprecationWarning
#
# if request_context is None:
# request_context = current.request
#
# if custom_db is None and 'db' in globals():
# custom_db = db
#
# blocks = db(db.block.region==region_name).select(db.block.ALL, orderby=db.block.weight)
#
# if blocks:
# return XML("\n".join([
# current.response.render('generic/block.html', dict(block=block))
# for block in blocks
# ]))
#
# return ''

def get_region(region_name, custom_db=None, request_context=None):
"""For HTML requests only, return the region content wrapper in a <div>,
if any content is present, or an empty string if not.
"""
if request_context is None:
request_context = current.request

region_content = get_region_content(
region_name=region_name,
custom_db=custom_db,
request_context=request_context)
if region_content:
if request_context.extension == 'html':
return DIV(region_content, _id=region_name)
return ""
raise DeprecationWarning
# if request_context is None:
# request_context = current.request
#
# region_content = get_region_content(
# region_name=region_name,
# custom_db=custom_db,
# request_context=request_context)
# if region_content:
# if request_context.extension == 'html':
# return DIV(region_content, _id=region_name)
# return ""


def get_comments(db, obj_type, obj_delta):
"""Get list of comments to a given object"""
return db(
(db.comment.object_type == obj_type),
#db.comment.object_delta == obj_delta
).select(orderby=~db.comment.created)
raise DeprecationWarning

def recursive_update(d1,d2):
"""Recursively update a dictionary or dict-like object."""
if not hasattr(d2, '__getitem__'):
raise ValueError, "d2 is not a dict-like"
for k in d2.keys():
try:
recursive_update(d1[k], d2[k])
except:
d1[k] = d2[k]

0 comments on commit a3e929c

Please sign in to comment.