Commit 39d27455 authored by Jean-Paul Smets's avatar Jean-Paul Smets

Updated aq_dynamic and Predicate for erp5 web.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11891 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e9792acc
...@@ -169,7 +169,8 @@ class Predicate(Folder): ...@@ -169,7 +169,8 @@ class Predicate(Folder):
security.declareProtected( Permissions.AccessContentsInformation, security.declareProtected( Permissions.AccessContentsInformation,
'buildSQLQuery' ) 'buildSQLQuery' )
def buildSQLQuery(self, strict_membership=0, table='category', def buildSQLQuery(self, strict_membership=0, table='category',
join_table='catalog', join_column='uid'): join_table='catalog', join_column='uid',
**kw):
""" """
A Predicate can be rendered as an SQL expression. This A Predicate can be rendered as an SQL expression. This
can be used to generate SQL requests in reports or in can be used to generate SQL requests in reports or in
...@@ -177,6 +178,26 @@ class Predicate(Folder): ...@@ -177,6 +178,26 @@ class Predicate(Folder):
XXX - This method is not implemented yet XXX - This method is not implemented yet
""" """
# Build the identity criterion
catalog_kw = {}
catalog_kw.update(kw) # query_table, REQUEST, ignore_empty_string, **kw
for criterion in self.getCriterionList():
if criterion.min and criterion.max:
catalog_kw[criterion.property] = { 'query' : (criterion.min, criterion.max),
'range' : 'minmax'
}
elif criterion.min:
catalog_kw[criterion.property] = { 'query' : criterion.min,
'range' : 'min'
}
elif criterion.max:
catalog_kw[criterion.property] = { 'query' : criterion.max,
'range' : 'max'
}
else:
catalog_kw[criterion.property] = criterion.identity
portal_catalog = getToolByName(self, 'portal_catalog')
portal_categories = getToolByName(self, 'portal_categories') portal_categories = getToolByName(self, 'portal_categories')
from_table_dict = {} from_table_dict = {}
...@@ -228,9 +249,15 @@ class Predicate(Folder): ...@@ -228,9 +249,15 @@ class Predicate(Folder):
sql_text = ' AND '.join(join_select_list + membership_select_list + sql_text = ' AND '.join(join_select_list + membership_select_list +
multimembership_select_list) multimembership_select_list)
# And now build criteria # Now merge identity and membership criteria
return { 'from_table_list' : from_table_dict.items(), catalog_kw['where_expression'] = sql_text
'where_expression' : sql_text } sql_query = portal_catalog.buildSQLQuery(**catalog_kw)
for alias, table in sql_query['from_table_list']:
if from_table_dict.has_key(alias):
raise KeyError, "The same table is used twice for an identity criterion and for a membership criterion"
from_table_dict[alias] = table
sql_query['from_table_list'] = from_table_dict.items()
return sql_query
security.declareProtected( Permissions.AccessContentsInformation, 'asSQLExpression' ) security.declareProtected( Permissions.AccessContentsInformation, 'asSQLExpression' )
def asSQLExpression(self, strict_membership=0, table='category'): def asSQLExpression(self, strict_membership=0, table='category'):
...@@ -246,6 +273,18 @@ class Predicate(Folder): ...@@ -246,6 +273,18 @@ class Predicate(Folder):
sql_text_list = map(lambda (a,b): '%s AS %s' % (b,a), table_list) sql_text_list = map(lambda (a,b): '%s AS %s' % (b,a), table_list)
return ' , '.join(sql_text_list) return ' , '.join(sql_text_list)
def searchResults(self, **kw):
"""
"""
portal_catalog = getToolByName(self, 'portal_catalog')
return portal_catalog.searchResults(build_sql_query_method=self.buildSQLQuery,**kw)
def countResults(self, REQUEST=None, used=None, **kw):
"""
"""
portal_catalog = getToolByName(self, 'portal_catalog')
return portal_catalog.countResults(build_sql_query_method=self.buildSQLQuery,**kw)
security.declareProtected( Permissions.AccessContentsInformation, 'getCriterionList' ) security.declareProtected( Permissions.AccessContentsInformation, 'getCriterionList' )
def getCriterionList(self, **kw): def getCriterionList(self, **kw):
""" """
......
...@@ -26,19 +26,21 @@ ...@@ -26,19 +26,21 @@
############################################################################## ##############################################################################
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from AccessControl import getSecurityManager from AccessControl.SecurityManagement import getSecurityManager, newSecurityManager, setSecurityManager
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
from Products.ERP5Type import Permissions, PropertySheet,\ from Products.ERP5Type import Permissions, PropertySheet,\
Constraint, Interface, Cache Constraint, Interface, Cache
from Products.ERP5.Document.Domain import Domain from Products.ERP5.Document.Domain import Domain
#from Products.ERP5.Document.WebSite import WebSite
from Acquisition import ImplicitAcquisitionWrapper, aq_base, aq_inner from Acquisition import ImplicitAcquisitionWrapper, aq_base, aq_inner
from Products.ERP5Type.Base import TempBase from Products.ERP5Type.Base import TempBase
from Globals import get_request from Globals import get_request
from zLOG import LOG from zLOG import LOG
from Products.ERP5.Document.WebSite import reserved_name_dict, reserved_name_dict_init, CACHE_KEY, WEBSITE_USER from Products.ERP5.Document.WebSite import reserved_name_dict, reserved_name_dict_init
WEBSECTION_KEY = 'web_section_value' from Products.ERP5.Document.WebSite import CACHE_KEY, WEBSITE_USER, WEBSECTION_KEY, DOCUMENT_NAME_KEY
class WebSection(Domain): class WebSection(Domain):
""" """
...@@ -133,7 +135,7 @@ class WebSection(Domain): ...@@ -133,7 +135,7 @@ class WebSection(Domain):
if user is not None: if user is not None:
old_manager = getSecurityManager() old_manager = getSecurityManager()
newSecurityManager(get_request(), user) newSecurityManager(get_request(), user)
document = self.WebSite_getDocumentValue(portal, name) document = self.WebSite_getDocumentValue(name=name, portal=portal)
request[CACHE_KEY][name] = document request[CACHE_KEY][name] = document
if user is not None: if user is not None:
setSecurityManager(old_manager) setSecurityManager(old_manager)
...@@ -142,4 +144,14 @@ class WebSection(Domain): ...@@ -142,4 +144,14 @@ class WebSection(Domain):
if request[CACHE_KEY].has_key(name): if request[CACHE_KEY].has_key(name):
del request[CACHE_KEY][name] del request[CACHE_KEY][name]
raise raise
if document is not None:
request[DOCUMENT_NAME_KEY] = name
document = aq_base(document.asContext(id=name, # Hide some properties to permit location the original
original_container=document.getParentValue(),
original_id=document.getId(),
editable_absolute_url=document.absolute_url()))
return document return document
security.declareProtected(Permissions.AccessContentsInformation, 'getWebSiteValue')
def getWebSiteValue(self):
return self.getParentValue().getWebSiteValue()
...@@ -62,12 +62,15 @@ class WebSiteTraversalHook(Persistent): ...@@ -62,12 +62,15 @@ class WebSiteTraversalHook(Persistent):
def _physicalPathToVirtualPath(self, path): def _physicalPathToVirtualPath(self, path):
""" """
Remove the path to the VirtualRoot from a physical path Remove the path to the VirtualRoot from a physical path
and add the path to the WebSite is any and add the path to the WebSite if any
""" """
if type(path) is type(''): if type(path) is type(''):
path = path.split( '/') path = path.split( '/')
website_path = self._v_request.get(WEBSECTION_KEY, self._v_request.get(WEBSITE_KEY, None)) # Every Web Section acts as a mini site though layout for document editing is the root layout
#website_path = self._v_request.get(WEBSECTION_KEY, self._v_request.get(WEBSITE_KEY, None))
# Only consider Web Site for absolute_url
website_path = self._v_request.get(WEBSITE_KEY, None)
if website_path: if website_path:
website_path = tuple(website_path) # Make sure all path are tuples website_path = tuple(website_path) # Make sure all path are tuples
path = tuple(path) # Make sure all path are tuples path = tuple(path) # Make sure all path are tuples
...@@ -94,6 +97,10 @@ class WebSiteTraversalHook(Persistent): ...@@ -94,6 +97,10 @@ class WebSiteTraversalHook(Persistent):
i = i + 1 i = i + 1
else: else:
break break
#if self._v_request.has_key(DOCUMENT_NAME_KEY):
# # Replace the last id of the path with the name which
# # was used to lookup the document
# path = path[:-1] + (self._v_request[DOCUMENT_NAME_KEY],)
return path[i:] return path[i:]
def __call__(self, container, request): def __call__(self, container, request):
...@@ -110,6 +117,7 @@ Domain_getattr = Domain.inheritedAttribute('__getattr__') ...@@ -110,6 +117,7 @@ Domain_getattr = Domain.inheritedAttribute('__getattr__')
# Use a request key to store access attributes and prevent infinite recursion # Use a request key to store access attributes and prevent infinite recursion
CACHE_KEY = 'web_site_aq_cache' CACHE_KEY = 'web_site_aq_cache'
DOCUMENT_NAME_KEY = 'web_site_document_name'
reserved_name_dict = { 'getApplicableLayout' : 1, reserved_name_dict = { 'getApplicableLayout' : 1,
'getLayout' : 1, 'getLayout' : 1,
'Localizer' : 1, 'Localizer' : 1,
...@@ -234,7 +242,7 @@ class WebSite(Domain): ...@@ -234,7 +242,7 @@ class WebSite(Domain):
if user is not None: if user is not None:
old_manager = getSecurityManager() old_manager = getSecurityManager()
newSecurityManager(get_request(), user) newSecurityManager(get_request(), user)
document = self.WebSite_getDocumentValue(portal, name) document = self.WebSite_getDocumentValue(name=name, portal=portal)
request[CACHE_KEY][name] = document request[CACHE_KEY][name] = document
if user is not None: if user is not None:
setSecurityManager(old_manager) setSecurityManager(old_manager)
...@@ -243,6 +251,11 @@ class WebSite(Domain): ...@@ -243,6 +251,11 @@ class WebSite(Domain):
if request[CACHE_KEY].has_key(name): if request[CACHE_KEY].has_key(name):
del request[CACHE_KEY][name] del request[CACHE_KEY][name]
raise raise
if document is not None:
document = aq_base(document.asContext(id=name, # Hide some properties to permit location the original
original_container=document.getParentValue(),
original_id=document.getId(),
editable_absolute_url=document.absolute_url()))
return document return document
# Draft - this is being worked on # Draft - this is being worked on
...@@ -273,6 +286,4 @@ class WebSite(Domain): ...@@ -273,6 +286,4 @@ class WebSite(Domain):
Return a list of URLs which exist in the site for Return a list of URLs which exist in the site for
a given document a given document
""" """
pass pass
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment