3232from imio .dms .mail import IM_EDITOR_SERVICE_FUNCTIONS
3333from imio .dms .mail import IM_READER_SERVICE_FUNCTIONS
3434from imio .dms .mail .adapters import OMApprovalAdapter
35+
3536# from imio.dms.mail import MAIN_FOLDERS
3637from imio .dms .mail .browser .settings import default_creating_group
3738from imio .dms .mail .browser .settings import IImioDmsMailConfig
4142from imio .dms .mail .interfaces import IPersonnelContact
4243from imio .dms .mail .interfaces import IProtectedItem
4344from imio .dms .mail .setuphandlers import blacklistPortletCategory
45+
4446# from imio.dms.mail.utils import separate_fullname
4547from imio .dms .mail .utils import create_personnel_content
4648from imio .dms .mail .utils import create_read_label_cron_task
6062from imio .esign .utils import remove_files_from_session
6163from imio .helpers .cache import invalidate_cachekey_volatile_for
6264from imio .helpers .cache import setup_ram_cache
65+
6366# from imio.helpers.content import get_vocab_values
6467from imio .helpers .content import object_values
6568from imio .helpers .content import uuidToObject
8992from z3c .relationfield .relation import RelationValue
9093from zc .relation .interfaces import ICatalog # noqa
9194from zExceptions import Redirect
95+
9296# from zope.component.interfaces import ComponentLookupError
9397from zope .annotation import IAnnotations
9498from zope .component import getAdapter
130134 class IReferenceable (Interface ):
131135 pass
132136
137+
133138logger = logging .getLogger ("imio.dms.mail: events" )
134139
135140
@@ -421,19 +426,26 @@ def dmsoutgoingmail_transition(mail, event):
421426 approval .start_approval_process ()
422427 if not mail .esign :
423428 # if not mail.seal, we render odt to remove download subdocument comment
424- if (not mail .seal and event .transition
425- and event .transition .id in ("set_validated" , "set_to_print" , "propose_to_be_signed" , "mark_as_sent" )):
426- for afile in object_values (mail , ("ImioDmsFile" , )):
429+ if (
430+ not mail .seal
431+ and event .transition
432+ and event .transition .id in ("set_validated" , "set_to_print" , "propose_to_be_signed" , "mark_as_sent" )
433+ ):
434+ for afile in object_values (mail , ("ImioDmsFile" ,)):
427435 doc_annot = IAnnotations (afile ).get ("documentgenerator" , {})
428436 # if not a generated odt (or needing mailing) or already done, we pass
429437 if doc_annot .get ("need_mailing" , True ) is True or doc_annot .get ("cleaned_download" ) is True :
430438 continue
431- helper_view = getMultiAdapter ((mail , mail .REQUEST ), name = ' document_generation_helper_view' )
439+ helper_view = getMultiAdapter ((mail , mail .REQUEST ), name = " document_generation_helper_view" )
432440 helper_view .pod_template = doc_annot .get ("template_uid" )
433441 helper_view .output_format = "odt"
434- gen_context = {"context" : mail , "portal" : api .portal .get (), "view" : helper_view ,
435- "render_download_barcode" : True }
436- new_file_content = convert_odt (afile .file , fmt = 'odt' , gen_context = gen_context )
442+ gen_context = {
443+ "context" : mail ,
444+ "portal" : api .portal .get (),
445+ "view" : helper_view ,
446+ "render_download_barcode" : True ,
447+ }
448+ new_file_content = convert_odt (afile .file , fmt = "odt" , gen_context = gen_context )
437449 afile .file = NamedBlobFile (new_file_content , filename = afile .file .filename )
438450 modified (afile , Attributes (ImioDmsFile , "file" ))
439451 doc_annot ["cleaned_download" ] = True
@@ -466,7 +478,8 @@ def dmsoutgoingmail_transition(mail, event):
466478 type = "error" ,
467479 )
468480 if seal_code and seal_email :
469- ExternalSessionCreateView (mail , mail .REQUEST )(session_id = approval .session_id )
481+ for sid in approval .session_ids :
482+ ExternalSessionCreateView (mail , mail .REQUEST )(session_id = sid )
470483 else :
471484 # TODO check if to_sign and approved files have a pdf version
472485 pass
@@ -639,7 +652,7 @@ def task_transition(task, event):
639652
640653
641654def _correct_to_sign (file_obj ):
642- """"Correct to_sign value following mimetype.
655+ """ "Correct to_sign value following mimetype.
643656
644657 :param file_obj: dmsommainfile or dmsappendixfile
645658 :return: True if to_sign has been changed
@@ -652,12 +665,7 @@ def _correct_to_sign(file_obj):
652665 file_obj .to_approve = False
653666 category_object = get_category_object (file_obj , file_obj .content_category )
654667 update_categorized_elements (
655- file_obj .__parent__ ,
656- file_obj ,
657- category_object ,
658- limited = True ,
659- sort = False ,
660- logging = True
668+ file_obj .__parent__ , file_obj , category_object , limited = True , sort = False , logging = True
661669 )
662670 api .portal .show_message (
663671 message = _ (
@@ -686,22 +694,19 @@ def _correct_to_approve(file_obj):
686694 new_value = False
687695 om_obj = file_obj .__parent__
688696 approval = OMApprovalAdapter (om_obj )
689- if (orig_value and getattr (file_obj , "to_sign" , False ) and approval .approvers
690- and not base_hasattr (file_obj , "conv_from_uid" )
691- and not getattr (file_obj , "need_mailing" , False )):
697+ if (
698+ orig_value
699+ and getattr (file_obj , "to_sign" , False )
700+ and approval .approvers
701+ and not base_hasattr (file_obj , "conv_from_uid" )
702+ and not getattr (file_obj , "need_mailing" , False )
703+ ):
692704 new_value = True
693705 approval .add_file_to_approval (file_obj .UID ())
694706 if orig_value != new_value : # only when passing from True to False normally
695707 file_obj .to_approve = new_value
696708 category_object = get_category_object (file_obj , file_obj .content_category )
697- update_categorized_elements (
698- om_obj ,
699- file_obj ,
700- category_object ,
701- limited = True ,
702- sort = False ,
703- logging = True
704- )
709+ update_categorized_elements (om_obj , file_obj , category_object , limited = True , sort = False , logging = True )
705710
706711
707712def i_annex_added (obj , event ):
@@ -862,7 +867,7 @@ def imiodmsfile_added(obj, event):
862867
863868def imiodmsfile_iconified_attr_changed (obj , event ):
864869 """When an iconified attribute is changed. Not used for the moment."""
865- if event .attr_name == ' approved' :
870+ if event .attr_name == " approved" :
866871 if event .is_created :
867872 return
868873 fil = event .object # noqa F841
@@ -1344,10 +1349,13 @@ def organization_modified(obj, event):
13441349
13451350def held_position_modified (obj , event ):
13461351 if IPersonnelContact .providedBy (obj ):
1347- invalidate_cachekey_volatile_for (' imio.dms.mail.vocabularies.OMSignersVocabulary' )
1352+ invalidate_cachekey_volatile_for (" imio.dms.mail.vocabularies.OMSignersVocabulary" )
13481353 invalidate_cachekey_volatile_for ("imio.dms.mail.vocabularies.SigningApprovingsVocabulary" )
1349- mod_attr = [at for at in getattr (event , "descriptions" , []) if base_hasattr (at , "attributes" )
1350- and "IUsagesBehavior.usages" in at .attributes ]
1354+ mod_attr = [
1355+ at
1356+ for at in getattr (event , "descriptions" , [])
1357+ if base_hasattr (at , "attributes" ) and "IUsagesBehavior.usages" in at .attributes
1358+ ]
13511359 if mod_attr :
13521360 update_approvers_settings ()
13531361
@@ -1357,7 +1365,7 @@ def held_position_removed(obj, event):
13571365 # at site removal
13581366 if event .object .portal_type == "Plone Site" :
13591367 return
1360- invalidate_cachekey_volatile_for (' imio.dms.mail.vocabularies.OMSignersVocabulary' )
1368+ invalidate_cachekey_volatile_for (" imio.dms.mail.vocabularies.OMSignersVocabulary" )
13611369 invalidate_cachekey_volatile_for ("imio.dms.mail.vocabularies.SigningApprovingsVocabulary" )
13621370
13631371
0 commit comments