[Erp5-report] r10338 - in /erp5/trunk/products/ERP5OOo: Constraint/ PropertySheet/

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Sep 26 18:39:31 CEST 2006


Author: bartek
Date: Tue Sep 26 18:39:28 2006
New Revision: 10338

URL: http://svn.erp5.org?rev=10338&view=rev
Log:
triplet uniqueness check using Constraint (#20)

Added:
    erp5/trunk/products/ERP5OOo/Constraint/
    erp5/trunk/products/ERP5OOo/Constraint/DocumentCoordinatesConstraint.py
Modified:
    erp5/trunk/products/ERP5OOo/PropertySheet/DMSFile.py

Added: erp5/trunk/products/ERP5OOo/Constraint/DocumentCoordinatesConstraint.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5OOo/Constraint/DocumentCoordinatesConstraint.py?rev=10338&view=auto
==============================================================================
--- erp5/trunk/products/ERP5OOo/Constraint/DocumentCoordinatesConstraint.py (added)
+++ erp5/trunk/products/ERP5OOo/Constraint/DocumentCoordinatesConstraint.py Tue Sep 26 18:39:28 2006
@@ -1,0 +1,64 @@
+##############################################################################
+#
+# Copyright (c) 2006 Nexedi SARL and Contributors. All Rights Reserved.
+#          Jerome Perrin <jerome at 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 

Modified: erp5/trunk/products/ERP5OOo/PropertySheet/DMSFile.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5OOo/PropertySheet/DMSFile.py?rev=10338&r1=10337&r2=10338&view=diff
==============================================================================
--- erp5/trunk/products/ERP5OOo/PropertySheet/DMSFile.py (original)
+++ erp5/trunk/products/ERP5OOo/PropertySheet/DMSFile.py Tue Sep 26 18:39:28 2006
@@ -31,23 +31,17 @@
   """
 
   _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




More information about the Erp5-report mailing list