diff --git a/bt5/erp5_dms/WorkflowTemplateItem/portal_workflow/document_publication_workflow/scripts/checkUniqueCoordinates.xml b/bt5/erp5_dms/WorkflowTemplateItem/portal_workflow/document_publication_workflow/scripts/checkUniqueCoordinates.xml index fea77ceba02833f53e9fc395b73d53082e1c33a2..340602b42bc1c85b960c2c9dcb967ea881abed42 100644 --- a/bt5/erp5_dms/WorkflowTemplateItem/portal_workflow/document_publication_workflow/scripts/checkUniqueCoordinates.xml +++ b/bt5/erp5_dms/WorkflowTemplateItem/portal_workflow/document_publication_workflow/scripts/checkUniqueCoordinates.xml @@ -74,17 +74,11 @@ from Products.DCWorkflow.DCWorkflow import ValidationFailed\n \n err=\'\'\n o=state_change.object\n -for req in (\'reference\', \'language\', \'version\'):\n - if o.getProperty(req) is None or o.getProperty(req)==\'\':\n - err+=\'E: %s is None \' % req\n -if err:\n - raise ValidationFailed(err)\n -res=context.portal_catalog(reference=o.getReference(),language=o.getLanguage(),version=o.getVersion(),portal_type=context.getPortalDocumentTypeList())\n -res=list(res)\n -if len(res)==2: # this and the other one\n - raise ValidationFailed(\'E: another object %s - %s - %s exists\' % (o.getReference(),o.getLanguage(),o.getVersion()))\n -if len(res)>2:\n - raise Exception(\'Fatal error: multiple objects %s - %s - %s exist\' % (o.getReference(),o.getLanguage(),o.getVersion()))\n +res=o.checkConsistency()\n +res=[c for c in res if c[1]==\'DocumentCoordinatesConstraint inconsistency\']\n +if len(res)>0:\n + msg=\'<br/>\'.join(str(c[3]) for c in res)\n + raise ValidationFailed(msg)\n ]]></string> </value> @@ -135,14 +129,14 @@ if len(res)>2:\n <string>err</string> <string>_getattr_</string> <string>o</string> - <string>_getiter_</string> - <string>req</string> - <string>None</string> - <string>context</string> <string>res</string> - <string>list</string> + <string>append</string> + <string>$append0</string> + <string>_getiter_</string> + <string>c</string> + <string>_getitem_</string> <string>len</string> - <string>Exception</string> + <string>msg</string> </tuple> </value> </item> diff --git a/bt5/erp5_dms/bt/revision b/bt5/erp5_dms/bt/revision index 4be28fd89c294b35df49187879b2fe9bce6997ae..412965750910b48d20bc79b925a1cc30685a9d64 100644 --- a/bt5/erp5_dms/bt/revision +++ b/bt5/erp5_dms/bt/revision @@ -1 +1 @@ -194 \ No newline at end of file +196 \ No newline at end of file diff --git a/product/ERP5OOo/Constraint/DocumentCoordinatesConstraint.py b/product/ERP5OOo/Constraint/DocumentCoordinatesConstraint.py new file mode 100644 index 0000000000000000000000000000000000000000..24f0e6e3cc281581dc82fc9723911babaf799b3d --- /dev/null +++ b/product/ERP5OOo/Constraint/DocumentCoordinatesConstraint.py @@ -0,0 +1,64 @@ +############################################################################## +# +# Copyright (c) 2006 Nexedi SARL and Contributors. All Rights Reserved. +# Jerome Perrin <jerome@nexedi.com> +# +# 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. +# +############################################################################## + +from Products.ERP5Type.Constraint import Constraint +from Products.ERP5Type.Message import Message +N_ = lambda msg, **kw: Message('erp5_ui', msg, **kw) +_MARKER = [] + +class DocumentCoordinatesConstraint(Constraint): + """ + We check if the document has all required coordinates (reference, + version and language) and that it there is no other doc with + the same coordinates + we do not fix (although we could, e.g. change version number) + """ + + def checkConsistency(self, o, fixit=0): + """Implement here the consistency checker + """ + errors = [] + + for req in ('reference', 'language', 'version'): + if o.getProperty(req) is None or o.getProperty(req)=='': + s='%s is None ' % req + errors.append(self._generateError(o, N_(s))) + if errors: + return errors + res=o.portal_catalog(reference=o.getReference(),language=o.getLanguage(),version=o.getVersion(),portal_type=o.getPortalDocumentTypeList()) + res=list(res) + if len(res)==2: # this and the other one + s='E: another object %s - %s - %s exists' % (o.getReference(),o.getLanguage(),o.getVersion()) + errors.append(self._generateError(o, N_(s))) + if len(res)>2: # this is very serious + raise Exception('Fatal error: multiple objects %s - %s - %s exist' % (o.getReference(),o.getLanguage(),o.getVersion())) + errors.append(self._generateError(o, N_(s))) + return errors + + +# vim: filetype=python syntax=python shiftwidth=2 diff --git a/product/ERP5OOo/PropertySheet/DMSFile.py b/product/ERP5OOo/PropertySheet/DMSFile.py index 7d78660f476348bb959019c19b9c02341d9e7345..a88bce06add270c0138e6d57daa4a5d18f13d818 100644 --- a/product/ERP5OOo/PropertySheet/DMSFile.py +++ b/product/ERP5OOo/PropertySheet/DMSFile.py @@ -31,23 +31,17 @@ class DMSFile: """ _properties = ( - { 'id' : 'contributor_related_title', - 'description' : 'Contributors linked by relation', - 'type' : 'string', - 'acquisition_base_category' : ('contributor_related',), - 'acquisition_portal_type' : ('Person','Organisation'), - 'acquisition_copy_value' : 0, - 'acquisition_accessor_id' : 'getTitle', - 'acquisition_depends' : None, - 'mode' : 'r' }, - { 'id' : 'contributor_name', - 'description' : 'contributors entered by hand', - 'type' : 'lines', - 'mode' : ''}, ) _categories = ('destination','similar','predecessor','successor','source_project','publication_section','classification', - 'contributor_related','function','group','site') + 'contributor','function','group','site') + + _constraints = ( + { + 'id' : 'unique_coordinates', + 'description':'coordinate triplet must be complete and unique', + 'type':'DocumentCoordinatesConstraint'}, + ) # vim: shiftwidth=2