Beispiel #1
0
    def migrate_event_attachments(self):
        self.print_step('migrating event attachments')

        for event, obj, material, resources in self._committing_iterator(
                self._iter_event_materials()):
            folder = self._folder_from_material(material, obj)
            lm = LegacyAttachmentFolderMapping(linked_object=obj,
                                               material_id=material.id,
                                               folder_id=folder['id'])
            self.todo[LegacyAttachmentFolderMapping].append(_sa_to_dict(lm))
            if not self.quiet:
                self.print_success(
                    cformat('%{cyan}[{}]%{reset} %{blue!}({})').format(
                        folder['title'], _link_repr(folder)),
                    event_id=event.id)
            for resource in resources:
                attachment = self._attachment_from_resource(
                    folder, material, resource, event)
                if attachment is None:
                    continue
                lm = LegacyAttachmentMapping(linked_object=obj,
                                             material_id=material.id,
                                             resource_id=resource.id,
                                             attachment_id=attachment['id'])
                self.todo[LegacyAttachmentMapping].append(_sa_to_dict(lm))
                if not self.quiet:
                    if attachment['type'] == AttachmentType.link:
                        self.print_success(cformat('- %{cyan}{}').format(
                            attachment['title']),
                                           event_id=event.id)
                    else:
                        self.print_success(cformat('- %{cyan!}{}').format(
                            attachment['title']),
                                           event_id=event.id)
Beispiel #2
0
def compat_attachment(**kwargs):
    _clean_args(kwargs)
    attachment = LegacyAttachmentMapping.find(
        **kwargs).first_or_404().attachment
    if attachment.is_deleted or attachment.folder.is_deleted or attachment.folder.linked_object is None:
        raise NotFound
    return redirect(attachment.download_url, 302 if current_app.debug else 301)
Beispiel #3
0
def compat_attachment(**kwargs):
    _clean_args(kwargs)
    mapping = LegacyAttachmentMapping.find_first(**kwargs)
    if mapping is None:
        if kwargs['material_id'] == 'minutes' and kwargs['resource_id'] == 'minutes':
            return _redirect_to_note(**kwargs)
        raise NotFound
    attachment = mapping.attachment
    if attachment.is_deleted or attachment.folder.is_deleted:
        raise NotFound
    return redirect(attachment.download_url, 302 if current_app.debug else 301)
Beispiel #4
0
 def migrate_event_attachments(self):
     for obj, material, resources, legacy_link_data in self._iter_event_materials():
         folder = self._folder_from_material(material, obj)
         LegacyAttachmentFolderMapping(material_id=material.id, folder=folder, **legacy_link_data)
         if not self.quiet:
             self.print_success('%[cyan][{}]%[reset] %[blue!]({})'.format(folder.title, folder.link_repr))
         for resource in resources:
             attachment = self._attachment_from_resource(folder, material, resource, self.conf)
             if attachment is None:
                 continue
             LegacyAttachmentMapping(material_id=material.id, resource_id=resource.id, attachment=attachment,
                                     **legacy_link_data)
             if not self.quiet:
                 if attachment.type == AttachmentType.link:
                     self.print_success('- %[cyan]{}'.format(attachment.title))
                 else:
                     self.print_success('- %[cyan!]{}'.format(attachment.title))
Beispiel #5
0
def compat_attachment(**kwargs):
    _clean_args(kwargs)
    attachment = LegacyAttachmentMapping.find(**kwargs).first_or_404().attachment
    if attachment.is_deleted or attachment.folder.is_deleted or attachment.folder.linked_object is None:
        raise NotFound
    return redirect(attachment.download_url, 302 if current_app.debug else 301)