Attachment

Todo

Docstrings (module, models, operations)

Models

class indico.modules.attachments.models.attachments.Attachment(**kwargs)

Bases: indico.core.db.sqlalchemy.protection.ProtectionMixin, indico.core.storage.models.VersionedResourceMixin, flask_sqlalchemy.Model

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

absolute_download_url

The absolute download url for the attachment

access_key = None
acl

The ACL of the folder (used for ProtectionMode.protected)

acl_entries
all_files
can_access(user, *args, **kwargs)

Checks if the user is allowed to access the attachment.

This is the case if the user has access to see the attachment or if the user can manage attachments for the linked object.

description

The description of the attachment

download_url

The download url for the attachment

file
file_id
folder

The folder containing the attachment

folder_id

The ID of the folder the attachment belongs to

get_download_url(absolute=False)

Returns the download url for the attachment.

During static site generation this returns a local URL for the file or the target URL for the link.

Parameters:absolute – If the returned URL should be absolute.
id

The ID of the attachment

is_deleted

If the attachment has been deleted

The target URL for a link attachment

locator
modified_dt

The date/time when the attachment was created/modified

own_no_access_contact = None
protection_mode
protection_parent
stored_file_class

alias of AttachmentFile

stored_file_fkey = u'attachment_id'
stored_file_table = u'attachments.files'
title

The name of the attachment

type

The type of the attachment (file or link)

user

The user who created the attachment

user_id

The ID of the user who created the attachment

class indico.modules.attachments.models.attachments.AttachmentFile(**kwargs)

Bases: indico.core.storage.models.StoredFileMixin, flask_sqlalchemy.Model

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

attachment_id

The ID of the associated attachment

content_type

The MIME type of the file

created_dt

The date/time when the file was uploaded

filename

The name of the file

id

The ID of the file

is_previewable
md5

An MD5 hash of the file.

Automatically assigned when save() is called.

size

The size of the file (in bytes).

Automatically assigned when save() is called.

storage_backend
storage_file_id
user

The user who uploaded the file

user_id

The user who uploaded the file

version_of = u'attachment'
class indico.modules.attachments.models.attachments.AttachmentType

Bases: indico.util.struct.enum.RichIntEnum

file = 1
class indico.modules.attachments.models.folders.AttachmentFolder(**kwargs)

Bases: indico.core.db.sqlalchemy.links.LinkMixin, indico.core.db.sqlalchemy.protection.ProtectionMixin, flask_sqlalchemy.Model

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

access_key = None
acl

The ACL of the folder (used for ProtectionMode.protected)

acl_entries
attachments

The list of attachments that are not deleted, ordered by name

can_access(user, *args, **kwargs)

Checks if the user is allowed to access the folder.

This is the case if the user has access the folder or if the user can manage attachments for the linked object.

can_view(user)

Checks if the user can see the folder.

This does not mean the user can actually access its contents. It just determines if it is visible to him or not.

category
category_id
contribution
contribution_id
description

The description of the folder

event
event_id
events_backref_name = u'all_attachment_folders'
classmethod get_for_linked_object(linked_object, preload_event=False)

Gets the attachments for the given object.

This only returns attachments that haven’t been deleted.

Parameters:
  • linked_object – A category, event, session, contribution or subcontribution.
  • preload_event – If all attachments for the same event should be pre-loaded and cached in the app context. This must not be used when linked_object is a category.
classmethod get_or_create(linked_object, title=None)

Gets a folder for the given object or creates it.

If no folder title is specified, the default folder will be used. It is the caller’s responsibility to add the folder or an object (such as an attachment) associated with it to the SQLAlchemy session using db.session.add(...).

classmethod get_or_create_default(linked_object)

Gets the default folder for the given object or creates it.

id

The ID of the folder

is_always_visible

If the folder is always visible (even if you cannot access it)

is_default

If the folder is the default folder (used for “folder-less” files)

is_deleted

If the folder has been deleted

linked_event
linked_event_id
locator

Defines a smart locator property.

This behaves pretty much like a normal read-only property and the decorated function should return a dict containing the necessary data to build a URL for the object.

This decorator should usually be applied to a method named locator as this name is required for get_locator to find it automatically when just passing the object.

If you need more than one locator, you can define it like this:

@locator_property
def locator(self):
    return {...}

@locator.other
def locator(self):
    return {...}

The other locator can then be accessed by passing obj.locator.other to the code expecting an object with a locator.

own_no_access_contact = None
protection_mode
protection_parent
session
session_id
subcontribution
subcontribution_id
title

The name of the folder (None for the default folder)

class indico.modules.attachments.models.principals.AttachmentFolderPrincipal(**kwargs)

Bases: indico.core.db.sqlalchemy.principals.PrincipalMixin, flask_sqlalchemy.Model

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

email = None
folder_id

The ID of the associated folder

id

The ID of the acl entry

ip_network_group = None
ip_network_group_id = None
local_group
local_group_id
multipass_group_name
multipass_group_provider
principal_backref_name = u'in_attachment_folder_acls'
type
unique_columns = (u'folder_id',)
user
user_id
class indico.modules.attachments.models.principals.AttachmentPrincipal(**kwargs)

Bases: indico.core.db.sqlalchemy.principals.PrincipalMixin, flask_sqlalchemy.Model

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

attachment_id

The ID of the associated attachment

email = None
id

The ID of the acl entry

ip_network_group = None
ip_network_group_id = None
local_group
local_group_id
multipass_group_name
multipass_group_provider
principal_backref_name = u'in_attachment_acls'
type
unique_columns = (u'attachment_id',)
user
user_id

Operations

Add a link attachment to linked_object

Utilities

indico.modules.attachments.util.can_manage_attachments(obj, user)

Checks if a user can manage attachments for the object

indico.modules.attachments.util.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.

Parameters:
  • linked_object – The object whose attachments are to be returned
  • include_empty – Whether to return empty folders as well.
  • include_hidden – Include folders that the user can’t see
  • preload_event – in the process, preload all objects tied to the corresponding event and keep them in cache
indico.modules.attachments.util.get_attached_items(linked_object, include_empty=True, include_hidden=True, preload_event=False)

Return a structured representation of all the attachments linked to an object.

Parameters:
  • linked_object – The object whose attachments are to be returned
  • include_empty – Whether to return empty folders as well.
  • include_hidden – Include folders that the user can’t see
  • preload_event – in the process, preload all objects tied to the corresponding event and keep them in cache
indico.modules.attachments.util.get_default_folder_names()
indico.modules.attachments.util.get_event(linked_object)
indico.modules.attachments.util.get_nested_attached_items(obj)

Returns a structured representation of all attachments linked to an object and all its nested objects.

Parameters:obj – A Event, Session, Contribution or SubContribution object.
class indico.modules.attachments.preview.ImagePreviewer

Bases: indico.modules.attachments.preview.Previewer

ALLOWED_CONTENT_TYPE = <_sre.SRE_Pattern object>
TEMPLATE = u'image_preview.html'
class indico.modules.attachments.preview.MarkdownPreviewer

Bases: indico.modules.attachments.preview.Previewer

ALLOWED_CONTENT_TYPE = <_sre.SRE_Pattern object>
classmethod generate_content(attachment)
class indico.modules.attachments.preview.PDFPreviewer

Bases: indico.modules.attachments.preview.Previewer

ALLOWED_CONTENT_TYPE = <_sre.SRE_Pattern object>
TEMPLATE = u'iframe_preview.html'
classmethod can_preview(attachment_file)
class indico.modules.attachments.preview.Previewer

Bases: object

Base class for file previewers

To create a new file prewiewer, subclass this class and register it using the get_file_previewers signal.

ALLOWED_CONTENT_TYPE = None
TEMPATE = None
TEMPLATES_DIR = u'attachments/previewers/'
classmethod can_preview(attachment_file)

Checks if the content type of the file matches the allowed content type of files that the previewer can be used for.

classmethod generate_content(attachment)

Generates the HTML output of the file preview

class indico.modules.attachments.preview.TextPreviewer

Bases: indico.modules.attachments.preview.Previewer

ALLOWED_CONTENT_TYPE = <_sre.SRE_Pattern object>
classmethod generate_content(attachment)
indico.modules.attachments.preview.get_file_previewer(attachment_file)

Returns a file previewer for the given attachment file based on the file’s content type.

indico.modules.attachments.preview.get_file_previewers()