code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def register_link_events(cls):
"""Register sqlalchemy events needed by this mixin.
Call this method after the definition of a model which uses
this mixin class.
"""
event_mapping = {cls.session: lambda x: x.event,
cls.session_block: lambda x: x.event,
... | Register sqlalchemy events needed by this mixin.
Call this method after the definition of a model which uses
this mixin class.
| register_link_events | python | indico/indico | indico/core/db/sqlalchemy/links.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/links.py | MIT |
def link_repr(self):
"""A kwargs-style string suitable for the object's repr."""
info = [('link_type', self.link_type.name if self.link_type is not None else 'None')]
info.extend((key, getattr(self, key)) for key in _all_columns if getattr(self, key) is not None)
return ', '.join(f'{key}... | A kwargs-style string suitable for the object's repr. | link_repr | python | indico/indico | indico/core/db/sqlalchemy/links.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/links.py | MIT |
def link_event_log_data(self):
"""
Return a dict containing information about the linked object
suitable for the event log.
It does not return any information for an object linked to a
category or the event itself.
"""
data = {}
if self.link_type == LinkT... |
Return a dict containing information about the linked object
suitable for the event log.
It does not return any information for an object linked to a
category or the event itself.
| link_event_log_data | python | indico/indico | indico/core/db/sqlalchemy/links.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/links.py | MIT |
def location_parent(self):
"""The parent object to consult if the location is inherited."""
if not self.allow_location_inheritance:
return None
raise NotImplementedError | The parent object to consult if the location is inherited. | location_parent | python | indico/indico | indico/core/db/sqlalchemy/locations.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/locations.py | MIT |
def venue(self):
"""The venue (Location) where this item is located.
This is ``None`` if a custom venue name was entered.
"""
if self.inherit_location and self.location_parent is None:
return None
return self.own_venue if not self.inherit_location else self.location_... | The venue (Location) where this item is located.
This is ``None`` if a custom venue name was entered.
| venue | python | indico/indico | indico/core/db/sqlalchemy/locations.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/locations.py | MIT |
def room(self):
"""The Room where this item is located.
This is ``None`` if a custom room name was entered.
"""
if self.inherit_location and self.location_parent is None:
return None
return self.own_room if not self.inherit_location else self.location_parent.room | The Room where this item is located.
This is ``None`` if a custom room name was entered.
| room | python | indico/indico | indico/core/db/sqlalchemy/locations.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/locations.py | MIT |
def venue_name(self):
"""The name of the location where this item is located."""
if self.inherit_location and self.location_parent is None:
return ''
venue = self.venue
if venue is not None:
return venue.name
return self.own_venue_name if not self.inherit_... | The name of the location where this item is located. | venue_name | python | indico/indico | indico/core/db/sqlalchemy/locations.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/locations.py | MIT |
def get_room_name(self, full=True, verbose=False):
"""The name of the room where this item is located.
If both ``full`` and ``verbose`` are set to ``False``, the
"friendly name" will be returned in that case. Both ``full`` and
``verbose`` cannot be set to ``True``.
:param full:... | The name of the room where this item is located.
If both ``full`` and ``verbose`` are set to ``False``, the
"friendly name" will be returned in that case. Both ``full`` and
``verbose`` cannot be set to ``True``.
:param full: If the room has a "friendly name" (e.g. 'Main
... | get_room_name | python | indico/indico | indico/core/db/sqlalchemy/locations.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/locations.py | MIT |
def address(self):
"""The address where this item is located."""
if self.inherit_location and self.location_parent is None:
return ''
return self.own_address if not self.inherit_location else self.location_parent.address | The address where this item is located. | address | python | indico/indico | indico/core/db/sqlalchemy/locations.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/locations.py | MIT |
def location_data(self):
"""All location data for the item.
Returns a dict containing ``source``, ``inheriting``, ``room``,
``room_name``, ``venue_name`` and ``address``. The
``source`` is the object the location data is taken from, i.e.
either the item itself or the object the... | All location data for the item.
Returns a dict containing ``source``, ``inheriting``, ``room``,
``room_name``, ``venue_name`` and ``address``. The
``source`` is the object the location data is taken from, i.e.
either the item itself or the object the location data is
inherited ... | location_data | python | indico/indico | indico/core/db/sqlalchemy/locations.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/locations.py | MIT |
def widget_location_data(self):
"""All location data for the item, meant to be used in the location
widget.
"""
location_data = self.location_data
return {
'address': location_data['address'],
'room_name': location_data['room_name'],
'room_id':... | All location data for the item, meant to be used in the location
widget.
| widget_location_data | python | indico/indico | indico/core/db/sqlalchemy/locations.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/locations.py | MIT |
def prepare_db(empty=False, root_path=None, verbose=True, force=False):
"""Initialize an empty database (create tables, set alembic rev to HEAD)."""
if not _require_pg_version(13, force=force):
return False
if not _require_encoding('UTF8'):
return False
if not _require_extensions('unacce... | Initialize an empty database (create tables, set alembic rev to HEAD). | prepare_db | python | indico/indico | indico/core/db/sqlalchemy/migration.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/migration.py | MIT |
def serialize_email_principal(email):
"""Serialize email principal to a simple dict."""
return {
'_type': 'Email',
'email': email.email,
'id': email.name,
'name': email.name,
'identifier': email.identifier
} | Serialize email principal to a simple dict. | serialize_email_principal | python | indico/indico | indico/core/db/sqlalchemy/principals.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/principals.py | MIT |
def get_emails(self):
"""Get a set of all unique emails associated with this principal.
For users, this is just the primary email (or nothing for the system user).
For anything group-like it is the primary email address of each group member
who has an Indico account.
"""
... | Get a set of all unique emails associated with this principal.
For users, this is just the primary email (or nothing for the system user).
For anything group-like it is the primary email address of each group member
who has an Indico account.
| get_emails | python | indico/indico | indico/core/db/sqlalchemy/principals.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/principals.py | MIT |
def get_users(self):
"""Get a set of all users associated with this principal.
For users this is just the user itself. For anything group-like this
returns all members.
"""
if self.type == PrincipalType.user:
return {self.user}
elif self.type in (PrincipalTyp... | Get a set of all users associated with this principal.
For users this is just the user itself. For anything group-like this
returns all members.
| get_users | python | indico/indico | indico/core/db/sqlalchemy/principals.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/principals.py | MIT |
def merge_users(cls, target, source, relationship_attr):
"""Merge two users in the ACL.
:param target: The target user of the merge.
:param source: The user that is being merged into `target`.
:param relationship_attr: The name of the relationship pointing
... | Merge two users in the ACL.
:param target: The target user of the merge.
:param source: The user that is being merged into `target`.
:param relationship_attr: The name of the relationship pointing
to the object associated with the ACL
... | merge_users | python | indico/indico | indico/core/db/sqlalchemy/principals.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/principals.py | MIT |
def replace_email_with_user(cls, user, relationship_attr):
"""
Replace all email-based entries matching the user's email
addresses with user-based entries.
If the user is already in the ACL, the two entries are merged.
:param user: A User object.
:param relationship_att... |
Replace all email-based entries matching the user's email
addresses with user-based entries.
If the user is already in the ACL, the two entries are merged.
:param user: A User object.
:param relationship_attr: The name of the relationship pointing
... | replace_email_with_user | python | indico/indico | indico/core/db/sqlalchemy/principals.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/principals.py | MIT |
def has_management_permission(self, permission=None, explicit=False):
"""Check whether a principal has a certain management permission.
The check always succeeds if the user is a full manager; in
that case the list of permissions is ignored.
:param permission: The permission to check f... | Check whether a principal has a certain management permission.
The check always succeeds if the user is a full manager; in
that case the list of permissions is ignored.
:param permission: The permission to check for or 'ANY' to check for any
management permission.
... | has_management_permission | python | indico/indico | indico/core/db/sqlalchemy/principals.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/principals.py | MIT |
def is_self_protected(self):
"""Check whether the object itself is protected.
If you also care about inherited protection from a parent,
use `is_protected` instead.
"""
if self.disable_protection_mode:
raise NotImplementedError
return self.protection_mode == ... | Check whether the object itself is protected.
If you also care about inherited protection from a parent,
use `is_protected` instead.
| is_self_protected | python | indico/indico | indico/core/db/sqlalchemy/protection.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/protection.py | MIT |
def is_protected(self):
"""
Check whether this object is protected, either by itself or
by inheriting from a protected object.
"""
if self.disable_protection_mode:
raise NotImplementedError
if self.is_inheriting:
# Unlisted events inherit protectio... |
Check whether this object is protected, either by itself or
by inheriting from a protected object.
| is_protected | python | indico/indico | indico/core/db/sqlalchemy/protection.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/protection.py | MIT |
def can_access(self, user, allow_admin=True):
"""Check if the user can access the object.
:param user: The :class:`.User` to check. May be None if the
user is not logged in.
:param allow_admin: If admin users should always have access
"""
if self.disable_pro... | Check if the user can access the object.
:param user: The :class:`.User` to check. May be None if the
user is not logged in.
:param allow_admin: If admin users should always have access
| can_access | python | indico/indico | indico/core/db/sqlalchemy/protection.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/protection.py | MIT |
def check_access_key(self, access_key=None):
"""Check whether an access key is valid for the object.
:param access_key: Use the given access key instead of taking
it from the session.
"""
assert self.allow_access_key
if not self.access_key:
... | Check whether an access key is valid for the object.
:param access_key: Use the given access key instead of taking
it from the session.
| check_access_key | python | indico/indico | indico/core/db/sqlalchemy/protection.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/protection.py | MIT |
def _check_speaker_access(self, user):
"""Check whether speakers can access this protected object."""
return (
self.allow_speakers # The class supports allowing speakers
and self.speakers_can_access # The database says speakers are allowed here
and getattr(self, 'ev... | Check whether speakers can access this protected object. | _check_speaker_access | python | indico/indico | indico/core/db/sqlalchemy/protection.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/protection.py | MIT |
def set_session_access_key(self, access_key):
"""Store an access key for the object in the session.
:param access_key: The access key to store. It is not checked
for validity.
"""
assert self.allow_access_key
session.setdefault('access_keys', {})[self.... | Store an access key for the object in the session.
:param access_key: The access key to store. It is not checked
for validity.
| set_session_access_key | python | indico/indico | indico/core/db/sqlalchemy/protection.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/protection.py | MIT |
def update_principal(self, principal, read_access=None, quiet=False):
"""Update access privileges for the given principal.
:param principal: A `User`, `GroupProxy` or `EmailPrincipal` instance.
:param read_access: If the principal should have explicit read
access to ... | Update access privileges for the given principal.
:param principal: A `User`, `GroupProxy` or `EmailPrincipal` instance.
:param read_access: If the principal should have explicit read
access to the object.
:param quiet: Whether the ACL change should happen silently.
... | update_principal | python | indico/indico | indico/core/db/sqlalchemy/protection.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/protection.py | MIT |
def remove_principal(self, principal, quiet=False):
"""Revoke all access privileges for the given principal.
This method doesn't do anything if the user is not in the
object's ACL.
:param principal: A `User`, `GroupProxy` or `EmailPrincipal` instance.
:param quiet: Whether the ... | Revoke all access privileges for the given principal.
This method doesn't do anything if the user is not in the
object's ACL.
:param principal: A `User`, `GroupProxy` or `EmailPrincipal` instance.
:param quiet: Whether the ACL change should happen silently.
This i... | remove_principal | python | indico/indico | indico/core/db/sqlalchemy/protection.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/protection.py | MIT |
def all_manager_emails(self):
"""Return the emails of all managers."""
# We ignore email principals here. They never signed up in indico anyway...
return {p.principal.email
for p in self.acl_entries
if p.type == PrincipalType.user and p.has_management_permission()... | Return the emails of all managers. | all_manager_emails | python | indico/indico | indico/core/db/sqlalchemy/protection.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/protection.py | MIT |
def can_manage(self, user, permission=None, allow_admin=True, check_parent=True, explicit_permission=False):
"""Check if the user can manage the object.
:param user: The :class:`.User` to check. May be None if the
user is not logged in.
:param: permission: The management pe... | Check if the user can manage the object.
:param user: The :class:`.User` to check. May be None if the
user is not logged in.
:param: permission: The management permission that is needed for
the check to succeed. If not specified, full
... | can_manage | python | indico/indico | indico/core/db/sqlalchemy/protection.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/protection.py | MIT |
def update_principal(self, principal, read_access=None, full_access=None, permissions=None, add_permissions=None,
del_permissions=None, quiet=False):
"""Update access privileges for the given principal.
If the principal is not in the ACL, it will be added if
necessary. ... | Update access privileges for the given principal.
If the principal is not in the ACL, it will be added if
necessary. If the changes remove all its privileges, it
will be removed from the ACL.
:param principal: A `User`, `GroupProxy` or `EmailPrincipal` instance.
:param read_ac... | update_principal | python | indico/indico | indico/core/db/sqlalchemy/protection.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/protection.py | MIT |
def get_manager_emails(self, *, include_groups=True, permission=None, explicit=False):
"""Get the emails of all managers.
:param include_groups: whether to also include group members
"""
return set(itertools.chain.from_iterable(
x.get_emails()
for x in self.acl_e... | Get the emails of all managers.
:param include_groups: whether to also include group members
| get_manager_emails | python | indico/indico | indico/core/db/sqlalchemy/protection.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/protection.py | MIT |
def _get_acl_data(obj, principal):
"""Helper function to get the necessary data for ACL modifications.
:param obj: A `ProtectionMixin` instance
:param principal: A User or GroupProxy uinstance
:return: A tuple containing the principal class and the existing
ACL entry for the given principa... | Helper function to get the necessary data for ACL modifications.
:param obj: A `ProtectionMixin` instance
:param principal: A User or GroupProxy uinstance
:return: A tuple containing the principal class and the existing
ACL entry for the given principal if it exists.
| _get_acl_data | python | indico/indico | indico/core/db/sqlalchemy/protection.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/protection.py | MIT |
def _resolve_principal(principal):
"""Helper function to convert an email principal to a user if possible.
:param principal: A `User`, `GroupProxy` or `EmailPrincipal` instance.
"""
if isinstance(principal, EmailPrincipal):
return principal.user or principal
return principal | Helper function to convert an email principal to a user if possible.
:param principal: A `User`, `GroupProxy` or `EmailPrincipal` instance.
| _resolve_principal | python | indico/indico | indico/core/db/sqlalchemy/protection.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/protection.py | MIT |
def get_review_rating(self, review, allow_create=False):
"""Get the rating given in particular review.
:param review: the review object
:param allow_create: if there is not rating for that review a new one is created
"""
results = [rating for rating in review.ratings if rating.q... | Get the rating given in particular review.
:param review: the review object
:param allow_create: if there is not rating for that review a new one is created
| get_review_rating | python | indico/indico | indico/core/db/sqlalchemy/review_questions.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/review_questions.py | MIT |
def fts_matches(column, search_string, *, exact=False):
"""Check whether a fts-indexed column matches a search string.
To be used in a SQLAlchemy `filter` call.
:param column: The column to search in
:param search_string: A string to search for
:param exact: Whether to search for the exact string
... | Check whether a fts-indexed column matches a search string.
To be used in a SQLAlchemy `filter` call.
:param column: The column to search in
:param search_string: A string to search for
:param exact: Whether to search for the exact string
| fts_matches | python | indico/indico | indico/core/db/sqlalchemy/searchable.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/searchable.py | MIT |
def define_unaccented_lowercase_index(column, table=None, custom_name=None):
"""Define an index that uses the indico_unaccent function.
Since this is usually used for searching, the column's value is
also converted to lowercase before being unaccented. To make proper
use of this index, use this criteri... | Define an index that uses the indico_unaccent function.
Since this is usually used for searching, the column's value is
also converted to lowercase before being unaccented. To make proper
use of this index, use this criterion when querying the table::
db.func.indico.indico_unaccent(db.func.lower(c... | define_unaccented_lowercase_index | python | indico/indico | indico/core/db/sqlalchemy/custom/unaccent.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/custom/unaccent.py | MIT |
def astimezone(self, tz):
"""Convert the datetime to a specific timezone.
This is useful if you want e.g. to cast to Date afterwards
but need a specific timezone instead of UTC.
When accessing the value returned by this method in Python
it will be a naive da... | Convert the datetime to a specific timezone.
This is useful if you want e.g. to cast to Date afterwards
but need a specific timezone instead of UTC.
When accessing the value returned by this method in Python
it will be a naive datetime object in the specified time
... | astimezone | python | indico/indico | indico/core/db/sqlalchemy/custom/utcdatetime.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/custom/utcdatetime.py | MIT |
def get_all_tables(db):
"""Return a dict containing all tables grouped by schema."""
inspector = inspect(db.engine)
schemas = sorted(set(inspector.get_schema_names()) - {'information_schema'})
return dict(zip(schemas, (inspector.get_table_names(schema=schema) for schema in schemas), strict=True)) | Return a dict containing all tables grouped by schema. | get_all_tables | python | indico/indico | indico/core/db/sqlalchemy/util/management.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/util/management.py | MIT |
def delete_all_tables(db):
"""Drop all tables in the database."""
conn = db.engine.connect()
transaction = conn.begin()
inspector = inspect(db.engine)
metadata = MetaData()
all_schema_tables = get_all_tables(db)
tables = []
all_fkeys = []
for schema, schema_tables in all_schema_tabl... | Drop all tables in the database. | delete_all_tables | python | indico/indico | indico/core/db/sqlalchemy/util/management.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/util/management.py | MIT |
def create_all_tables(db, verbose=False, add_initial_data=True):
"""Create all tables and required initial objects."""
from indico.core.oauth.models.applications import OAuthApplication, SystemAppType
from indico.modules.categories import Category
from indico.modules.categories.models.categories import ... | Create all tables and required initial objects. | create_all_tables | python | indico/indico | indico/core/db/sqlalchemy/util/management.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/util/management.py | MIT |
def paginate(self, *, page=1, per_page=25, show_all=False) -> Pagination:
"""Paginate a query object.
This behaves almost like the default `paginate` method from
Flask-SQLAlchemy but allows showing all results on a single page.
:param page: Number of the page to return.
:param ... | Paginate a query object.
This behaves almost like the default `paginate` method from
Flask-SQLAlchemy but allows showing all results on a single page.
:param page: Number of the page to return.
:param per_page: Number of items per page.
:param show_all: Whether to show all the ... | paginate | python | indico/indico | indico/core/db/sqlalchemy/util/models.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/util/models.py | MIT |
def signal_query(self, query_name, **kwargs):
"""Return a query object that may have been modified by a signal handler.
:param query_name: A descriptive name to provide context to signal handlers.
:return: A query object.
"""
queries = values_from_signal(signals.core.db_query.se... | Return a query object that may have been modified by a signal handler.
:param query_name: A descriptive name to provide context to signal handlers.
:return: A query object.
| signal_query | python | indico/indico | indico/core/db/sqlalchemy/util/models.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/util/models.py | MIT |
def get(cls, oid, is_deleted: bool | None = None) -> Self | None:
"""Get an object based on its primary key.
:param oid: The primary key of the object
:param is_deleted: If specified, ``None`` will be returned if
the ``is_deleted`` attribute of the object
... | Get an object based on its primary key.
:param oid: The primary key of the object
:param is_deleted: If specified, ``None`` will be returned if
the ``is_deleted`` attribute of the object
does not match the specified value. This
... | get | python | indico/indico | indico/core/db/sqlalchemy/util/models.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/util/models.py | MIT |
def get_or_404(cls, oid, is_deleted=None):
"""Get an object based on its primary key, raising a 404 if not found.
:param oid: The primary key of the object
:param is_deleted: If specified, a 404 error will be returned if the
`is_deleted` attribute of the object does n... | Get an object based on its primary key, raising a 404 if not found.
:param oid: The primary key of the object
:param is_deleted: If specified, a 404 error will be returned if the
`is_deleted` attribute of the object does not match
the specified valu... | get_or_404 | python | indico/indico | indico/core/db/sqlalchemy/util/models.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/util/models.py | MIT |
def preload_relationships(cls, query, *relationships, **kwargs):
"""Preload relationships for all objects from a query.
:param query: A SQLAlchemy query object.
:param relationships: The names of relationships to preload.
:param strategy: The loading strategy to use for the
... | Preload relationships for all objects from a query.
:param query: A SQLAlchemy query object.
:param relationships: The names of relationships to preload.
:param strategy: The loading strategy to use for the
relationships. Defaults to `joinedload` and
... | preload_relationships | python | indico/indico | indico/core/db/sqlalchemy/util/models.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/util/models.py | MIT |
def populate_from_dict(self, data, keys=None, skip=None, track_changes=True):
"""Populate the object with values in a dictionary.
:param data: a dict containing values to populate the object.
:param keys: If set, only keys from that list are populated.
:param skip: If set, keys from tha... | Populate the object with values in a dictionary.
:param data: a dict containing values to populate the object.
:param keys: If set, only keys from that list are populated.
:param skip: If set, keys from that list are skipped.
:param track_changes: Set to false to disable change tracking... | populate_from_dict | python | indico/indico | indico/core/db/sqlalchemy/util/models.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/util/models.py | MIT |
def populate_from_attrs(self, obj, attrs):
"""Populate the object from another object's attributes.
:param obj: an object
:param attrs: a set containing the attributes to copy
"""
cls = type(self)
for attr in attrs:
if not hasattr(cls, attr):
... | Populate the object from another object's attributes.
:param obj: an object
:param attrs: a set containing the attributes to copy
| populate_from_attrs | python | indico/indico | indico/core/db/sqlalchemy/util/models.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/util/models.py | MIT |
def import_all_models(package_name='indico'):
"""Utility that imports all modules in indico/**/models/.
:param package_name: Package name to scan for models. If unset,
the top-level package containing this file
is used.
"""
package_root = get_package_ro... | Utility that imports all modules in indico/**/models/.
:param package_name: Package name to scan for models. If unset,
the top-level package containing this file
is used.
| import_all_models | python | indico/indico | indico/core/db/sqlalchemy/util/models.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/util/models.py | MIT |
def get_all_models():
"""Get all models SQLAlchemy knows about."""
from indico.core.db import db
return {mapper.class_ for mapper in db.Model.registry.mappers} | Get all models SQLAlchemy knows about. | get_all_models | python | indico/indico | indico/core/db/sqlalchemy/util/models.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/util/models.py | MIT |
def get_default_values(model):
"""Return a dict containing all static default values of a model.
This only takes `default` into account, not `server_default`.
:param model: A SQLAlchemy model
"""
return {attr.key: attr.columns[0].default.arg
for attr in model.__mapper__.column_attrs
... | Return a dict containing all static default values of a model.
This only takes `default` into account, not `server_default`.
:param model: A SQLAlchemy model
| get_default_values | python | indico/indico | indico/core/db/sqlalchemy/util/models.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/util/models.py | MIT |
def get_simple_column_attrs(model):
"""
Return a set containing all "simple" column attributes, i.e.
attributes which map to a table column and are neither primary
key nor foreign key.
This is useful if you want to get a list of attributes that are
usually safe to copy without extra processing ... |
Return a set containing all "simple" column attributes, i.e.
attributes which map to a table column and are neither primary
key nor foreign key.
This is useful if you want to get a list of attributes that are
usually safe to copy without extra processing when creating a
copy of a database obje... | get_simple_column_attrs | python | indico/indico | indico/core/db/sqlalchemy/util/models.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/util/models.py | MIT |
def auto_table_args(cls, **extra_kwargs):
"""Merge SQLAlchemy ``__table_args__`` values.
This is useful when using mixins to compose model classes if the
mixins need to define custom ``__table_args__``. Since defining
them directly they can define ``__auto_table_args`` classproperties
which will th... | Merge SQLAlchemy ``__table_args__`` values.
This is useful when using mixins to compose model classes if the
mixins need to define custom ``__table_args__``. Since defining
them directly they can define ``__auto_table_args`` classproperties
which will then merged in the final model class using the regu... | auto_table_args | python | indico/indico | indico/core/db/sqlalchemy/util/models.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/util/models.py | MIT |
def populate_one_to_one_backrefs(model, *relationships):
"""Populate the backref of a one-to-one relationship on load.
See this post in the SQLAlchemy docs on why it's useful/necessary:
http://docs.sqlalchemy.org/en/latest/orm/loading_relationships.html#creating-custom-load-rules
:param model: The mod... | Populate the backref of a one-to-one relationship on load.
See this post in the SQLAlchemy docs on why it's useful/necessary:
http://docs.sqlalchemy.org/en/latest/orm/loading_relationships.html#creating-custom-load-rules
:param model: The model class.
:param relationships: The names of the relationshi... | populate_one_to_one_backrefs | python | indico/indico | indico/core/db/sqlalchemy/util/models.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/util/models.py | MIT |
def override_attr(attr_name, parent_name, *, fget=None, check_attr_name=None, own_attr_name=None):
"""Create property that overrides an attribute coming from parent.
In order to ensure setter functionality at creation time, ``parent`` must be
initialized before the overriden attribute.
:param attr_nam... | Create property that overrides an attribute coming from parent.
In order to ensure setter functionality at creation time, ``parent`` must be
initialized before the overriden attribute.
:param attr_name: The name of the attribute to be overriden.
:param parent_name: The name of the attribute from which... | override_attr | python | indico/indico | indico/core/db/sqlalchemy/util/models.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/util/models.py | MIT |
def escape_like(value):
"""Escape a string to be used as a plain string in LIKE."""
escape_char = '\\'
return (value
.replace(escape_char, escape_char * 2) # literal escape char needs to be escaped
.replace('%', escape_char + '%') # we don't want % wildcards inside the value
... | Escape a string to be used as a plain string in LIKE. | escape_like | python | indico/indico | indico/core/db/sqlalchemy/util/queries.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/util/queries.py | MIT |
def get_related_object(obj, relationship, criteria):
"""Get an object from a one-to-many relationship.
If the relationship is already loaded, the criteria are evaluated
in Python; otherwise a query is sent to the database to get just
the specified object.
For maximum compatibility between the two ... | Get an object from a one-to-many relationship.
If the relationship is already loaded, the criteria are evaluated
in Python; otherwise a query is sent to the database to get just
the specified object.
For maximum compatibility between the two loading methods, values
consisting of only digits are co... | get_related_object | python | indico/indico | indico/core/db/sqlalchemy/util/queries.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/util/queries.py | MIT |
def get_n_matching(query, n, predicate, *, prefetch_factor=5, preload_bulk=None, offset=0):
"""Get N objects from a query that satisfy a condition.
This queries for ``n * 5`` objects initially and then loads
more objects until no more results are available or ``n`` objects
have been found.
:param ... | Get N objects from a query that satisfy a condition.
This queries for ``n * 5`` objects initially and then loads
more objects until no more results are available or ``n`` objects
have been found.
:param query: A sqlalchemy query object
:param n: The max number of objects to return
:param predi... | get_n_matching | python | indico/indico | indico/core/db/sqlalchemy/util/queries.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/util/queries.py | MIT |
def with_total_rows(query, single_entity=True):
"""Get the result of a query and its total row count.
:param query: a sqlalchemy query
:param single_entity: whether the original query only returns
a single entity. In this case, each
returned result will j... | Get the result of a query and its total row count.
:param query: a sqlalchemy query
:param single_entity: whether the original query only returns
a single entity. In this case, each
returned result will just be that entity
instead of... | with_total_rows | python | indico/indico | indico/core/db/sqlalchemy/util/queries.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/util/queries.py | MIT |
def no_autoflush(fn):
"""Wrap the decorated function in a no-autoflush block."""
@wraps(fn)
def wrapper(*args, **kwargs):
with db.session.no_autoflush:
return fn(*args, **kwargs)
return wrapper | Wrap the decorated function in a no-autoflush block. | no_autoflush | python | indico/indico | indico/core/db/sqlalchemy/util/session.py | https://github.com/indico/indico/blob/master/indico/core/db/sqlalchemy/util/session.py | MIT |
def validate_requested_scope(self):
"""Validate if requested scope is supported by Authorization Server."""
scope = self.request.scope
state = self.request.state
if scope:
allowed = set(scope_to_list(self.request.client.get_allowed_scope(scope)))
requested = set(s... | Validate if requested scope is supported by Authorization Server. | validate_requested_scope | python | indico/indico | indico/core/oauth/grants.py | https://github.com/indico/indico/blob/master/indico/core/oauth/grants.py | MIT |
def check_redirect_uri(self, redirect_uri):
"""Called by authlib to validate the redirect_uri.
Uses a logic similar to the one at GitHub, i.e. protocol and
host/port must match exactly and if there is a path in the
whitelisted URL, the path of the redirect_uri must start with
th... | Called by authlib to validate the redirect_uri.
Uses a logic similar to the one at GitHub, i.e. protocol and
host/port must match exactly and if there is a path in the
whitelisted URL, the path of the redirect_uri must start with
that path.
| check_redirect_uri | python | indico/indico | indico/core/oauth/models/applications.py | https://github.com/indico/indico/blob/master/indico/core/oauth/models/applications.py | MIT |
def init(self):
"""Called when the plugin is being loaded/initialized.
If you want to run custom initialization code, this is the
method to override. Make sure to call the base method or
the other overridable methods in this class will not be
called anymore.
"""
... | Called when the plugin is being loaded/initialized.
If you want to run custom initialization code, this is the
method to override. Make sure to call the base method or
the other overridable methods in this class will not be
called anymore.
| init | python | indico/indico | indico/core/plugins/__init__.py | https://github.com/indico/indico/blob/master/indico/core/plugins/__init__.py | MIT |
def get_blueprints(self):
"""Return blueprints to be registered on the application.
A single blueprint can be returned directly, for multiple blueprint you need
to yield them or return an iterable.
""" | Return blueprints to be registered on the application.
A single blueprint can be returned directly, for multiple blueprint you need
to yield them or return an iterable.
| get_blueprints | python | indico/indico | indico/core/plugins/__init__.py | https://github.com/indico/indico/blob/master/indico/core/plugins/__init__.py | MIT |
def translation_path(self):
"""Return translation files to be used by the plugin.
By default, get <root_path>/translations, unless it does not exist.
"""
translations_path = os.path.join(self.root_path, 'translations')
return translations_path if os.path.exists(translations_path... | Return translation files to be used by the plugin.
By default, get <root_path>/translations, unless it does not exist.
| translation_path | python | indico/indico | indico/core/plugins/__init__.py | https://github.com/indico/indico/blob/master/indico/core/plugins/__init__.py | MIT |
def translation_domain(self):
"""Return the domain for this plugin's translation_path."""
path = self.translation_path
return Domain(path) if path else NullDomain() | Return the domain for this plugin's translation_path. | translation_domain | python | indico/indico | indico/core/plugins/__init__.py | https://github.com/indico/indico/blob/master/indico/core/plugins/__init__.py | MIT |
def inject_bundle(self, name, view_class=None, subclasses=True, condition=None):
"""Inject an asset bundle into Indico's pages.
:param name: Name of the bundle
:param view_class: If a WP class is specified, only inject it into pages using that class
:param subclasses: also inject into s... | Inject an asset bundle into Indico's pages.
:param name: Name of the bundle
:param view_class: If a WP class is specified, only inject it into pages using that class
:param subclasses: also inject into subclasses of `view_class`
:param condition: a callable to determine whether to injec... | inject_bundle | python | indico/indico | indico/core/plugins/__init__.py | https://github.com/indico/indico/blob/master/indico/core/plugins/__init__.py | MIT |
def inject_vars_js(self):
"""
Return a string that will define variables for the plugin in
the vars.js file.
"""
vars_js = self.get_vars_js()
if vars_js:
return f'var {self.name.title()}Plugin = {json.dumps(vars_js)};' |
Return a string that will define variables for the plugin in
the vars.js file.
| inject_vars_js | python | indico/indico | indico/core/plugins/__init__.py | https://github.com/indico/indico/blob/master/indico/core/plugins/__init__.py | MIT |
def settings(cls):
""":class:`SettingsProxy` for the plugin's settings."""
if cls.name is None:
raise RuntimeError('Plugin has not been loaded yet')
instance = cls.instance
with instance.plugin_context(): # in case the default settings come from a property
return... | :class:`SettingsProxy` for the plugin's settings. | settings | python | indico/indico | indico/core/plugins/__init__.py | https://github.com/indico/indico/blob/master/indico/core/plugins/__init__.py | MIT |
def event_settings(cls):
""":class:`EventSettingsProxy` for the plugin's event-specific settings."""
if cls.name is None:
raise RuntimeError('Plugin has not been loaded yet')
instance = cls.instance
with instance.plugin_context(): # in case the default settings come from a p... | :class:`EventSettingsProxy` for the plugin's event-specific settings. | event_settings | python | indico/indico | indico/core/plugins/__init__.py | https://github.com/indico/indico/blob/master/indico/core/plugins/__init__.py | MIT |
def user_settings(cls):
""":class:`UserSettingsProxy` for the plugin's user-specific settings."""
if cls.name is None:
raise RuntimeError('Plugin has not been loaded yet')
instance = cls.instance
with instance.plugin_context(): # in case the default settings come from a prop... | :class:`UserSettingsProxy` for the plugin's user-specific settings. | user_settings | python | indico/indico | indico/core/plugins/__init__.py | https://github.com/indico/indico/blob/master/indico/core/plugins/__init__.py | MIT |
def plugin_url_rule_to_js(endpoint):
"""Like :func:`~indico.web.flask.util.url_rule_to_js` but prepending plugin name prefix to the endpoint."""
if '.' in endpoint[1:]: # 'foo' or '.foo' should not get the prefix
endpoint = f'plugin_{endpoint}'
return url_rule_to_js(endpoint) | Like :func:`~indico.web.flask.util.url_rule_to_js` but prepending plugin name prefix to the endpoint. | plugin_url_rule_to_js | python | indico/indico | indico/core/plugins/__init__.py | https://github.com/indico/indico/blob/master/indico/core/plugins/__init__.py | MIT |
def url_for_plugin(endpoint, *targets, **values):
"""Like :func:`~indico.web.flask.util.url_for` but prepending ``'plugin_'`` to the blueprint name."""
if '.' in endpoint[1:]: # 'foo' or '.foo' should not get the prefix
endpoint = f'plugin_{endpoint}'
return url_for(endpoint, *targets, **values) | Like :func:`~indico.web.flask.util.url_for` but prepending ``'plugin_'`` to the blueprint name. | url_for_plugin | python | indico/indico | indico/core/plugins/__init__.py | https://github.com/indico/indico/blob/master/indico/core/plugins/__init__.py | MIT |
def get_plugin_template_module(template_name, **context):
"""Like :func:`~indico.web.flask.templating.get_template_module`, but using plugin templates."""
template_name = f'{current_plugin.name}:{template_name}'
return get_template_module(template_name, **context) | Like :func:`~indico.web.flask.templating.get_template_module`, but using plugin templates. | get_plugin_template_module | python | indico/indico | indico/core/plugins/__init__.py | https://github.com/indico/indico/blob/master/indico/core/plugins/__init__.py | MIT |
def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
engine = engine_from_config(config.get_section(config.config_ini_section),
prefix='sqlalchemy.',
... | Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
| run_migrations_online | python | indico/indico | indico/core/plugins/alembic/env.py | https://github.com/indico/indico/blob/master/indico/core/plugins/alembic/env.py | MIT |
def bind(self, *args):
"""Return a version of this proxy that is bound to some arguments.
This is useful for specialized versions of the proxy such as
EventSettingsProxy where one might want to provide an easy-to-use
version that does not require the event to be specified in each
... | Return a version of this proxy that is bound to some arguments.
This is useful for specialized versions of the proxy such as
EventSettingsProxy where one might want to provide an easy-to-use
version that does not require the event to be specified in each
method.
:param args: Th... | bind | python | indico/indico | indico/core/settings/proxy.py | https://github.com/indico/indico/blob/master/indico/core/settings/proxy.py | MIT |
def get(self, name):
"""Retrieve an ACL setting.
:param name: Setting name
"""
self._check_name(name)
return get_setting_acl(SettingPrincipal, self, name, self._cache) | Retrieve an ACL setting.
:param name: Setting name
| get | python | indico/indico | indico/core/settings/proxy.py | https://github.com/indico/indico/blob/master/indico/core/settings/proxy.py | MIT |
def set(self, name, acl):
"""Replace an ACL with a new one.
:param name: Setting name
:param acl: A set containing principals (users/groups)
"""
self._check_name(name)
SettingPrincipal.set_acl(self.module, name, acl)
self._flush_cache() | Replace an ACL with a new one.
:param name: Setting name
:param acl: A set containing principals (users/groups)
| set | python | indico/indico | indico/core/settings/proxy.py | https://github.com/indico/indico/blob/master/indico/core/settings/proxy.py | MIT |
def contains_user(self, name, user):
"""Check if a user is in an ACL.
To pass this check, the user can either be in the ACL itself
or in a group in the ACL.
:param name: Setting name
:param user: A :class:`.User`
"""
from indico.util.user import iter_acl
... | Check if a user is in an ACL.
To pass this check, the user can either be in the ACL itself
or in a group in the ACL.
:param name: Setting name
:param user: A :class:`.User`
| contains_user | python | indico/indico | indico/core/settings/proxy.py | https://github.com/indico/indico/blob/master/indico/core/settings/proxy.py | MIT |
def add_principal(self, name, principal):
"""Add a principal to an ACL.
:param name: Setting name
:param principal: A :class:`.User` or a :class:`.GroupProxy`
"""
self._check_name(name)
SettingPrincipal.add_principal(self.module, name, principal)
self._flush_cach... | Add a principal to an ACL.
:param name: Setting name
:param principal: A :class:`.User` or a :class:`.GroupProxy`
| add_principal | python | indico/indico | indico/core/settings/proxy.py | https://github.com/indico/indico/blob/master/indico/core/settings/proxy.py | MIT |
def remove_principal(self, name, principal):
"""Remove a principal from an ACL.
:param name: Setting name
:param principal: A :class:`.User` or a :class:`.GroupProxy`
"""
self._check_name(name)
SettingPrincipal.remove_principal(self.module, name, principal)
self.... | Remove a principal from an ACL.
:param name: Setting name
:param principal: A :class:`.User` or a :class:`.GroupProxy`
| remove_principal | python | indico/indico | indico/core/settings/proxy.py | https://github.com/indico/indico/blob/master/indico/core/settings/proxy.py | MIT |
def get(self, name, default=SettingsProxyBase.default_sentinel):
"""Retrieve the value of a single setting.
:param name: Setting name
:param default: Default value in case the setting does not exist
:return: The settings's value or the default value
"""
self._check_name(... | Retrieve the value of a single setting.
:param name: Setting name
:param default: Default value in case the setting does not exist
:return: The settings's value or the default value
| get | python | indico/indico | indico/core/settings/proxy.py | https://github.com/indico/indico/blob/master/indico/core/settings/proxy.py | MIT |
def set(self, name, value):
"""Set a single setting.
:param name: Setting name
:param value: Setting value; must be JSON-serializable
"""
self._check_name(name)
Setting.set(self.module, name, self._convert_from_python(name, value))
self._flush_cache() | Set a single setting.
:param name: Setting name
:param value: Setting value; must be JSON-serializable
| set | python | indico/indico | indico/core/settings/proxy.py | https://github.com/indico/indico/blob/master/indico/core/settings/proxy.py | MIT |
def set_multi(self, items):
"""Set multiple settings at once.
:param items: Dict containing the new settings
"""
items = {k: self._convert_from_python(k, v) for k, v in items.items()}
self._split_call(items,
lambda x: Setting.set_multi(self.module, x),
... | Set multiple settings at once.
:param items: Dict containing the new settings
| set_multi | python | indico/indico | indico/core/settings/proxy.py | https://github.com/indico/indico/blob/master/indico/core/settings/proxy.py | MIT |
def delete(self, *names):
"""Delete settings.
:param names: One or more names of settings to delete
"""
self._split_call(names,
lambda name: Setting.delete(self.module, *name),
lambda name: SettingPrincipal.delete(self.module, *name))
... | Delete settings.
:param names: One or more names of settings to delete
| delete | python | indico/indico | indico/core/settings/proxy.py | https://github.com/indico/indico/blob/master/indico/core/settings/proxy.py | MIT |
def preload_settings_bulk(proxy, filter_col, filter_values):
"""Preload settings in bulk for a given SettingsProxy.
This is useful for scoped settings proxies such as event or category settings
when you want to preload settings for many objects in a single query.
"""
settings = proxy.query.filter(f... | Preload settings in bulk for a given SettingsProxy.
This is useful for scoped settings proxies such as event or category settings
when you want to preload settings for many objects in a single query.
| preload_settings_bulk | python | indico/indico | indico/core/settings/util.py | https://github.com/indico/indico/blob/master/indico/core/settings/util.py | MIT |
def get_storage(backend_name):
"""Return an FS object for the given backend.
The backend must be defined in the STORAGE_BACKENDS dict in the
indico config. Once a backend has been used it is assumed to
stay there forever or at least as long as it is referenced
somewhere.
Each backend definiti... | Return an FS object for the given backend.
The backend must be defined in the STORAGE_BACKENDS dict in the
indico config. Once a backend has been used it is assumed to
stay there forever or at least as long as it is referenced
somewhere.
Each backend definition uses the ``name:data`` notation, e.... | get_storage | python | indico/indico | indico/core/storage/backend.py | https://github.com/indico/indico/blob/master/indico/core/storage/backend.py | MIT |
def _copy_file(self, source, target, chunk_size=1024*1024):
"""Copy a file, in chunks, from ``source`` to ``target``.
The return value will be the MD5 checksum of the file (hex).
"""
checksum = md5()
while True:
chunk = source.read(chunk_size)
if not chun... | Copy a file, in chunks, from ``source`` to ``target``.
The return value will be the MD5 checksum of the file (hex).
| _copy_file | python | indico/indico | indico/core/storage/backend.py | https://github.com/indico/indico/blob/master/indico/core/storage/backend.py | MIT |
def get_local_path(self, file_id):
"""Return a local path for the file.
While this path MAY point to the permanent location of the
stored file, it MUST NOT be used for anything but read
operations and MUST NOT be used after existing this function's
contextmanager.
:para... | Return a local path for the file.
While this path MAY point to the permanent location of the
stored file, it MUST NOT be used for anything but read
operations and MUST NOT be used after existing this function's
contextmanager.
:param file_id: The ID of the file within the stora... | get_local_path | python | indico/indico | indico/core/storage/backend.py | https://github.com/indico/indico/blob/master/indico/core/storage/backend.py | MIT |
def content_type(cls):
"""The MIME type of the file."""
return db.Column(
db.String,
nullable=not cls.file_required
) | The MIME type of the file. | content_type | python | indico/indico | indico/core/storage/models.py | https://github.com/indico/indico/blob/master/indico/core/storage/models.py | MIT |
def size(cls):
"""The size of the file (in bytes).
Automatically assigned when `save()` is called.
"""
return db.Column(
db.BigInteger,
nullable=not cls.file_required
) | The size of the file (in bytes).
Automatically assigned when `save()` is called.
| size | python | indico/indico | indico/core/storage/models.py | https://github.com/indico/indico/blob/master/indico/core/storage/models.py | MIT |
def md5(cls):
"""An MD5 hash of the file.
Automatically assigned when `save()` is called.
"""
return db.Column(
db.String,
nullable=not cls.file_required
) | An MD5 hash of the file.
Automatically assigned when `save()` is called.
| md5 | python | indico/indico | indico/core/storage/models.py | https://github.com/indico/indico/blob/master/indico/core/storage/models.py | MIT |
def created_dt(cls):
"""The date/time when the file was uploaded."""
if not cls.add_file_date_column:
return None
return db.Column(
UTCDateTime,
nullable=not cls.file_required,
default=now_utc
) | The date/time when the file was uploaded. | created_dt | python | indico/indico | indico/core/storage/models.py | https://github.com/indico/indico/blob/master/indico/core/storage/models.py | MIT |
def storage(self):
"""The Storage object used to store the file."""
if self.storage_backend is None:
raise RuntimeError('No storage backend set')
return get_storage(self.storage_backend) | The Storage object used to store the file. | storage | python | indico/indico | indico/core/storage/models.py | https://github.com/indico/indico/blob/master/indico/core/storage/models.py | MIT |
def save(self, data):
"""Save a file in the file storage.
This requires the AttachmentFile to be associated with
an Attachment which needs to be associated with a Folder since
the data from these objects is needed to generate the path
used to store the file.
:param data... | Save a file in the file storage.
This requires the AttachmentFile to be associated with
an Attachment which needs to be associated with a Folder since
the data from these objects is needed to generate the path
used to store the file.
:param data: bytes or a file-like object
... | save | python | indico/indico | indico/core/storage/models.py | https://github.com/indico/indico/blob/master/indico/core/storage/models.py | MIT |
def open(self):
"""Return the stored file as a file-like object."""
if self.storage_file_id is None:
raise Exception('There is no file to open')
return self.storage.open(self.storage_file_id) | Return the stored file as a file-like object. | open | python | indico/indico | indico/core/storage/models.py | https://github.com/indico/indico/blob/master/indico/core/storage/models.py | MIT |
def send(self, inline=True):
"""Send the file to the user."""
if self.storage_file_id is None:
raise Exception('There is no file to send')
return self.storage.send_file(self.storage_file_id, self.content_type, self.filename, inline=inline) | Send the file to the user. | send | python | indico/indico | indico/core/storage/models.py | https://github.com/indico/indico/blob/master/indico/core/storage/models.py | MIT |
def int_to_roman(value):
"""Convert an integer to Roman numerals."""
if not 0 < value < 4000:
raise ValueError('Int to Roman Error: Argument must be between 1 and 3999')
ints = (1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1)
nums = ('m', 'cm', 'd', 'cd', 'c', 'xc', 'l', 'xl', 'x', 'ix', '... | Convert an integer to Roman numerals. | int_to_roman | python | indico/indico | indico/legacy/pdfinterface/base.py | https://github.com/indico/indico/blob/master/indico/legacy/pdfinterface/base.py | MIT |
def _drawDots(self):
"""Draw row of dots from the end of the abstract title to the page number."""
try:
freeSpace = int(self.blPara.lines[-1][0])
except TypeError:
# Sometimes we get an ABag instead of a tuple.. in this case we use the extraSpace attribute
# a... | Draw row of dots from the end of the abstract title to the page number. | _drawDots | python | indico/indico | indico/legacy/pdfinterface/base.py | https://github.com/indico/indico/blob/master/indico/legacy/pdfinterface/base.py | MIT |
def firstPage(self, c, doc):
"""Set the first page of the document.
This function is called by doc.build method for the first page.
""" | Set the first page of the document.
This function is called by doc.build method for the first page.
| firstPage | python | indico/indico | indico/legacy/pdfinterface/base.py | https://github.com/indico/indico/blob/master/indico/legacy/pdfinterface/base.py | MIT |
def laterPages(self, c, doc):
"""Set the layout of the page after the first.
This function is called by doc.build method one each page after the first.
""" | Set the layout of the page after the first.
This function is called by doc.build method one each page after the first.
| laterPages | python | indico/indico | indico/legacy/pdfinterface/base.py | https://github.com/indico/indico/blob/master/indico/legacy/pdfinterface/base.py | MIT |
def __init__(self, indexedFlowable, filename, firstPageNumber=1, include_toc=False, **kw):
"""Toc is the TableOfContents object
indexedFlowale is a dictionnary with flowables as key and a dictionnary as value.
the sub-dictionnary have two key:
text: the text which will br pri... | Toc is the TableOfContents object
indexedFlowale is a dictionnary with flowables as key and a dictionnary as value.
the sub-dictionnary have two key:
text: the text which will br print in the table
level: the level of the entry( modifying the indentation and the polic... | __init__ | python | indico/indico | indico/legacy/pdfinterface/base.py | https://github.com/indico/indico/blob/master/indico/legacy/pdfinterface/base.py | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.