本文整理汇总了Python中indico.modules.attachments.models.folders.AttachmentFolder类的典型用法代码示例。如果您正苦于以下问题:Python AttachmentFolder类的具体用法?Python AttachmentFolder怎么用?Python AttachmentFolder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AttachmentFolder类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: _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)
示例3: _process
def _process(self):
form = AttachmentFolderForm(obj=FormDefaults(is_always_visible=True), linked_object=self.object)
if form.validate_on_submit():
folder = AttachmentFolder(object=self.object)
form.populate_obj(folder, skip={'acl'})
if folder.is_self_protected:
folder.acl = form.acl.data
db.session.add(folder)
logger.info('Folder %s created by %s', folder, session.user)
signals.attachments.folder_created.send(folder, user=session.user)
flash(_("Folder \"{name}\" created").format(name=folder.title), 'success')
return jsonify_data(attachment_list=_render_attachment_list(self.object))
return jsonify_template('attachments/create_folder.html', form=form,
protection_message=_render_protection_message(self.object))
示例4: _process
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))
示例5: _addMaterialFrom
def _addMaterialFrom(self, target, categoryPath):
for folder in AttachmentFolder.get_for_linked_object(target, preload_event=True):
for attachment in folder.attachments:
if attachment.type == AttachmentType.file:
dst_path = posixpath.join(self._mainPath, "files", categoryPath,
"{}-{}".format(attachment.id, attachment.file.filename))
with attachment.file.get_local_path() as file_path:
self._addFileFromSrc(dst_path, file_path)
示例6: _add_material
def _add_material(self, target, type_):
for folder in AttachmentFolder.get_for_linked_object(target, preload_event=True):
for attachment in folder.attachments:
if not attachment.can_access(None):
continue
if attachment.type == AttachmentType.file:
dst_path = posixpath.join(self._content_dir, "material", type_,
"{}-{}".format(attachment.id, attachment.file.filename))
with attachment.file.get_local_path() as file_path:
self._copy_file(dst_path, file_path)
示例7: 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)
示例8: _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))
示例9: get_attached_folders
def get_attached_folders(linked_object, include_empty=True, include_hidden=True, preload_event=False):
"""
Return a list of all the folders linked to an object.
:param linked_object: The object whose attachments are to be returned
:param include_empty: Whether to return empty folders as well.
:param include_hidden: Include folders that the user can't see
:param preload_event: in the process, preload all objects tied to the
corresponding event and keep them in cache
"""
from indico.modules.attachments.models.folders import AttachmentFolder
folders = AttachmentFolder.get_for_linked_object(linked_object, preload_event=preload_event)
if not include_hidden:
folders = [f for f in folders if f.can_view(session.user)]
if not include_empty:
folders = [f for f in folders if f.attachments]
return folders
示例10: _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)
示例11: 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
示例12: _get_folders_protection_info
def _get_folders_protection_info(linked_object):
folders = AttachmentFolder.find(object=linked_object, is_deleted=False)
return {folder.id: folder.is_self_protected for folder in folders}
示例13: has_data
def has_data(self):
return AttachmentFolder.has_rows() or Attachment.has_rows()
示例14: _checkParams
def _checkParams(self):
self.folder = AttachmentFolder.find_one(id=request.view_args['folder_id'], is_deleted=False)