Commit 6890aa5c authored by Jean-Paul Smets's avatar Jean-Paul Smets

Naming convention: SQL should be in big caps.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11869 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent cdac6e8d
......@@ -414,15 +414,15 @@ class Category(Folder):
"""
return context.isMemberOf(self.getCategoryName())
security.declareProtected( Permissions.AccessContentsInformation, 'asSqlExpression' )
def asSqlExpression(self, strict_membership=0, table='category', base_category = None):
security.declareProtected( Permissions.AccessContentsInformation, 'asSQLExpression' )
def asSQLExpression(self, strict_membership=0, table='category', base_category = None):
"""
A Predicate can be rendered as an sql expression. This
can be useful to create reporting trees based on the
ZSQLCatalog
"""
#LOG('Category.asSqlExpression self', 0, str(self))
#LOG('asSqlExpression parent', 0, str(self.aq_parent))
#LOG('Category.asSQLExpression self', 0, str(self))
#LOG('asSQLExpression parent', 0, str(self.aq_parent))
if base_category is None:
base_category = self
elif type(base_category) is type('a'):
......@@ -437,7 +437,7 @@ class Category(Folder):
(table, self.getUid(), table, base_category.getBaseCategoryUid())
# Now useless since we precompute the mapping
#for o in self.objectValues():
# sql_text += ' OR %s' % o.asSqlExpression()
# sql_text += ' OR %s' % o.asSQLExpression()
return sql_text
# A Category's categories is self
......@@ -553,7 +553,7 @@ class BaseCategory(Category):
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
def asSqlExpression(self, strict_membership=0, table='category', base_category=None):
def asSQLExpression(self, strict_membership=0, table='category', base_category=None):
"""
A Predicate can be rendered as an sql expression. This
can be useful to create reporting trees based on the
......@@ -568,7 +568,7 @@ class BaseCategory(Category):
(table, self.uid, table, self.uid)
# Now useless since we precompute the mapping
#for o in self.objectValues():
# sql_text += ' OR %s' % o.asSqlExpression()
# sql_text += ' OR %s' % o.asSQLExpression()
return sql_text
security.declareProtected(Permissions.AccessContentsInformation,
......
......@@ -84,7 +84,7 @@ class Filter(Implicit):
"""
return self.filter_dict
def asSql(self):
def asSQL(self):
"""
Returns an SQL expression which can be used as a query
"""
......
......@@ -51,7 +51,7 @@ class Predicate(Interface):
"""
pass
def asSqlExpression():
def asSQLExpression():
"""
A Predicate can be rendered as an sql expression. This
can be useful to create reporting trees based on the
......
......@@ -235,7 +235,7 @@ class SimulationTool (BaseTool):
# keywords for related keys
**kw):
"""
generates keywords and calls buildSqlQuery
generates keywords and calls buildSQLQuery
"""
new_kw = {}
new_kw.update(kw)
......@@ -575,7 +575,7 @@ class SimulationTool (BaseTool):
**kw - if we want extended selection with more keywords (but
bad performance) check what we can do with
buildSqlQuery
buildSQLQuery
NOTE: we may want to define a parameter so that we can select the kind of
inventory statistics we want to display (ex. sum, average, cost, etc.)
......@@ -1040,7 +1040,7 @@ class SimulationTool (BaseTool):
selection_domain, selection_report - see ListBox
**kw - if we want extended selection with more keywords (but bad performance)
check what we can do with buildSqlQuery
check what we can do with buildSQLQuery
Extra parameters for getTrackingList :
......
......@@ -1381,7 +1381,7 @@ class TestAccountingRules(TestAccountingRulesMixin, ERP5TypeTestCase):
self.failUnless(self.getCategoryTool() != None)
self.failUnless(self.getSimulationTool() != None)
self.failUnless(self.getTypeTool() != None)
self.failUnless(self.getSqlConnection() != None)
self.failUnless(self.getSQLConnection() != None)
self.failUnless(self.getCatalogTool() != None)
self.failUnless(self.getRuleTool() != None)
self.failUnless(self.getAccountModule() != None)
......
......@@ -89,7 +89,7 @@ class TestAlarm(ERP5TypeTestCase):
self.failUnless(self.getCategoryTool()!=None)
self.failUnless(self.getSimulationTool()!=None)
self.failUnless(self.getTypeTool()!=None)
self.failUnless(self.getSqlConnection()!=None)
self.failUnless(self.getSQLConnection()!=None)
self.failUnless(self.getCatalogTool()!=None)
#def populate(self, quiet=1, run=1):
......
......@@ -83,7 +83,7 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
portal = self.getPortal()
catalog_tool = self.getCatalogTool()
# create the fake catalog table
sql_connection = self.getSqlConnection()
sql_connection = self.getSQLConnection()
sql = 'create table if not exists `fake_catalog` (`toto` BIGINT)'
sql_connection.manage_test(sql)
self._catch_log_errors()
......
......@@ -100,31 +100,31 @@ class Test(ERP5TypeTestCase):
user = uf.getUserById(username).__of__(uf)
newSecurityManager(None, user)
def getSqlPathList(self):
def getSQLPathList(self):
"""
Give the full list of path in the catalog
"""
sql_connection = self.getSqlConnection()
sql_connection = self.getSQLConnection()
sql = 'select path from catalog'
result = sql_connection.manage_test(sql)
path_list = map(lambda x: x['path'],result)
return path_list
def checkRelativeUrlInSqlPathList(self,url_list):
path_list = self.getSqlPathList()
def checkRelativeUrlInSQLPathList(self,url_list):
path_list = self.getSQLPathList()
portal_id = self.getPortalId()
for url in url_list:
path = '/' + portal_id + '/' + url
self.failUnless(path in path_list)
LOG('checkRelativeUrlInSqlPathList found path:',0,path)
LOG('checkRelativeUrlInSQLPathList found path:',0,path)
def checkRelativeUrlNotInSqlPathList(self,url_list):
path_list = self.getSqlPathList()
def checkRelativeUrlNotInSQLPathList(self,url_list):
path_list = self.getSQLPathList()
portal_id = self.getPortalId()
for url in url_list:
path = '/' + portal_id + '/' + url
self.failUnless(path not in path_list)
LOG('checkRelativeUrlInSqlPathList not found path:',0,path)
LOG('checkRelativeUrlInSQLPathList not found path:',0,path)
def test_01_StandardSearchFolder(self, quiet=0, run=run_all_test):
......
......@@ -84,31 +84,31 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
user = uf.getUserById('seb').__of__(uf)
newSecurityManager(None, user)
def getSqlPathList(self):
def getSQLPathList(self):
"""
Give the full list of path in the catalog
"""
sql_connection = self.getSqlConnection()
sql_connection = self.getSQLConnection()
sql = 'select path from catalog'
result = sql_connection.manage_test(sql)
path_list = map(lambda x: x['path'],result)
return path_list
def checkRelativeUrlInSqlPathList(self,url_list):
path_list = self.getSqlPathList()
def checkRelativeUrlInSQLPathList(self,url_list):
path_list = self.getSQLPathList()
portal_id = self.getPortalId()
for url in url_list:
path = '/' + portal_id + '/' + url
self.failUnless(path in path_list)
LOG('checkRelativeUrlInSqlPathList found path:',0,path)
LOG('checkRelativeUrlInSQLPathList found path:',0,path)
def checkRelativeUrlNotInSqlPathList(self,url_list):
path_list = self.getSqlPathList()
def checkRelativeUrlNotInSQLPathList(self,url_list):
path_list = self.getSQLPathList()
portal_id = self.getPortalId()
for url in url_list:
path = '/' + portal_id + '/' + url
self.failUnless(path not in path_list)
LOG('checkRelativeUrlInSqlPathList not found path:',0,path)
LOG('checkRelativeUrlInSQLPathList not found path:',0,path)
def test_01_HasEverything(self, quiet=quiet, run=run_all_test):
if not run: return
......@@ -118,7 +118,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
self.failUnless(self.getCategoryTool()!=None)
self.failUnless(self.getSimulationTool()!=None)
self.failUnless(self.getTypeTool()!=None)
self.failUnless(self.getSqlConnection()!=None)
self.failUnless(self.getSQLConnection()!=None)
self.failUnless(self.getCatalogTool()!=None)
def test_02_EverythingCatalogued(self, quiet=quiet, run=run_all_test):
......@@ -141,37 +141,37 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
person_module = self.getPersonModule()
person = person_module.newContent(id='1',portal_type='Person')
path_list = [person.getRelativeUrl()]
self.checkRelativeUrlNotInSqlPathList(path_list)
self.checkRelativeUrlNotInSQLPathList(path_list)
person.immediateReindexObject()
self.checkRelativeUrlInSqlPathList(path_list)
self.checkRelativeUrlInSQLPathList(path_list)
person_module.manage_delObjects('1')
get_transaction().commit()
self.tic()
self.checkRelativeUrlNotInSqlPathList(path_list)
self.checkRelativeUrlNotInSQLPathList(path_list)
# Now we will ask to immediatly reindex
person = person_module.newContent(id='2',
portal_type='Person',
immediate_reindex=1)
path_list = [person.getRelativeUrl()]
self.checkRelativeUrlInSqlPathList(path_list)
self.checkRelativeUrlInSQLPathList(path_list)
person.immediateReindexObject()
self.checkRelativeUrlInSqlPathList(path_list)
self.checkRelativeUrlInSQLPathList(path_list)
person_module.manage_delObjects('2')
get_transaction().commit()
self.tic()
self.checkRelativeUrlNotInSqlPathList(path_list)
self.checkRelativeUrlNotInSQLPathList(path_list)
# Now we will try with the method deleteContent
person = person_module.newContent(id='3',portal_type='Person')
path_list = [person.getRelativeUrl()]
self.checkRelativeUrlNotInSqlPathList(path_list)
self.checkRelativeUrlNotInSQLPathList(path_list)
person.immediateReindexObject()
self.checkRelativeUrlInSqlPathList(path_list)
self.checkRelativeUrlInSQLPathList(path_list)
person_module.deleteContent('3')
# Now delete things is made with activities
self.checkRelativeUrlNotInSqlPathList(path_list)
self.checkRelativeUrlNotInSQLPathList(path_list)
get_transaction().commit()
self.tic()
self.checkRelativeUrlNotInSqlPathList(path_list)
self.checkRelativeUrlNotInSQLPathList(path_list)
def test_04_SearchFolderWithDeletedObjects(self, quiet=quiet, run=run_all_test):
if not run: return
......@@ -401,7 +401,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
# Clear catalog
portal_catalog = self.getCatalogTool()
portal_catalog.manage_catalogClear()
sql_connection = self.getSqlConnection()
sql_connection = self.getSQLConnection()
sql = 'select count(*) from catalog where portal_type!=NULL'
result = sql_connection.manage_test(sql)
message_count = result[0]['COUNT(*)']
......@@ -419,7 +419,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
message_count = result[0]['COUNT(*)']
self.assertEquals(0, message_count)
# Check if object are catalogued
self.checkRelativeUrlInSqlPathList([
self.checkRelativeUrlInSQLPathList([
organisation.getRelativeUrl(),
'portal_categories/%s' % base_category.getRelativeUrl()])
......@@ -454,7 +454,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
# Clear catalog
portal_catalog = self.getCatalogTool()
portal_catalog.manage_catalogClear()
sql_connection = self.getSqlConnection()
sql_connection = self.getSQLConnection()
sql = 'SELECT COUNT(*) FROM category '\
'WHERE uid=%s and category_strict_membership = 1' %\
......@@ -521,7 +521,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
LOG('Testing... ',0,message)
portal_catalog = self.getCatalogTool()
portal = self.getPortal()
sql_connection = self.getSqlConnection()
sql_connection = self.getSQLConnection()
module = portal.getDefaultModule('Organisation')
organisation = module.newContent(portal_type='Organisation',)
......@@ -821,7 +821,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
portal_type='Person',
immediate_reindex=1)
path_list = [person.getRelativeUrl()]
self.checkRelativeUrlInSqlPathList(path_list)
self.checkRelativeUrlInSQLPathList(path_list)
# We will delete the connector
# in order to make sure it will not work any more
portal = self.getPortal()
......@@ -1239,7 +1239,7 @@ class TestERP5Catalog(ERP5TypeTestCase, LogInterceptor):
get_transaction().commit()
self.tic()
path_list = [new_person.getRelativeUrl()]
self.checkRelativeUrlInSqlPathList(path_list)
self.checkRelativeUrlInSQLPathList(path_list)
def test_44_ParentRelatedKeys(self, quiet=quiet, run=run_all_test):
if not run: return
......
......@@ -1150,7 +1150,7 @@ class Base( CopyContainer,
"""
return self
def asSqlExpression(self, strict_membership=0, table='category', base_category = None):
def asSQLExpression(self, strict_membership=0, table='category', base_category = None):
"""
Any document can be used as a Category. It can therefore
serve in a Predicate and must be rendered as an sql expression. This
......@@ -1171,8 +1171,8 @@ class Base( CopyContainer,
return sql_text
security.declareProtected( Permissions.AccessContentsInformation,
'getParentSqlExpression' )
def getParentSqlExpression(self, table = 'catalog', strict_membership = 0):
'getParentSQLExpression' )
def getParentSQLExpression(self, table = 'catalog', strict_membership = 0):
"""
Builds an SQL expression to search children and subclidren
"""
......@@ -1767,6 +1767,21 @@ class Base( CopyContainer,
"""
return self.title_and_id()
security.declareProtected(Permissions.AccessContentsInformation,
'getTranslatedShortTitleOrId')
def getTranslatedShortTitleOrId(self):
"""
Returns the translated title or the id if the id is empty
"""
title = self.getTranslatedTitle()
if title is not None:
title = str(title)
if title == '' or title is None:
return self.getId()
else:
return title
return self.getId()
security.declareProtected(Permissions.AccessContentsInformation,
'getTranslatedTitleOrId')
def getTranslatedTitleOrId(self):
......
......@@ -726,18 +726,18 @@ class Folder( CopyContainer, CMFBTreeFolder, Base, FolderMixIn):
getObjectIds = CMFBTreeFolder.objectIds
# Overloading
security.declareProtected( Permissions.AccessContentsInformation, 'getParentSqlExpression' )
def getParentSqlExpression(self, table = 'catalog', strict_membership = 0):
security.declareProtected( Permissions.AccessContentsInformation, 'getParentSQLExpression' )
def getParentSQLExpression(self, table = 'catalog', strict_membership = 0):
"""
Builds an SQL expression to search children and subclidren
"""
if strict_membership:
return Base.getParentSqlExpression(self, table=table, strict_membership=strict_membership)
return Base.getParentSQLExpression(self, table=table, strict_membership=strict_membership)
result = "%s.parent_uid = %s" % (table, self.getUid())
for o in self.objectValues():
if hasattr(aq_base(o), 'objectValues'):
# Do not consider non folder objects
result = "%s OR %s" % (result, o.getParentSqlExpression(table=table, strict_membership=strict_membership))
result = "%s OR %s" % (result, o.getParentSQLExpression(table=table, strict_membership=strict_membership))
return "( %s )" % result
......
......@@ -399,7 +399,7 @@ class ERP5TypeTestCase(PortalTestCase):
def getSimulationTool(self):
return getToolByName(self.getPortal(), 'portal_simulation', None)
def getSqlConnection(self):
def getSQLConnection(self):
return getToolByName(self.getPortal(), 'erp5_sql_connection', None)
def getPortalId(self):
......
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