From 82568ec1b7f725e74196a5035440eb587bbd3453 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Mon, 5 Dec 2011 16:10:01 +0100 Subject: [PATCH] splitting doc number in parts --- themis/libellioimport/configure.zcml | 8 +++++ themis/libellioimport/migration.py | 44 ++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/themis/libellioimport/configure.zcml b/themis/libellioimport/configure.zcml index 1b72980..1c328bb 100644 --- a/themis/libellioimport/configure.zcml +++ b/themis/libellioimport/configure.zcml @@ -42,4 +42,12 @@ permission="cmf.ManagePortal" /> + + + diff --git a/themis/libellioimport/migration.py b/themis/libellioimport/migration.py index 85d256f..52e5940 100644 --- a/themis/libellioimport/migration.py +++ b/themis/libellioimport/migration.py @@ -6,6 +6,7 @@ import datetime import cStringIO import xml.etree.ElementTree as ET +import transaction from zope.app.intid.interfaces import IIntIds from z3c.relationfield import RelationValue from Products.Five.browser import BrowserView @@ -22,6 +23,9 @@ except ImportError: from plone.namedfile.file import NamedImage from Products.CMFCore.WorkflowCore import WorkflowException +from zope.event import notify +from zope.lifecycleevent import ObjectAddedEvent, ObjectModifiedEvent + from plone.registry.interfaces import IRegistry from zope import component @@ -513,3 +517,43 @@ class UpdateToBlobs(BrowserView): print 'transforming file in', object.id newv = NamedFile(v.data, filename=v.filename) setattr(object, attr, newv) + + +class SplitDocNumbers(BrowserView): + def __call__(self): + catalog = getToolByName(self.context, 'portal_catalog') + for count, brain in enumerate(catalog.search({'portal_type': ['bqrD', 'biqD', + 'cr_seanceD', 'ProjetD', 'proposition_decret_reglementD', + 'proposition_resolution_modificationD', 'PropositionD', + 'rapports_commissionsD']})): + object = brain.getObject() + if object.numero_suite: + continue # already filled + attr_name = None + attr_value = None + for attr in ('numero_biq', 'numero_document'): + if hasattr(object, attr): + attr_name = attr + attr_value = getattr(object, attr) + break + if not attr_name: + continue + try: + new_number = re.findall(r'(\d+) \(', attr_value)[0] + except IndexError: + print 'failed to get doc number for', attr_value + continue + no_suite = None + if '°' in attr_value: + try: + no_suite = re.findall(r'°\s*(\d+)', attr_value)[0] + except IndexError: + print 'failed to get suite number for', attr_value + continue + setattr(object, attr, new_number) + if no_suite: + object.numero_suite = no_suite + + notify(ObjectModifiedEvent(object)) + if count%100 == 0: + transaction.commit()