diff --git a/bt5/erp5_dms/ExtensionTemplateItem/cutFound.py b/bt5/erp5_dms/ExtensionTemplateItem/DocumentExtraction.py similarity index 53% rename from bt5/erp5_dms/ExtensionTemplateItem/cutFound.py rename to bt5/erp5_dms/ExtensionTemplateItem/DocumentExtraction.py index 7693f7c74a465be643ff06647da432deb332eff1..f8e841ad5d560ddedca97b30f267da050cb53e7e 100644 --- a/bt5/erp5_dms/ExtensionTemplateItem/cutFound.py +++ b/bt5/erp5_dms/ExtensionTemplateItem/DocumentExtraction.py @@ -1,3 +1,30 @@ +############################################################################## +# +# Copyright (c) 2006-2007 Nexedi SA and Contributors. All Rights Reserved. +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# garantees and support are strongly adviced to contract a Free Software +# Service Company +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +############################################################################## + import string, re redundant_chars='"\'.:;,-+<>()*~' # chars we need to strip from a word before we see if it matches, and from the searchwords to eliminate boolean mode chars @@ -64,18 +91,22 @@ def generateParts(context,text,sw,tags,trail,maxlines): yield par # return the last marked part -def cutFound(context,txt,sw,tags,trail,maxlines): +def cutFound(context, txt, sw, tags, trail, maxlines): + """ + Returns an excerpt of text found in the txt string + """ + txt = str(txt) # initialize class FoundWord.tags=tags # strip html tags (in case it is a web page - we show result without formatting) - r=re.compile('<script>.*?</script>',re.DOTALL|re.IGNORECASE) - r=re.compile('<head>.*?</head>',re.DOTALL|re.IGNORECASE) - txt=re.sub(r,'',txt) - r=re.compile('<([^>]+)>',re.DOTALL|re.IGNORECASE) - txt=re.sub(r,'',txt) - r=re.compile('\s+') - txt=re.sub(r,' ',txt) - txt=txt.replace('-',' - ') # to find hyphenated occurrences + r = re.compile('<script>.*?</script>',re.DOTALL|re.IGNORECASE) + r = re.compile('<head>.*?</head>',re.DOTALL|re.IGNORECASE) + txt = re.sub(r,'',txt) + r = re.compile('<([^>]+)>',re.DOTALL|re.IGNORECASE) + txt = re.sub(r,'',txt) + r = re.compile('\s+') + txt = re.sub(r,' ',txt) + txt = txt.replace('-',' - ') # to find hyphenated occurrences text = ' '.join(txt.split('\n')).split(' ') # very rough tokenization return [p for p in generateParts(context,text,sw,tags,trail,maxlines)] diff --git a/bt5/erp5_dms/ExtensionTemplateItem/documentUtils.py b/bt5/erp5_dms/ExtensionTemplateItem/DocumentManagement.py similarity index 55% rename from bt5/erp5_dms/ExtensionTemplateItem/documentUtils.py rename to bt5/erp5_dms/ExtensionTemplateItem/DocumentManagement.py index 2226a3135c53455b5c98bf135010a179adbc92bf..79e7cf27fb8a650a2d2210617b82035b8f56b198 100644 --- a/bt5/erp5_dms/ExtensionTemplateItem/documentUtils.py +++ b/bt5/erp5_dms/ExtensionTemplateItem/DocumentManagement.py @@ -1,3 +1,30 @@ +############################################################################## +# +# Copyright (c) 2006-2007 Nexedi SA and Contributors. All Rights Reserved. +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# garantees and support are strongly adviced to contract a Free Software +# Service Company +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +############################################################################## + import zipfile, cStringIO, re import xmlrpclib, base64 from Products.CMFCore.utils import getToolByName @@ -74,4 +101,28 @@ def getLastWorkflowDate(self, state_name='simulation_state', state=('released',' return ch['time'] return 0 -# vim: syntax=python shiftwidth=2 +############################################################################# +# Mail management + +def findAddress(txt): + """ + find email address in a string + """ + validchars='0-9A-Za-z.\-_' + r=re.compile('[%s]+@[%s]+' % (validchars,validchars)) + m=r.search(txt) + return m and m.group() + +def extractParams(txt): + """ + extract parameters given in mail body + We assume that parameters are given as lines of the format: + name:value + """ + r=re.compile('^([\w_]+):([\w_/]+)$') + res=[] + for line in txt.split(): + found=r.findall(line.strip()) + if len(found)==1: + res.append(found[0]) + return dict(res) diff --git a/bt5/erp5_dms/ExtensionTemplateItem/searchUtils.py b/bt5/erp5_dms/ExtensionTemplateItem/DocumentSearch.py similarity index 70% rename from bt5/erp5_dms/ExtensionTemplateItem/searchUtils.py rename to bt5/erp5_dms/ExtensionTemplateItem/DocumentSearch.py index 41c2a1fd6d4f3b6e90deeed126d7348509c18cdd..e06f453ecea11c160c15958763b2b3209ea2295b 100644 --- a/bt5/erp5_dms/ExtensionTemplateItem/searchUtils.py +++ b/bt5/erp5_dms/ExtensionTemplateItem/DocumentSearch.py @@ -1,3 +1,30 @@ +############################################################################## +# +# Copyright (c) 2006-2007 Nexedi SA and Contributors. All Rights Reserved. +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# garantees and support are strongly adviced to contract a Free Software +# Service Company +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +############################################################################## + """ RULES diff --git a/bt5/erp5_dms/ExtensionTemplateItem/asSecurityGroupId.py b/bt5/erp5_dms/ExtensionTemplateItem/asSecurityGroupId.py deleted file mode 100644 index fbec02a675310813c8e11be45b5bd3d694e4a1af..0000000000000000000000000000000000000000 --- a/bt5/erp5_dms/ExtensionTemplateItem/asSecurityGroupId.py +++ /dev/null @@ -1,65 +0,0 @@ -def asSecurityGroupId(self,**kw): - ## Script (Python) "xERP5Type_asSecurityGroupId" - ##bind container=container - ##bind self=self - ##bind namespace= - ##bind script=script - ##bind subpath=traverse_subpath - ##parameters=category_order, **kw - ##title= - ## - # category_order : list of base_categories we want to use to generate the group id - # kw : keys should be base categories, - # values should be value of corresponding relative urls (obtained by getBaseCategory()) - # - # Example call : self.ERP5TypeSecurity_asGroupId(category_order=('site', 'group', 'function'), - # site='france/lille', group='nexedi', function='accounting/accountant') - # This will generate a string like 'LIL_NXD_ACT' where "LIL", "NXD" and "ACT" are the codification - # of respecively "france/lille", "nexedi" and "accounting/accountant" categories - # - # ERP5Type_asSecurityGroupId can also return a list of users whenever a category points - # to a Person instance. This is useful to implement user based local role assignments - - - code_list = [] - user_list = [] - - # sort the category list lexicographically - # this prevents us to choose the exact order we want, - # but also prevents some human mistake to break everything by creating site_function instead of function_site - category_order=kw.get('category_order',None) - if category_order not in (None, ''): - category_order = list(category_order) - category_order.sort() - else: - category_order = [] - - for base_category in category_order: - if kw.has_key(base_category): - category_list = kw[base_category] - if type(category_list)==type(''): - category_list = [category_list] - for category in category_list: - category_path = '%s/%s' % (base_category, category) - category_object = self.portal_categories.getCategoryValue(category_path) - if category_object in (None, ''): - raise "SecurityRoleDefinitionError", "Category '%s' doesn't exist" % (category_path) - if category_object.getPortalType() == 'Person': - # We define a person here - user_name = category_object.getReference() - if user_name is not None: user_list.append(user_name) - elif category_object.getPortalType() == 'Project': - # We use the project reference as a group - category_code = category_object.getReference(category_object.getTitle()) - code_list.append(category_code) - else: - # We define a group item here - category_code = category_object.getCodification() or category_object.getId() - code_list.append(category_code) - - # Return a list of users or a single group - if user_list: - #self.log('user_list',user_list) - return user_list - #self.log('code_list',code_list) - return '_'.join(code_list) diff --git a/bt5/erp5_dms/ExtensionTemplateItem/mailUtils.py b/bt5/erp5_dms/ExtensionTemplateItem/mailUtils.py deleted file mode 100644 index b94b913b271b3d6bb2ffd8144ad7710990854bc0..0000000000000000000000000000000000000000 --- a/bt5/erp5_dms/ExtensionTemplateItem/mailUtils.py +++ /dev/null @@ -1,27 +0,0 @@ -import re - -def findAddress(txt): - """ - find email address in a string - """ - validchars='0-9A-Za-z.\-_' - r=re.compile('[%s]+@[%s]+' % (validchars,validchars)) - m=r.search(txt) - return m and m.group() - -def extractParams(txt): - """ - extract parameters given in mail body - We assume that parameters are given as lines of the format: - name:value - """ - r=re.compile('^([\w_]+):([\w_/]+)$') - res=[] - for line in txt.split(): - found=r.findall(line.strip()) - if len(found)==1: - res.append(found[0]) - return dict(res) - - -# vim: shiftwidth=2 diff --git a/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/Document_getLastWorkflowStateEntryDate.xml b/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/Document_getLastWorkflowStateEntryDate.xml index ec32af542cfe7deb8bd28cf51d0ff4e4b28ac671..033e16f885d0112022b9223d47c4259d3589e262 100644 --- a/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/Document_getLastWorkflowStateEntryDate.xml +++ b/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/Document_getLastWorkflowStateEntryDate.xml @@ -24,7 +24,7 @@ </item> <item> <key> <string>_module</string> </key> - <value> <string>documentUtils</string> </value> + <value> <string>DocumentManagement</string> </value> </item> <item> <key> <string>_owner</string> </key> diff --git a/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/Document_getPropertyDictFromMail.xml b/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/Document_getPropertyDictFromMail.xml index 59e2a2df36337ecbb45bfe0d57725f787f1a6912..e98160f2e01a2eaa6ca207d191cc26edf012a6eb 100644 --- a/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/Document_getPropertyDictFromMail.xml +++ b/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/Document_getPropertyDictFromMail.xml @@ -24,7 +24,7 @@ </item> <item> <key> <string>_module</string> </key> - <value> <string>mailUtils</string> </value> + <value> <string>DocumentManagement</string> </value> </item> <item> <key> <string>_owner</string> </key> diff --git a/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/cutFound.xml b/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/cutFound.xml index f0daf186efd2f1a169bbb2ba30046de1c07f7a1f..d1c305b7df8dc13f089a4bd9fc3644041a77292f 100644 --- a/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/cutFound.xml +++ b/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/cutFound.xml @@ -24,7 +24,7 @@ </item> <item> <key> <string>_module</string> </key> - <value> <string>cutFound</string> </value> + <value> <string>DocumentExtraction</string> </value> </item> <item> <key> <string>id</string> </key> diff --git a/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/findAddress.xml b/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/findAddress.xml index 8c3164415bb19262770a747a64c305c8fa028dd4..b880250f9684c42d398e5cd9b6f982a7f971e5b2 100644 --- a/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/findAddress.xml +++ b/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/findAddress.xml @@ -24,7 +24,7 @@ </item> <item> <key> <string>_module</string> </key> - <value> <string>mailUtils</string> </value> + <value> <string>DocumentManagement</string> </value> </item> <item> <key> <string>id</string> </key> diff --git a/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/parseSearchString.xml b/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/parseSearchString.xml index a92ba998cba468ff482df3f642b5e75a87eac403..4db595b5588c0d566b2d290ad9f4016b2db79c72 100644 --- a/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/parseSearchString.xml +++ b/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/parseSearchString.xml @@ -24,7 +24,7 @@ </item> <item> <key> <string>_module</string> </key> - <value> <string>searchUtils</string> </value> + <value> <string>DocumentSearch</string> </value> </item> <item> <key> <string>id</string> </key> diff --git a/bt5/erp5_dms/bt/template_extension_id_list b/bt5/erp5_dms/bt/template_extension_id_list index 8d620305e5a9ea6f9ad68f0b2f9ba800a2bb3913..30a676212e3c2e16f2ebf09ff8b9fa742b9d860f 100644 --- a/bt5/erp5_dms/bt/template_extension_id_list +++ b/bt5/erp5_dms/bt/template_extension_id_list @@ -1,5 +1,3 @@ -searchUtils -mailUtils -cutFound -asSecurityGroupId -documentUtils \ No newline at end of file +DocumentSearch +DocumentExtraction +DocumentManagement \ No newline at end of file