本文整理汇总了Python中indico.modules.attachments.models.attachments.Attachment.file方法的典型用法代码示例。如果您正苦于以下问题:Python Attachment.file方法的具体用法?Python Attachment.file怎么用?Python Attachment.file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类indico.modules.attachments.models.attachments.Attachment
的用法示例。
在下文中一共展示了Attachment.file方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clone
# 需要导入模块: from indico.modules.attachments.models.attachments import Attachment [as 别名]
# 或者: from indico.modules.attachments.models.attachments.Attachment import file [as 别名]
def clone(self, new_event, options):
if 'attachments' not in options:
return
folder_mapping = {}
attrs = get_simple_column_attrs(AttachmentFolder)
for old_folder in self.find_folders():
new_folder = AttachmentFolder(event_id=new_event.id, **{attr: getattr(old_folder, attr) for attr in attrs})
if new_folder.linked_object is None:
continue
new_folder.acl = old_folder.acl
db.session.add(new_folder)
folder_mapping[old_folder] = new_folder
attrs = get_simple_column_attrs(Attachment) - {'modified_dt'}
for old_attachment in self.find_attachments():
folder = folder_mapping.get(old_attachment.folder)
if not folder:
continue
new_attachment = Attachment(folder=folder, user_id=old_attachment.user_id, acl=old_attachment.acl,
**{attr: getattr(old_attachment, attr) for attr in attrs})
if new_attachment.type == AttachmentType.file:
old_file = old_attachment.file
new_attachment.file = AttachmentFile(
attachment=new_attachment,
user_id=old_file.user_id,
filename=old_file.filename,
content_type=old_file.content_type
)
with old_file.open() as fd:
new_attachment.file.save(fd)
db.session.add(new_attachment)
db.session.flush()
示例2: _clone_attachment_folder
# 需要导入模块: from indico.modules.attachments.models.attachments import Attachment [as 别名]
# 或者: from indico.modules.attachments.models.attachments.Attachment import file [as 别名]
def _clone_attachment_folder(self, old_folder, new_object):
folder_attrs = get_simple_column_attrs(AttachmentFolder) | {'acl'}
attachment_attrs = (get_simple_column_attrs(Attachment) | {'user', 'acl'}) - {'modified_dt'}
folder = AttachmentFolder(object=new_object)
folder.populate_from_attrs(old_folder, folder_attrs)
for old_attachment in old_folder.attachments:
attachment = Attachment(folder=folder)
attachment.populate_from_attrs(old_attachment, attachment_attrs)
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)
示例3: _create_material
# 需要导入模块: from indico.modules.attachments.models.attachments import Attachment [as 别名]
# 或者: from indico.modules.attachments.models.attachments.Attachment import file [as 别名]
def _create_material(self, logs):
folder = AttachmentFolder.find_first(object=self.event_new, is_default=False, title='Chat Logs',
is_deleted=False)
if folder is None:
folder = AttachmentFolder(protection_mode=ProtectionMode.protected, linked_object=self.event_new,
title='Chat Logs', description='Chat logs for this event')
db.session.add(folder)
filename = '{}.html'.format(secure_filename(self.material_name, 'logs'))
attachment = Attachment(folder=folder, user=session.user, title=self.material_name, type=AttachmentType.file,
description="Chat logs for the chat room '{}'".format(self.chatroom.name))
attachment.file = AttachmentFile(user=session.user, filename=filename, content_type='text/html')
attachment.file.save(logs.encode('utf-8'))
db.session.flush()
signals.attachments.attachment_created.send(attachment, user=session.user)
log_data = [
('Range', 'Everything' if not self.date_filter else
'{} - {}'.format(format_date(self.start_date), format_date(self.end_date))),
]
self.event.log(EventLogRealm.management, EventLogKind.positive, 'Chat',
'Created material: {}'.format(filename), session.user, data=log_data)
示例4: create_contribution_from_abstract
# 需要导入模块: from indico.modules.attachments.models.attachments import Attachment [as 别名]
# 或者: from indico.modules.attachments.models.attachments.Attachment import file [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
示例5: _process
# 需要导入模块: from indico.modules.attachments.models.attachments import Attachment [as 别名]
# 或者: from indico.modules.attachments.models.attachments.Attachment import file [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))