Esempio n. 1
0
 def _clone_attachment_folder(self, old_folder, new_object):
     folder_attrs = get_simple_column_attrs(AttachmentFolder)
     attachment_attrs = (get_simple_column_attrs(Attachment)
                         | {'user'}) - {'modified_dt'}
     folder = AttachmentFolder(object=new_object)
     folder.populate_from_attrs(old_folder, folder_attrs)
     folder.acl_entries = clone_principals(AttachmentFolderPrincipal,
                                           old_folder.acl_entries,
                                           self._event_role_map,
                                           self._regform_map)
     for old_attachment in old_folder.attachments:
         attachment = Attachment(folder=folder)
         attachment.populate_from_attrs(old_attachment, attachment_attrs)
         attachment.acl_entries = clone_principals(
             AttachmentPrincipal, old_attachment.acl_entries,
             self._event_role_map, self._regform_map)
         if attachment.type == AttachmentType.file:
             old_file = old_attachment.file
             attachment.file = AttachmentFile(
                 attachment=attachment,
                 user=old_file.user,
                 filename=old_file.filename,
                 content_type=old_file.content_type)
             with old_file.open() as fd:
                 attachment.file.save(fd)