Attachment

Todo

Docstrings (module, models, operations)

Models

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

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.

property 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)

Check 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

property 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)

Return 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

property locator
modified_dt

The date/time when the attachment was created/modified

own_no_access_contact = None
protection_mode
property protection_parent

The parent object to consult for ProtectionMode.inheriting.

query: IndicoBaseQuery

A SQLAlchemy query for a model. Equivalent to db.session.query(Model). Can be customized per-model by overriding query_class.

Warning

The query interface is considered legacy in SQLAlchemy. Prefer using session.execute(select()) instead.

stored_file_class

alias of AttachmentFile

stored_file_fkey = 'attachment_id'
stored_file_table = 'attachments.files'
title
title_required = False

Whether the title column may not be empty

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)

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.

extension

The extension of the file.

filename

The name of the file.

id

The ID of the file

property 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 = 'attachment'

Name of attribute (backref) that will be made to point to the versioned resource (leave as None if you don’t want versioning)

class indico.modules.attachments.models.attachments.AttachmentType(value)

An enumeration.

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

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

The link types that are supported. Can be overridden in the model using the mixin. Affects the table structure, so any changes to it should go along with a migration step!

attachments

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

can_access(user, *args, **kwargs)

Check 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)

Check 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 = 'all_attachment_folders'

The name of the backref that’s added to the Event model to access all linked objects

classmethod get_for_linked_object(linked_object, preload_event=False)

Get 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, **create_kwargs)

Get a folder for the given object or create 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(...).

Additional kwargs will be used when creating a custom folder; in case of a default folder they must not be used.

classmethod get_or_create_default(linked_object)

Get 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

is_hidden

If the folder is never shown in the frontend (even if you can access it)

The laziness of the backref that’s added to the linked objects

The name of the backref that’s added to the linked objects

linked_event
linked_event_id
locator()

Define 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
property protection_parent

The parent object to consult for ProtectionMode.inheriting.

session
session_block = None
session_block_id = None
session_id
subcontribution
subcontribution_id
title

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

If only one link per object should be allowed. This may also be a string containing an SQL string to specify the criterion for the unique index to be applied, e.g. 'is_foo = true'.

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

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.

allow_category_roles = True

Whether it should be allowed to add a category role

allow_event_roles = True

Whether it should be allowed to add an event role.

allow_registration_forms = True

Whether it should be allowed to add registrants

category_role
category_role_id
email = None
event_role
event_role_id
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_id
multipass_group_name
multipass_group_provider
principal_backref_name = 'in_attachment_folder_acls'

The name of the backref added to User and LocalGroup. For consistency, it is recommended to name the backref in_foo_acl with foo describing the ACL where this mixin is used.

query: IndicoBaseQuery

A SQLAlchemy query for a model. Equivalent to db.session.query(Model). Can be customized per-model by overriding query_class.

Warning

The query interface is considered legacy in SQLAlchemy. Prefer using session.execute(select()) instead.

registration_form
registration_form_id
type
unique_columns = ('folder_id',)

The columns which should be included in the unique constraints. If set to None, no unique constraints will be added.

user_id
class indico.modules.attachments.models.principals.AttachmentPrincipal(**kwargs)

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.

allow_category_roles = True

Whether it should be allowed to add a category role

allow_event_roles = True

Whether it should be allowed to add an event role.

allow_registration_forms = True

Whether it should be allowed to add registrants

attachment_id

The ID of the associated attachment

category_role
category_role_id
email = None
event_role
event_role_id
id

The ID of the acl entry

ip_network_group = None
ip_network_group_id = None
local_group_id
multipass_group_name
multipass_group_provider
principal_backref_name = 'in_attachment_acls'

The name of the backref added to User and LocalGroup. For consistency, it is recommended to name the backref in_foo_acl with foo describing the ACL where this mixin is used.

registration_form
registration_form_id
type
unique_columns = ('attachment_id',)

The columns which should be included in the unique constraints. If set to None, no unique constraints will be added.

user_id

Operations

Add a link attachment to linked_object.

Utilities

indico.modules.attachments.util.can_manage_attachments(obj, user, allow_admin=True)

Check 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)
class indico.modules.attachments.preview.ImagePreviewer
ALLOWED_CONTENT_TYPE = re.compile('^image/')
TEMPLATE = 'image_preview.html'
class indico.modules.attachments.preview.MarkdownPreviewer
ALLOWED_CONTENT_TYPE = re.compile('^text/markdown$')
classmethod generate_content(attachment)

Generate the HTML output of the file preview.

class indico.modules.attachments.preview.PDFPreviewer
ALLOWED_CONTENT_TYPE = re.compile('^application/pdf$')
TEMPLATE = 'iframe_preview.html'
classmethod can_preview(attachment_file)

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

class indico.modules.attachments.preview.Previewer

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
TEMPLATE = None
TEMPLATES_DIR = 'attachments/previewers/'
classmethod can_preview(attachment_file)

Check 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)

Generate the HTML output of the file preview.

class indico.modules.attachments.preview.TextPreviewer
ALLOWED_CONTENT_TYPE = re.compile('^text/plain$')
classmethod generate_content(attachment)

Generate the HTML output of the file preview.

indico.modules.attachments.preview.get_file_previewer(attachment_file)

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

indico.modules.attachments.preview.get_file_previewers()