Commit 457fa183 authored by Bartek Górny's avatar Bartek Górny

triplet uniqueness check using Constraint (#20)

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@10339 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 70d32870
......@@ -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>
......
194
\ No newline at end of file
196
\ No newline at end of file
##############################################################################
#
# 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
......@@ -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
......
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