add one shot code to fix changes in deputies and related docs
This commit is contained in:
parent
75cbeb1bf9
commit
ce0860cb28
|
@ -21,4 +21,18 @@
|
|||
permission="cmf.ManagePortal"
|
||||
/>
|
||||
|
||||
<browser:view
|
||||
name="fixdeputies"
|
||||
for="*"
|
||||
class=".migration.FixDeputies"
|
||||
permission="cmf.ManagePortal"
|
||||
/>
|
||||
|
||||
<browser:view
|
||||
name="fixrelateddocs"
|
||||
for="*"
|
||||
class=".migration.FixRelatedDocs"
|
||||
permission="cmf.ManagePortal"
|
||||
/>
|
||||
|
||||
</configure>
|
||||
|
|
|
@ -396,3 +396,73 @@ class ImportDeputies(BrowserView):
|
|||
return current
|
||||
|
||||
|
||||
class FixDeputies(BrowserView):
|
||||
def __call__(self):
|
||||
self.settings = component.getUtility(IRegistry).forInterface(ITabellioSettings, False)
|
||||
self.from_id = self.request.form.get('from')
|
||||
self.to_id = self.request.form.get('to')
|
||||
catalog = getToolByName(self.context, 'portal_catalog')
|
||||
for brain in catalog({'auteurs': self.from_id}):
|
||||
obj = brain.getObject()
|
||||
for attr in ('orateurs', 'orateurs_en_commission', 'auteurs',
|
||||
'rapporteurs', 'orateurs_seance_reponse_orale',
|
||||
'auteur', 'expediteur'):
|
||||
if hasattr(obj, attr) and type(getattr(obj, attr)) is list:
|
||||
setattr(obj, attr, self.replace_in_list(getattr(obj, attr)))
|
||||
for attr in ('auteur',):
|
||||
if hasattr(obj, attr) and type(getattr(obj, attr)) is str:
|
||||
if getattr(obj, attr) == self.from_id:
|
||||
setattr(obj, attr, self.to_id)
|
||||
|
||||
def replace_in_list(self, oldlist):
|
||||
newlist = []
|
||||
for item in oldlist:
|
||||
if item == self.from_id:
|
||||
newlist.append(self.to_id)
|
||||
else:
|
||||
newlist.append(item)
|
||||
return newlist
|
||||
|
||||
_documents_folder = None
|
||||
def documents_folder(self):
|
||||
if self._documents_folder:
|
||||
return self._documents_folder
|
||||
path = self.settings.documentsPath
|
||||
self._documents_folder = self.get_folder_at_path(path)
|
||||
return self._documents_folder
|
||||
documents_folder = property(documents_folder)
|
||||
|
||||
|
||||
class FixRelatedDocs(BrowserView):
|
||||
def __call__(self):
|
||||
catalog = getToolByName(self.context, 'portal_catalog')
|
||||
for brain in catalog.search({'review_state': 'pending'}):
|
||||
object = brain.getObject()
|
||||
for attr in ("bulletin_des_travaux",
|
||||
"bulletin_questions_ecrites",
|
||||
"courrier_reponse_accuse_de_reception",
|
||||
"cr_debats_declaration_politique_generale",
|
||||
"cr_debats_declaration_programme",
|
||||
"cr_reponse_orale",
|
||||
"cr_seance",
|
||||
"cr_seance_ou_biq",
|
||||
"cr_seance_pleniere",
|
||||
"cr_seance_prise_en_consideration",
|
||||
"cr_seance_vote_motion",
|
||||
"cr_vote_declaration_programme",
|
||||
"documents_lies",
|
||||
"lien_qo_ou_qe",
|
||||
"rapport",
|
||||
"rapport_de_commission",
|
||||
"reponse"):
|
||||
try:
|
||||
v = getattr(object, attr)
|
||||
except AttributeError:
|
||||
continue
|
||||
if v is None:
|
||||
continue
|
||||
if type(v) is list:
|
||||
continue
|
||||
setattr(object, attr, [v])
|
||||
|
||||
|
||||
|
|
Reference in New Issue