当前位置: 首页>>代码示例>>Python>>正文


Python AttachmentFolder.get_or_create_default方法代码示例

本文整理汇总了Python中indico.modules.attachments.models.folders.AttachmentFolder.get_or_create_default方法的典型用法代码示例。如果您正苦于以下问题:Python AttachmentFolder.get_or_create_default方法的具体用法?Python AttachmentFolder.get_or_create_default怎么用?Python AttachmentFolder.get_or_create_default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在indico.modules.attachments.models.folders.AttachmentFolder的用法示例。


在下文中一共展示了AttachmentFolder.get_or_create_default方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _process

# 需要导入模块: from indico.modules.attachments.models.folders import AttachmentFolder [as 别名]
# 或者: from indico.modules.attachments.models.folders.AttachmentFolder import get_or_create_default [as 别名]
    def _process(self):
        defaults = FormDefaults(self.attachment, protected=self.attachment.is_self_protected, skip_attrs={'file'})
        if self.attachment.type == AttachmentType.file:
            form = EditAttachmentFileForm(linked_object=self.object, obj=defaults, file=self.attachment)
        else:
            form = EditAttachmentLinkForm(linked_object=self.object, obj=defaults)

        if form.validate_on_submit():
            folder = form.folder.data or AttachmentFolder.get_or_create_default(linked_object=self.object)
            logger.info('Attachment %s edited by %s', self.attachment, session.user)
            form.populate_obj(self.attachment, skip={'acl', 'file'})
            self.attachment.folder = folder
            if self.attachment.is_self_protected:
                # can't use `=` because of https://bitbucket.org/zzzeek/sqlalchemy/issues/3583
                self.attachment.acl |= form.acl.data
                self.attachment.acl &= form.acl.data
            # files need special handling; links are already updated in `populate_obj`
            if self.attachment.type == AttachmentType.file:
                file = form.file.data['added']
                if file:
                    self.attachment.file = AttachmentFile(user=session.user, content_type=file.mimetype,
                                                          filename=secure_filename(file.filename, 'attachment'))
                    self.attachment.file.save(file.stream)

            signals.attachments.attachment_updated.send(self.attachment, user=session.user)
            flash(_("The attachment \"{name}\" has been updated").format(name=self.attachment.title), 'success')
            return jsonify_data(attachment_list=_render_attachment_list(self.object))

        template = ('attachments/upload.html' if self.attachment.type == AttachmentType.file else
                    'attachments/add_link.html')
        return jsonify_template(template, form=form, existing_attachment=self.attachment,
                                action=url_for('.modify_attachment', self.attachment),
                                protection_message=_render_protection_message(self.object),
                                folders_protection_info=_get_folders_protection_info(self.object))
开发者ID:bkolobara,项目名称:indico,代码行数:36,代码来源:base.py

示例2: add_attachment_link

# 需要导入模块: from indico.modules.attachments.models.folders import AttachmentFolder [as 别名]
# 或者: from indico.modules.attachments.models.folders.AttachmentFolder import get_or_create_default [as 别名]
def add_attachment_link(data, linked_object):
    """Add a link attachment to linked_object"""
    folder = data.pop('folder', None)
    if not folder:
        folder = AttachmentFolder.get_or_create_default(linked_object=linked_object)
    assert folder.object == linked_object
    link = Attachment(user=session.user, type=AttachmentType.link, folder=folder)
    link.populate_from_dict(data, skip={'acl', 'protected'})
    if link.is_self_protected:
        link.acl = data['acl']
    db.session.flush()
    logger.info('Attachment %s added by %s', link, session.user)
    signals.attachments.attachment_created.send(link, user=session.user)
开发者ID:DirkHoffmann,项目名称:indico,代码行数:15,代码来源:operations.py

示例3: _process

# 需要导入模块: from indico.modules.attachments.models.folders import AttachmentFolder [as 别名]
# 或者: from indico.modules.attachments.models.folders.AttachmentFolder import get_or_create_default [as 别名]
    def _process(self):
        form = AddAttachmentLinkForm(linked_object=self.object)
        if form.validate_on_submit():
            folder = form.folder.data or AttachmentFolder.get_or_create_default(linked_object=self.object)
            link = Attachment(user=session.user, type=AttachmentType.link)
            form.populate_obj(link, skip={'acl'})
            if link.is_protected:
                link.acl = form.acl.data
            link.folder = folder

            db.session.flush()
            logger.info('Attachment {} added by {}'.format(link, session.user))
            signals.attachments.attachment_created.send(link, user=session.user)
            flash(_("The link has been added"), 'success')
            return jsonify_data(attachment_list=_render_attachment_list(self.object))
        return jsonify_template('attachments/add_link.html', form=form,
                                protection_message=_render_protection_message(self.object),
                                folders_protection_info=_get_folders_protection_info(self.object))
开发者ID:hennogous,项目名称:indico,代码行数:20,代码来源:base.py

示例4: create_contribution_from_abstract

# 需要导入模块: from indico.modules.attachments.models.folders import AttachmentFolder [as 别名]
# 或者: from indico.modules.attachments.models.folders.AttachmentFolder import get_or_create_default [as 别名]
def create_contribution_from_abstract(abstract, contrib_session=None):
    from indico.modules.events.abstracts.settings import abstracts_settings

    event = abstract.event
    contrib_person_links = set()
    person_link_attrs = {'_title', 'address', 'affiliation', 'first_name', 'last_name', 'phone', 'author_type',
                         'is_speaker', 'display_order'}
    for abstract_person_link in abstract.person_links:
        link = ContributionPersonLink(person=abstract_person_link.person)
        link.populate_from_attrs(abstract_person_link, person_link_attrs)
        contrib_person_links.add(link)

    if contrib_session:
        duration = contrib_session.default_contribution_duration
    else:
        duration = contribution_settings.get(event, 'default_duration')
    custom_fields_data = {'custom_{}'.format(field_value.contribution_field.id): field_value.data for
                          field_value in abstract.field_values}
    contrib = create_contribution(event, {'friendly_id': abstract.friendly_id,
                                          'title': abstract.title,
                                          'duration': duration,
                                          'description': abstract.description,
                                          'type': abstract.accepted_contrib_type,
                                          'track': abstract.accepted_track,
                                          'session': contrib_session,
                                          'person_link_data': {link: True for link in contrib_person_links}},
                                  custom_fields_data=custom_fields_data)
    if abstracts_settings.get(event, 'copy_attachments') and abstract.files:
        folder = AttachmentFolder.get_or_create_default(contrib)
        for abstract_file in abstract.files:
            attachment = Attachment(user=abstract.submitter, type=AttachmentType.file, folder=folder,
                                    title=abstract_file.filename)
            attachment.file = AttachmentFile(user=abstract.submitter, filename=abstract_file.filename,
                                             content_type=abstract_file.content_type)
            with abstract_file.open() as fd:
                attachment.file.save(fd)
    db.session.flush()
    return contrib
开发者ID:indico,项目名称:indico,代码行数:40,代码来源:operations.py

示例5: _process

# 需要导入模块: from indico.modules.attachments.models.folders import AttachmentFolder [as 别名]
# 或者: from indico.modules.attachments.models.folders.AttachmentFolder import get_or_create_default [as 别名]
 def _process(self):
     form = AddAttachmentFilesForm(linked_object=self.object)
     if form.validate_on_submit():
         files = request.files.getlist('file')
         folder = form.folder.data or AttachmentFolder.get_or_create_default(linked_object=self.object)
         for f in files:
             filename = secure_filename(f.filename, 'attachment')
             attachment = Attachment(folder=folder, user=session.user, title=to_unicode(f.filename),
                                     type=AttachmentType.file, protection_mode=form.protection_mode.data)
             if attachment.is_self_protected:
                 attachment.acl = form.acl.data
             content_type = mimetypes.guess_type(f.filename)[0] or f.mimetype or 'application/octet-stream'
             attachment.file = AttachmentFile(user=session.user, filename=filename, content_type=content_type)
             attachment.file.save(f.file)
             db.session.add(attachment)
             db.session.flush()
             logger.info('Attachment %s uploaded by %s', attachment, session.user)
             signals.attachments.attachment_created.send(attachment, user=session.user)
         flash(ngettext("The attachment has been uploaded", "{count} attachments have been uploaded", len(files))
               .format(count=len(files)), 'success')
         return jsonify_data(attachment_list=_render_attachment_list(self.object))
     return jsonify_template('attachments/upload.html', form=form, action=url_for('.upload', self.object),
                             protection_message=_render_protection_message(self.object),
                             folders_protection_info=_get_folders_protection_info(self.object))
开发者ID:fph,项目名称:indico,代码行数:26,代码来源:base.py


注:本文中的indico.modules.attachments.models.folders.AttachmentFolder.get_or_create_default方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。