splitting doc number in parts
This commit is contained in:
parent
461dc5cd32
commit
82568ec1b7
|
@ -42,4 +42,12 @@
|
||||||
permission="cmf.ManagePortal"
|
permission="cmf.ManagePortal"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<browser:view
|
||||||
|
name="splitdocnumbers"
|
||||||
|
for="*"
|
||||||
|
class=".migration.UpdateToBlobs"
|
||||||
|
permission="cmf.ManagePortal"
|
||||||
|
/>
|
||||||
|
|
||||||
|
|
||||||
</configure>
|
</configure>
|
||||||
|
|
|
@ -6,6 +6,7 @@ import datetime
|
||||||
import cStringIO
|
import cStringIO
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
|
import transaction
|
||||||
from zope.app.intid.interfaces import IIntIds
|
from zope.app.intid.interfaces import IIntIds
|
||||||
from z3c.relationfield import RelationValue
|
from z3c.relationfield import RelationValue
|
||||||
from Products.Five.browser import BrowserView
|
from Products.Five.browser import BrowserView
|
||||||
|
@ -22,6 +23,9 @@ except ImportError:
|
||||||
from plone.namedfile.file import NamedImage
|
from plone.namedfile.file import NamedImage
|
||||||
from Products.CMFCore.WorkflowCore import WorkflowException
|
from Products.CMFCore.WorkflowCore import WorkflowException
|
||||||
|
|
||||||
|
from zope.event import notify
|
||||||
|
from zope.lifecycleevent import ObjectAddedEvent, ObjectModifiedEvent
|
||||||
|
|
||||||
from plone.registry.interfaces import IRegistry
|
from plone.registry.interfaces import IRegistry
|
||||||
from zope import component
|
from zope import component
|
||||||
|
|
||||||
|
@ -513,3 +517,43 @@ class UpdateToBlobs(BrowserView):
|
||||||
print 'transforming file in', object.id
|
print 'transforming file in', object.id
|
||||||
newv = NamedFile(v.data, filename=v.filename)
|
newv = NamedFile(v.data, filename=v.filename)
|
||||||
setattr(object, attr, newv)
|
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()
|
||||||
|
|
Reference in New Issue