本文整理汇总了Python中indico.modules.attachments.models.attachments.Attachment类的典型用法代码示例。如果您正苦于以下问题:Python Attachment类的具体用法?Python Attachment怎么用?Python Attachment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Attachment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clone
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: _merge_users
def _merge_users(target, source, **kwargs):
from indico.modules.attachments.models.attachments import Attachment, AttachmentFile
from indico.modules.attachments.models.principals import AttachmentPrincipal, AttachmentFolderPrincipal
Attachment.find(user_id=source.id).update({Attachment.user_id: target.id})
AttachmentFile.find(user_id=source.id).update({AttachmentFile.user_id: target.id})
AttachmentPrincipal.merge_users(target, source, 'attachment')
AttachmentFolderPrincipal.merge_users(target, source, 'folder')
示例3: add_attachment_link
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)
示例4: _clone_attachment_folder
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)
示例5: _build_base_query
def _build_base_query(self, added_since=None):
query = Attachment.find(Attachment.type == AttachmentType.file, ~AttachmentFolder.is_deleted,
~Attachment.is_deleted, AttachmentFolder.event_new == self.event_new,
_join=AttachmentFolder)
if added_since is not None:
query = query.join(Attachment.file).filter(cast(AttachmentFile.created_dt, Date) >= added_since)
return query
示例6: _getParams
def _getParams(self):
super(FileHook, self)._getParams()
self._attachment = Attachment.get(int(self._pathParams['res']))
if not self._attachment:
raise HTTPAPIError("File not found", 404)
示例7: _process
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))
示例8: materialToXMLMarc21
def materialToXMLMarc21(self, obj, out=None):
if not out:
out = self._XMLGen
for attachment in (Attachment.find(~AttachmentFolder.is_deleted, AttachmentFolder.object == obj,
is_deleted=False, _join=AttachmentFolder)
.options(joinedload(Attachment.legacy_mapping))):
if attachment.can_access(self.__aw.getUser().user):
self.resourceToXMLMarc21(attachment, out)
self._generateAccessList(acl=self._attachment_access_list(attachment), out=out,
objId=self._attachment_unique_id(attachment, add_prefix=False))
示例9: _create_material
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)
示例10: create_contribution_from_abstract
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
示例11: _process
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))
示例12: has_data
def has_data(self):
return AttachmentFolder.has_rows() or Attachment.has_rows()
示例13: find_attachments
def find_attachments(self):
return Attachment.find(~AttachmentFolder.is_deleted, ~Attachment.is_deleted,
AttachmentFolder.event_id == int(self.event.id), _join=AttachmentFolder)
示例14: _checkParams
def _checkParams(self):
self.attachment = Attachment.find_one(id=request.view_args['attachment_id'], is_deleted=False)
if self.attachment.folder.is_deleted:
raise NotFound
示例15: _count_attachments
def _count_attachments(cls, obj):
return Attachment.find(~AttachmentFolder.is_deleted, AttachmentFolder.linked_object == obj,
is_deleted=False, _join=AttachmentFolder).count()