[Erp5-report] r37167 ivan - in /erp5/trunk/products/ERP5: Document/ interfaces/ mixin/
nobody at svn.erp5.org
nobody at svn.erp5.org
Fri Jul 16 13:06:01 CEST 2010
Author: ivan
Date: Fri Jul 16 13:05:59 2010
New Revision: 37167
URL: http://svn.erp5.org?rev=37167&view=rev
Log:
Merge UpdateMixIn to CrawableMixin which extends ICrawable interface.
Added:
erp5/trunk/products/ERP5/mixin/crawable.py
Modified:
erp5/trunk/products/ERP5/Document/Document.py
erp5/trunk/products/ERP5/Document/ExternalSource.py
erp5/trunk/products/ERP5/interfaces/crawlable.py
Modified: erp5/trunk/products/ERP5/Document/Document.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/Document.py?rev=37167&r1=37166&r2=37167&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/Document.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/Document.py [utf8] Fri Jul 16 13:05:59 2010
@@ -60,9 +60,11 @@ from Products.ERP5.mixin.text_convertabl
from Products.ERP5.mixin.downloadable import DownloadableMixin
from Products.ERP5.mixin.document import DocumentMixin
from Products.ERP5.mixin.extensible_traversable import DocumentExtensibleTraversableMixIn
+from Products.ERP5.mixin.crawable import CrawableMixin
_MARKER = []
VALID_ORDER_KEY_LIST = ('user_login', 'content', 'file_name', 'input')
+
# these property ids are unchangable
FIXED_PROPERTY_IDS = ('id', 'uid', 'rid', 'sid')
@@ -129,61 +131,8 @@ class DocumentProxyError(Exception):pass
class NotConvertedError(Exception):pass
allow_class(NotConvertedError)
-class UpdateMixIn:
- """
- Provides an API to compute a date index based on the update
- frequency of the document.
- """
-
- # Declarative security
- security = ClassSecurityInfo()
-
- security.declareProtected(Permissions.AccessContentsInformation, 'getFrequencyIndex')
- def getFrequencyIndex(self):
- """
- Returns the document update frequency as an integer
- which is used by alamrs to decide which documents
- must be updates at which time. The index represents
- a time slot (ex. all days in a month, all hours in a week).
- """
- try:
- return self.getUpdateFrequencyValue().getIntIndex()
- except AttributeError:
- # Catch Attribute error or Key error - XXX not beautiful
- return 0
-
- security.declareProtected(Permissions.AccessContentsInformation, 'getCreationDateIndex')
- def getCreationDateIndex(self, at_date = None):
- """
- Returns the document Creation Date Index which is the creation
- date converted into hours modulo the Frequency Index.
- """
- frequency_index = self.getFrequencyIndex()
- if not frequency_index: return -1 # If not update frequency is provided, make sure we never update
- hour = convertDateToHour(date=self.getCreationDate())
- creation_date_index = hour % frequency_index
- # in the case of bisextile year, we substract 24 hours from the creation date,
- # otherwise updating documents (frequency=yearly update) created the last
- # 24 hours of bissextile year will be launched once every 4 years.
- if creation_date_index >= number_of_hours_in_year:
- creation_date_index = creation_date_index - number_of_hours_in_day
-
- return creation_date_index
-
- security.declareProtected(Permissions.AccessContentsInformation, 'isUpdatable')
- def isUpdatable(self):
- """
- This method is used to decide which document can be updated
- in the crawling process. This can depend for example on
- workflow states (publication state,
- validation state) or on roles on the document.
- """
- method = self._getTypeBasedMethod('isUpdatable',
- fallback_script_id = 'Document_isUpdatable')
- return method()
-
class Document(DocumentExtensibleTraversableMixIn, XMLObject, UrlMixIn, CachedConvertableMixin,
- SnapshotMixin, UpdateMixIn, TextConvertableMixin,
+ SnapshotMixin, CrawableMixin, TextConvertableMixin,
DownloadableMixin, DocumentMixin):
"""Document is an abstract class with all methods related to document
management in ERP5. This includes searchable text, explicit relations,
Modified: erp5/trunk/products/ERP5/Document/ExternalSource.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/ExternalSource.py?rev=37167&r1=37166&r2=37167&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/ExternalSource.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/ExternalSource.py [utf8] Fri Jul 16 13:05:59 2010
@@ -29,9 +29,9 @@ from AccessControl import ClassSecurityI
from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5.Document.Url import UrlMixIn
-from Products.ERP5.Document.Document import UpdateMixIn
+from Products.ERP5.mixin.crawable import CrawableMixin
-class ExternalSource(XMLObject, UrlMixIn, UpdateMixIn):
+class ExternalSource(XMLObject, UrlMixIn, CrawableMixin):
"""
An External Source consists of single URL which defines the
root of a collection of documents, each of which can be accessed
Modified: erp5/trunk/products/ERP5/interfaces/crawlable.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/interfaces/crawlable.py?rev=37167&r1=37166&r2=37167&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/interfaces/crawlable.py [utf8] (original)
+++ erp5/trunk/products/ERP5/interfaces/crawlable.py [utf8] Fri Jul 16 13:05:59 2010
@@ -91,3 +91,25 @@ class ICrawlable(Interface):
but with a different signature. This is probably inconsistent
and the interface must be revised. XXX
"""
+
+ def isUpdatable(self):
+ """
+ This method is used to decide if document can be updated
+ in the crawling process.
+ """
+
+ def getFrequencyIndex():
+ """
+ Returns the document update frequency as an integer
+ which is used by alamrs to decide which documents
+ must be updates at which time. The index represents
+ a time slot (ex. all days in a month, all hours in a week).
+ Note (ivan): not sure about this if needs to be part interface or not
+ """
+
+ def getCreationDateIndex(at_date):
+ """
+ Returns the document Creation Date Index which is the creation
+ date converted into hours modulo the Frequency Index.
+ Note (ivan): not sure about this if needs to be part interface or not
+ """
Added: erp5/trunk/products/ERP5/mixin/crawable.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/mixin/crawable.py?rev=37167&view=auto
==============================================================================
--- erp5/trunk/products/ERP5/mixin/crawable.py (added)
+++ erp5/trunk/products/ERP5/mixin/crawable.py [utf8] Fri Jul 16 13:05:59 2010
@@ -0,0 +1,82 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# Copyright (c) 2009 Nexedi SA and Contributors. All Rights Reserved.
+# Ivan Tyagov <ivan 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 AccessControl import ClassSecurityInfo, getSecurityManager
+from Products.ERP5Type import Permissions
+
+class CrawableMixin:
+ """
+ Generic implementation of ICrawlable interface
+ """
+ # Declarative security
+ security = ClassSecurityInfo()
+
+ security.declareProtected(Permissions.AccessContentsInformation, 'getFrequencyIndex')
+ def getFrequencyIndex(self):
+ """
+ Returns the document update frequency as an integer
+ which is used by alamrs to decide which documents
+ must be updates at which time. The index represents
+ a time slot (ex. all days in a month, all hours in a week).
+ """
+ try:
+ return self.getUpdateFrequencyValue().getIntIndex()
+ except AttributeError:
+ # Catch Attribute error or Key error - XXX not beautiful
+ return 0
+
+ security.declareProtected(Permissions.AccessContentsInformation, 'getCreationDateIndex')
+ def getCreationDateIndex(self, at_date = None):
+ """
+ Returns the document Creation Date Index which is the creation
+ date converted into hours modulo the Frequency Index.
+ """
+ frequency_index = self.getFrequencyIndex()
+ if not frequency_index: return -1 # If not update frequency is provided, make sure we never update
+ hour = convertDateToHour(date=self.getCreationDate())
+ creation_date_index = hour % frequency_index
+ # in the case of bisextile year, we substract 24 hours from the creation date,
+ # otherwise updating documents (frequency=yearly update) created the last
+ # 24 hours of bissextile year will be launched once every 4 years.
+ if creation_date_index >= number_of_hours_in_year:
+ creation_date_index = creation_date_index - number_of_hours_in_day
+
+ return creation_date_index
+
+ security.declareProtected(Permissions.AccessContentsInformation, 'isUpdatable')
+ def isUpdatable(self):
+ """
+ This method is used to decide which document can be updated
+ in the crawling process. This can depend for example on
+ workflow states (publication state,
+ validation state) or on roles on the document.
+ """
+ method = self._getTypeBasedMethod('isUpdatable',
+ fallback_script_id = 'Document_isUpdatable')
+ return method()
\ No newline at end of file
More information about the Erp5-report
mailing list