timApp.item package#

Submodules#

timApp.item.block module#

class timApp.item.block.Block(**kwargs)[source]#

Bases: sqlalchemy.ext.declarative.api.Model

The “base class” for all database objects that are part of the permission system.

accesses#
add_rights(groups, access_type: timApp.auth.accesstype.AccessType)[source]#
answerupload#
children#
created#

When this Block was created.

description#

Additional information about the Block. This is used for different purposes by different BlockTypes, so it isn’t merely a “description”.

docentries#
folder#
id#

A unique identifier for the Block.

internalmessage: timApp.messaging.timMessage.internalmessage_models.InternalMessage | None#
internalmessage_display: timApp.messaging.timMessage.internalmessage_models.InternalMessageDisplay | None#
is_unpublished()[source]#
latest_revision_id#

Old field that is not used anymore.

managed_messagelist: timApp.messaging.messagelist.messagelist_models.MessageListModel | None#
managed_usergroup: timApp.user.usergroup.UserGroup | None#
modified#

When this Block was last modified.

notifications#
property owner_accesses#
property owners: list[timApp.user.usergroup.UserGroup]#
property parent: Folder#
parents#
relevance#
set_owner(usergroup: timApp.user.usergroup.UserGroup)[source]#

Changes the owner group for a block.

Parameters

usergroup – The new usergroup.

tags: list[timApp.item.tag.Tag]#
translation#
type_id#

Type of the Block, see BlockType enum for possible types.

class timApp.item.block.BlockType(value)[source]#

Bases: enum.Enum

An enumeration.

Answer = 3#
Comment = 1#
Document = 0#
File = 7#
Folder = 6#
Image = 4#
Note = 2#
Reading = 5#
ScheduledFunction = 9#
Task = 10#
Upload = 8#
static from_str(type_name: str) timApp.item.block.BlockType[source]#
timApp.item.block.copy_default_rights(item, item_type: timApp.item.block.BlockType, owners_to_skip: Optional[list[timApp.user.usergroup.UserGroup]] = None)[source]#
timApp.item.block.insert_block(block_type: timApp.item.block.BlockType, description: str | None, owner_groups: Optional[list[timApp.user.usergroup.UserGroup]] = None) timApp.item.block.Block[source]#

Inserts a block to database.

Parameters
  • description – The name (description) of the block.

  • owner_groups – The owner groups of the block.

  • block_type – The type of the block.

Returns

The id of the block.

timApp.item.blockassociation module#

class timApp.item.blockassociation.BlockAssociation(**kwargs)[source]#

Bases: sqlalchemy.ext.declarative.api.Model

Associates blocks with other blocks. Currently only used for associating uploaded files with documents.

child#

The child Block.

parent#

The parent Block.

timApp.item.blockrelevance module#

class timApp.item.blockrelevance.BlockRelevance(**kwargs)[source]#

Bases: sqlalchemy.ext.declarative.api.Model

A relevance value of a block (used in search).

block_id#
relevance#

timApp.item.copy_rights module#

timApp.item.copy_rights.copy_rights(source: timApp.item.item.Item, dest: timApp.item.item.Item, new_owner: timApp.user.user.User, copy_active=True, copy_expired=True) None[source]#

timApp.item.distribute_rights module#

class timApp.item.distribute_rights.ChangeStartTimeGroupOp(type: Literal['changestarttimegroup'], group: str, starttime: datetime.datetime, timestamp: datetime.datetime)[source]#

Bases: object

group: str#
starttime: datetime.datetime#
timestamp: datetime.datetime#
type: Literal['changestarttimegroup']#
class timApp.item.distribute_rights.ChangeTimeGroupOp(type: Literal['changetimegroup'], group: str, secs: int, timestamp: datetime.datetime)[source]#

Bases: object

group: str#
secs: int#
timestamp: datetime.datetime#
type: Literal['changetimegroup']#
class timApp.item.distribute_rights.ChangeTimeOp(type: Literal['changetime'], email: str, secs: int, timestamp: datetime.datetime)[source]#

Bases: object

email: str#
secs: int#
timestamp: datetime.datetime#
type: Literal['changetime']#
class timApp.item.distribute_rights.ConfirmGroupOp(type: Literal['confirmgroup'], group: str, timestamp: datetime.datetime)[source]#

Bases: object

group: str#
timestamp: datetime.datetime#
type: Literal['confirmgroup']#
class timApp.item.distribute_rights.ConfirmOp(type: Literal['confirm'], email: str, timestamp: datetime.datetime)[source]#

Bases: object

email: str#
timestamp: datetime.datetime#
type: Literal['confirm']#
class timApp.item.distribute_rights.QuitOp(type: Literal['quit'], email: str, timestamp: datetime.datetime)[source]#

Bases: object

email: str#
timestamp: datetime.datetime#
type: Literal['quit']#
class timApp.item.distribute_rights.Right(require_confirm: bool, duration_from: datetime.datetime | None, duration_to: datetime.datetime | None, duration: isodate.duration.Duration | None, accessible_from: datetime.datetime | None, accessible_to: datetime.datetime | None)[source]#

Bases: object

accessible_from: datetime.datetime | None#
accessible_to: datetime.datetime | None#
duration: isodate.duration.Duration | None#
duration_from: datetime.datetime | None#
duration_to: datetime.datetime | None#
require_confirm: bool#
class timApp.item.distribute_rights.RightEntry(email: str, right: timApp.item.distribute_rights.Right)[source]#

Bases: object

email: str#
right: timApp.item.distribute_rights.Right#
class timApp.item.distribute_rights.RightLog(initial_right: timApp.item.distribute_rights.Right, group_cache: dict[str, list[str]] = <factory>, op_history: DefaultDict[str, list[timApp.item.distribute_rights.RightLogEntry]] = <factory>)[source]#

Bases: object

add_op(r: Union[timApp.item.distribute_rights.ConfirmOp, timApp.item.distribute_rights.UnlockOp, timApp.item.distribute_rights.ChangeTimeOp, timApp.item.distribute_rights.QuitOp, timApp.item.distribute_rights.UndoConfirmOp, timApp.item.distribute_rights.UndoQuitOp, timApp.item.distribute_rights.ChangeTimeGroupOp, timApp.item.distribute_rights.ChangeStartTimeGroupOp, timApp.item.distribute_rights.ConfirmGroupOp]) None[source]#
get_group_emails(r: Union[timApp.item.distribute_rights.ChangeTimeGroupOp, timApp.item.distribute_rights.ChangeStartTimeGroupOp, timApp.item.distribute_rights.ConfirmGroupOp]) list[str][source]#
get_right(email: str) timApp.item.distribute_rights.Right[source]#
group_cache: dict[str, list[str]]#
initial_right: timApp.item.distribute_rights.Right#
latest_op(email: str) timApp.item.distribute_rights.RightLogEntry | None[source]#
op_history: DefaultDict[str, list[timApp.item.distribute_rights.RightLogEntry]]#
process_group_rights(emails: list[str], fn: Callable[[timApp.item.distribute_rights.Right, timApp.item.distribute_rights.T], None], r: timApp.item.distribute_rights.T) None[source]#
class timApp.item.distribute_rights.RightLogEntry(op: Union[timApp.item.distribute_rights.ConfirmOp, timApp.item.distribute_rights.UnlockOp, timApp.item.distribute_rights.ChangeTimeOp, timApp.item.distribute_rights.QuitOp, timApp.item.distribute_rights.UndoConfirmOp, timApp.item.distribute_rights.UndoQuitOp, timApp.item.distribute_rights.ChangeTimeGroupOp, timApp.item.distribute_rights.ChangeStartTimeGroupOp, timApp.item.distribute_rights.ConfirmGroupOp], right: timApp.item.distribute_rights.Right)[source]#

Bases: object

op: Union[timApp.item.distribute_rights.ConfirmOp, timApp.item.distribute_rights.UnlockOp, timApp.item.distribute_rights.ChangeTimeOp, timApp.item.distribute_rights.QuitOp, timApp.item.distribute_rights.UndoConfirmOp, timApp.item.distribute_rights.UndoQuitOp, timApp.item.distribute_rights.ChangeTimeGroupOp, timApp.item.distribute_rights.ChangeStartTimeGroupOp, timApp.item.distribute_rights.ConfirmGroupOp]#
right: timApp.item.distribute_rights.Right#
class timApp.item.distribute_rights.UndoConfirmOp(type: Literal['undoconfirm'], email: str, timestamp: datetime.datetime)[source]#

Bases: object

email: str#
timestamp: datetime.datetime#
type: Literal['undoconfirm']#
class timApp.item.distribute_rights.UndoQuitOp(type: Literal['undoquit'], email: str, timestamp: datetime.datetime)[source]#

Bases: object

email: str#
timestamp: datetime.datetime#
type: Literal['undoquit']#
class timApp.item.distribute_rights.UnlockOp(type: Literal['unlock'], email: str, timestamp: datetime.datetime)[source]#

Bases: object

email: str#
timestamp: datetime.datetime#
type: Literal['unlock']#
timApp.item.distribute_rights.change_starttime(right: timApp.item.distribute_rights.Right, op: timApp.item.distribute_rights.ChangeStartTimeGroupOp) None[source]#
timApp.item.distribute_rights.change_starttime_route(group: str, target: str, minutes: int, redir: str) flask.wrappers.Response[source]#
timApp.item.distribute_rights.change_time(right: timApp.item.distribute_rights.Right, op: timApp.item.distribute_rights.ChangeTimeOp | timApp.item.distribute_rights.ChangeTimeGroupOp) None[source]#
timApp.item.distribute_rights.confirm_group(right: timApp.item.distribute_rights.Right, op: timApp.item.distribute_rights.ConfirmGroupOp) None[source]#
timApp.item.distribute_rights.do_dist_rights(op: Union[timApp.item.distribute_rights.ConfirmOp, timApp.item.distribute_rights.UnlockOp, timApp.item.distribute_rights.ChangeTimeOp, timApp.item.distribute_rights.QuitOp, timApp.item.distribute_rights.UndoConfirmOp, timApp.item.distribute_rights.UndoQuitOp, timApp.item.distribute_rights.ChangeTimeGroupOp, timApp.item.distribute_rights.ChangeStartTimeGroupOp, timApp.item.distribute_rights.ConfirmGroupOp], rights: timApp.item.distribute_rights.RightLog, target: str) list[str][source]#
timApp.item.distribute_rights.do_register_right(op: Union[timApp.item.distribute_rights.ConfirmOp, timApp.item.distribute_rights.UnlockOp, timApp.item.distribute_rights.ChangeTimeOp, timApp.item.distribute_rights.QuitOp, timApp.item.distribute_rights.UndoConfirmOp, timApp.item.distribute_rights.UndoQuitOp, timApp.item.distribute_rights.ChangeTimeGroupOp, timApp.item.distribute_rights.ChangeStartTimeGroupOp, timApp.item.distribute_rights.ConfirmGroupOp], target: str) tuple[timApp.item.distribute_rights.RightLog | None, str | None][source]#
timApp.item.distribute_rights.get_current_rights(target: str) tuple[timApp.item.distribute_rights.RightLog, pathlib.Path][source]#
timApp.item.distribute_rights.get_current_rights_route(groups: str, target: str) flask.wrappers.Response[source]#
timApp.item.distribute_rights.read_rights(path: pathlib.Path, index: int) tuple[list[Union[timApp.item.distribute_rights.ConfirmOp, timApp.item.distribute_rights.UnlockOp, timApp.item.distribute_rights.ChangeTimeOp, timApp.item.distribute_rights.QuitOp, timApp.item.distribute_rights.UndoConfirmOp, timApp.item.distribute_rights.UndoQuitOp, timApp.item.distribute_rights.ChangeTimeGroupOp, timApp.item.distribute_rights.ChangeStartTimeGroupOp, timApp.item.distribute_rights.ConfirmGroupOp]], list[dict]][source]#
timApp.item.distribute_rights.receive_right(rights: list[timApp.item.distribute_rights.RightEntry], item_path: str, secret: str) flask.wrappers.Response[source]#
timApp.item.distribute_rights.register_op_to_hosts(op: Union[timApp.item.distribute_rights.ConfirmOp, timApp.item.distribute_rights.UnlockOp, timApp.item.distribute_rights.ChangeTimeOp, timApp.item.distribute_rights.QuitOp, timApp.item.distribute_rights.UndoConfirmOp, timApp.item.distribute_rights.UndoQuitOp, timApp.item.distribute_rights.ChangeTimeGroupOp, timApp.item.distribute_rights.ChangeStartTimeGroupOp, timApp.item.distribute_rights.ConfirmGroupOp], target: str | list[str], is_receiving_backup: bool) list[str][source]#
timApp.item.distribute_rights.register_right(op: Union[timApp.item.distribute_rights.ConfirmOp, timApp.item.distribute_rights.UnlockOp, timApp.item.distribute_rights.ChangeTimeOp, timApp.item.distribute_rights.QuitOp, timApp.item.distribute_rights.UndoConfirmOp, timApp.item.distribute_rights.UndoQuitOp, timApp.item.distribute_rights.ChangeTimeGroupOp, timApp.item.distribute_rights.ChangeStartTimeGroupOp, timApp.item.distribute_rights.ConfirmGroupOp], target: str | list[str], secret: str, is_receiving_backup: bool = False) flask.wrappers.Response[source]#
timApp.item.distribute_rights.register_right_impl(op: Union[timApp.item.distribute_rights.ConfirmOp, timApp.item.distribute_rights.UnlockOp, timApp.item.distribute_rights.ChangeTimeOp, timApp.item.distribute_rights.QuitOp, timApp.item.distribute_rights.UndoConfirmOp, timApp.item.distribute_rights.UndoQuitOp, timApp.item.distribute_rights.ChangeTimeGroupOp, timApp.item.distribute_rights.ChangeStartTimeGroupOp, timApp.item.distribute_rights.ConfirmGroupOp], target: str | list[str], backup: bool = True, distribute: bool = True) list[str][source]#

timApp.item.item module#

class timApp.item.item.Item[source]#

Bases: timApp.item.item.ItemBase

An item that exists in the TIM directory hierarchy. Currently Folder and DocInfo.

static find_by_id(item_id)[source]#
get_relative_path(path: str)[source]#

Gets the item path relative to the given path. The item must be under the path; otherwise TimDbException is thrown.

get_relative_url_for_view(name: str)[source]#
get_url_for_view(name: str)[source]#
property id#

Returns the item id.

property location#
property parent: Folder#
parent_paths() list[tuple[str, str]][source]#
parents_to_root(include_root=True, eager_load_groups=False)[source]#
parents_to_root_eager#
property path#

Returns the Document path, including the language part in case of a translation.

property path_without_lang#

Returns the Document path without the language part in case of a translation.

property public#
property short_name#
property title#
to_json(curr_user: User | None = None)[source]#
property url#
property url_relative#
class timApp.item.item.ItemBase[source]#

Bases: object

An item that can be assigned permissions.

property block: timApp.item.block.Block#
property children#
property id#

Returns the item id.

property last_modified#
property owners#
property parents#
property relevance: timApp.item.blockrelevance.BlockRelevance#

timApp.item.manage module#

Routes for manage view.

class timApp.item.manage.CopyOptions(copy_active_rights: bool = True, copy_expired_rights: bool = False, stop_on_errors: bool = True)[source]#

Bases: object

copy_active_rights: bool = True#
copy_expired_rights: bool = False#
stop_on_errors: bool = True#
class timApp.item.manage.DefaultItemType(value)[source]#

Bases: enum.Enum

An enumeration.

document = 0#
folder = 1#
class timApp.item.manage.DefaultPermissionModel(type: timApp.auth.accesstype.AccessType, time: timApp.item.manage.TimeOpt, groups: list[str], confirm: bool | None, id: int, item_type: timApp.item.manage.DefaultItemType)[source]#

Bases: timApp.item.manage.PermissionSingleEditModel

item_type: timApp.item.manage.DefaultItemType#
class timApp.item.manage.DefaultPermissionRemoveModel(id: int, type: timApp.auth.accesstype.AccessType, group: int, item_type: timApp.item.manage.DefaultItemType)[source]#

Bases: timApp.item.manage.PermissionRemoveModel

item_type: timApp.item.manage.DefaultItemType#
class timApp.item.manage.EditOption(value)[source]#

Bases: enum.Enum

An enumeration.

Add = 'add'#
Remove = 'remove'#
class timApp.item.manage.PermissionClearModel(paths: list[str], type: timApp.auth.accesstype.AccessType)[source]#

Bases: object

paths: list[str]#
type: timApp.auth.accesstype.AccessType#
class timApp.item.manage.PermissionEditModel(type: timApp.auth.accesstype.AccessType, time: timApp.item.manage.TimeOpt, groups: list[str], confirm: bool | None)[source]#

Bases: object

confirm: bool | None#
group_objects#
groups: list[str]#
property nonexistent_groups#
time: timApp.item.manage.TimeOpt#
type: timApp.auth.accesstype.AccessType#
class timApp.item.manage.PermissionMassEditModel(type: timApp.auth.accesstype.AccessType, time: timApp.item.manage.TimeOpt, groups: list[str], confirm: bool | None, ids: list[int], action: timApp.item.manage.EditOption)[source]#

Bases: timApp.item.manage.PermissionEditModel

action: timApp.item.manage.EditOption#
ids: list[int]#
class timApp.item.manage.PermissionRemoveModel(id: int, type: timApp.auth.accesstype.AccessType, group: int)[source]#

Bases: object

group: int#
id: int#
type: timApp.auth.accesstype.AccessType#
class timApp.item.manage.PermissionSingleEditModel(type: timApp.auth.accesstype.AccessType, time: timApp.item.manage.TimeOpt, groups: list[str], confirm: bool | None, id: int)[source]#

Bases: timApp.item.manage.PermissionEditModel

id: int#
class timApp.item.manage.TimeOpt(type: timApp.item.manage.TimeType, duration: isodate.duration.Duration | None = None, to: datetime.datetime | None = None, ffrom: datetime.datetime | None = None, durationTo: datetime.datetime | None = None, durationFrom: datetime.datetime | None = None)[source]#

Bases: object

duration: isodate.duration.Duration | None = None#
durationFrom: datetime.datetime | None = None#
durationTo: datetime.datetime | None = None#
property duration_timedelta#
effective_opt#
ffrom: datetime.datetime | None = None#
to: datetime.datetime | None = None#
type: timApp.item.manage.TimeType#
class timApp.item.manage.TimeType(value)[source]#

Bases: enum.Enum

An enumeration.

always = 0#
duration = 2#
range = 1#
timApp.item.manage.add_alias(doc_id: int, new_alias: str, public: bool = True) flask.wrappers.Response[source]#
timApp.item.manage.add_default_doc_permission(m: timApp.item.manage.DefaultPermissionModel) flask.wrappers.Response[source]#
timApp.item.manage.add_perm(p: timApp.item.manage.PermissionEditModel, item: timApp.item.item.Item, replace_active_duration: bool = True) list[timApp.auth.auth_models.BlockAccess][source]#
timApp.item.manage.add_permission(m: timApp.item.manage.PermissionSingleEditModel)[source]#
timApp.item.manage.add_permission_basic(doc_id: int, username: str, type: str, duration: int) flask.wrappers.Response[source]#
timApp.item.manage.change_alias(alias: str, new_name: str, public: bool = True) flask.wrappers.Response[source]#
timApp.item.manage.change_title(item_id: int, new_title: str) flask.wrappers.Response[source]#
timApp.item.manage.check_ownership_loss(had_ownership, item)[source]#
timApp.item.manage.clear_permissions(m: timApp.item.manage.PermissionClearModel) flask.wrappers.Response[source]#
timApp.item.manage.confirm_permission(m: timApp.item.manage.PermissionRemoveModel) flask.wrappers.Response[source]#
timApp.item.manage.confirm_permission_url(doc_id: int, username: str, redir: str | None = None)[source]#
timApp.item.manage.copy_folder(from_folder: timApp.folder.folder.Folder, to_folder: timApp.folder.folder.Folder, user_who_copies: timApp.user.user.User, exclude_re: re.Pattern, options: timApp.item.manage.CopyOptions) list[timApp.document.exceptions.ValidationException][source]#
timApp.item.manage.copy_folder_endpoint(folder_id: int, destination: str, exclude: str | None, copy_options: timApp.item.manage.CopyOptions = Field(name='copy_options', type=<class 'timApp.item.manage.CopyOptions'>, default=<dataclasses._MISSING_TYPE object>, default_factory=<class 'timApp.item.manage.CopyOptions'>, init=True, repr=True, hash=None, compare=True, metadata=mappingproxy({}), kw_only=False, _field_type=_FIELD)) flask.wrappers.Response[source]#
timApp.item.manage.copy_folder_preview(folder_id: int, destination: str, exclude: str | None) flask.wrappers.Response[source]#
timApp.item.manage.del_document(doc_id: int) flask.wrappers.Response[source]#
timApp.item.manage.delete_folder(folder_id: int) flask.wrappers.Response[source]#
timApp.item.manage.do_confirm_permission(m: timApp.item.manage.PermissionRemoveModel, i: timApp.document.docinfo.DocInfo, redir: Optional[str] = None)[source]#
timApp.item.manage.edit_permissions(m: timApp.item.manage.PermissionMassEditModel) flask.wrappers.Response[source]#
timApp.item.manage.enum_items(folder: timApp.folder.folder.Folder, exclude_re: re.Pattern) Generator[timApp.item.item.Item, None, None][source]#
timApp.item.manage.expire_permission_url(doc_id: int, username: str, redir: str | None = None)[source]#
timApp.item.manage.get_changelog(doc_id: int, length: int) flask.wrappers.Response[source]#
timApp.item.manage.get_copy_folder_params(folder_id: int, dest: str, exclude: str | None)[source]#
timApp.item.manage.get_default_document_permissions(folder_id: int, object_type: str) flask.wrappers.Response[source]#
timApp.item.manage.get_doc_names(doc_id: int) flask.wrappers.Response[source]#
timApp.item.manage.get_group_and_doc(doc_id: int, username: str) tuple[timApp.user.usergroup.UserGroup, timApp.document.docinfo.DocInfo][source]#
timApp.item.manage.get_pattern(exclude: str | None) re.Pattern[str][source]#
timApp.item.manage.get_permissions(item_id: int) flask.wrappers.Response[source]#
timApp.item.manage.get_trash_folder() timApp.folder.folder.Folder[source]#
timApp.item.manage.log_right(s: str)[source]#
timApp.item.manage.manage(path: str) flask.wrappers.Response | str[source]#
timApp.item.manage.permission_response(m: timApp.item.manage.PermissionEditModel)[source]#
timApp.item.manage.raise_or_redirect(message: str, redir: Optional[str] = None) flask.wrappers.Response[source]#
timApp.item.manage.remove_alias(alias: str) flask.wrappers.Response[source]#
timApp.item.manage.remove_default_doc_permission(m: timApp.item.manage.DefaultPermissionRemoveModel) flask.wrappers.Response[source]#
timApp.item.manage.remove_perm(group: timApp.user.usergroup.UserGroup, b: timApp.item.block.Block, t: timApp.auth.accesstype.AccessType)[source]#
timApp.item.manage.remove_permission(m: timApp.item.manage.PermissionRemoveModel) flask.wrappers.Response[source]#
timApp.item.manage.rename_folder(item_id: int) flask.wrappers.Response[source]#
timApp.item.manage.self_expire_permission(id: int) flask.wrappers.Response[source]#
timApp.item.manage.verify_permission_edit_access(i: Union[timApp.item.item.ItemBase, timApp.item.block.Block], perm_type: timApp.auth.accesstype.AccessType) bool[source]#

Verifies that the user has right to edit a permission.

Parameters
  • i – The item to check for permission.

  • perm_type – The permission type.

Returns

True if owner permission was checked, false if just manage access.

timApp.item.partitioning module#

Functions related to document partitioning.

class timApp.item.partitioning.IndexedViewRange(b: int, e: int, par_count: int)[source]#

Bases: object

b: int#
e: int#
property end_index#
property is_full#
property is_restricted#
par_count: int#
property start_index#
property starts_from_beginning#
to_json(name: Optional[str] = None)[source]#
class timApp.item.partitioning.RequestedViewRange(b: Union[int, str, NoneType], e: Union[int, str, NoneType], size: int | None)[source]#

Bases: object

b: Optional[Union[int, str]]#
e: Optional[Union[int, str]]#
property end_index#
property end_par_id#
property is_full#
property is_restricted#
size: int | None#
property start_index#
property start_par_id#
timApp.item.partitioning.adjust_to_areas(areas: list[tuple[int, int]], b: int, e: int) tuple[int, int][source]#

Ensure range doesn’t cut any areas.

Parameters
  • areas – List of areas.

  • b – Begin index.

  • e – End index.

Returns

b and e adjusted to ranges.

timApp.item.partitioning.decide_view_range(doc_info: timApp.document.docinfo.DocInfo, preferred_set_size: int, index: int = 0, forwards: bool = True, areas: Optional[list[tuple[int, int]]] = None, min_set_size_modifier: float = 0.5) timApp.item.partitioning.IndexedViewRange[source]#

Decide begin and end indices of paragraph set based on preferred size. Avoids making the current part shorter than the piece size due to proximity to begin or end of the document. Also combines remaining paragraphs at the start or end, if they’d be smaller than allowed. For example: With set_size = 50 and modifier = 0.5 this will combine neighboring set if its size is 25 or less.

Parameters
  • doc_info – Document.

  • preferred_set_size – User defined set size. May change depending on document.

  • index – Begin or end index (depending on direction).

  • forwards – Begin index is the start index if true, end index if false (i.e. True = next, False = previous).

  • areas – List of known areas.

  • min_set_size_modifier – Smallest allowed neighboring set compared to set size.

Returns

Adjusted indices for view range.

timApp.item.partitioning.get_doc_version_hash(doc_info: timApp.document.docinfo.DocInfo) str[source]#

Gets version numbers from document and its preambles and creates a hash from them.

Parameters

doc_info – Document.

Returns

Version number hash as a string.

timApp.item.partitioning.get_document_areas(doc: timApp.document.docinfo.DocInfo) list[tuple[int, int]][source]#

Get a list of areas in the document.

Note

Areas inside areas are ignored.

Parameters

doc – Document.

Returns

List of area ranges.

timApp.item.partitioning.get_index_with_header_id(doc_info: timApp.document.docinfo.DocInfo, header_id: str) int | None[source]#

Returns first index containing the given HTML header id.

Parameters
  • doc_info – Document.

  • header_id – HTML header id.

Returns

Index of the corresponding paragraph or None if not found.

Reads piece size from cookie, if it exists.

Parameters

request – Request.

Returns

Piece size integer or None, if cookie not found.

timApp.item.partitioning.get_preamble_count(d: timApp.document.docinfo.DocInfo) int[source]#

Get the amount of preambles in the document.

Parameters

d – Document.

Returns

Preamble count; zero if none were found.

timApp.item.partitioning.int_or_none(s: str)[source]#
timApp.item.partitioning.load_index(file_path: pathlib.Path) dict | None[source]#

Load headers from a file.

Parameters

file_path – Cache file path.

Returns

Parsed contents or None.

timApp.item.partitioning.partition_texts(texts: list[timApp.document.prepared_par.PreparedPar], view_range: timApp.item.partitioning.IndexedViewRange, preamble_count)[source]#

Partition document with preambles taken into account.

Parameters
  • texts – List of processed paragraphs.

  • view_range – Range of normal paragraphs to include.

  • preamble_count – Number of preamble paragraphs to insert.

Returns

List of included paragraphs.

timApp.item.partitioning.save_index(index, file_path: pathlib.Path)[source]#

Save document header data as json.

Parameters
  • index – Headers.

  • file_path – File path.

timApp.item.routes module#

Routes for document view.

class timApp.item.routes.ItemWithRights(i: timApp.item.item.Item, rights: list[timApp.auth.auth_models.BlockAccess])[source]#

Bases: object

i: timApp.item.item.Item#
rights: list[timApp.auth.auth_models.BlockAccess]#
to_json()[source]#
timApp.item.routes.check_updated_pars(doc_id, major, minor)[source]#
timApp.item.routes.create_item_direct(item_path: str, item_type: str, item_title: str, cite: Optional[int] = None, copy: Optional[int] = None, template: Optional[str] = None, use_template: bool = True)[source]#
timApp.item.routes.create_item_route(item_path: str, item_type: str, item_title: str, cite: int | None = None, copy: int | None = None, template: str | None = None, use_template: bool = True)[source]#
timApp.item.routes.doc_access_info(doc_name)[source]#
timApp.item.routes.gen_cache(doc_path: str, same_for_all: bool = False, force: bool = False, print_diffs: bool = False, group: str | None = None)[source]#

Pre-generates document cache for the users with non-expired rights.

Useful for exam documents to reduce server load at the beginning of the exam.

Parameters
  • group – The usergroup for which to generate the cache. If omitted, the users are computed from the currently active (or upcoming) rights.

  • print_diffs – Whether to output diff information about cache content. Each cache entry is compared with the first cache entry.

  • doc_path – Path of the document for which to generate the cache.

  • same_for_all – Whether to use same cache for all users. This speeds up cache generation significantly.

  • force – Whether to force cache generation even if the existing cache seems up-to-date.

timApp.item.routes.get_additional_angular_modules(doc_info: timApp.document.docinfo.DocInfo) set[str][source]#
timApp.item.routes.get_document(doc_info: timApp.document.docinfo.DocInfo, view_range: Union[timApp.item.partitioning.RequestedViewRange, timApp.item.partitioning.IndexedViewRange]) tuple[list[timApp.document.docparagraph.DocParagraph], timApp.item.partitioning.IndexedViewRange][source]#
timApp.item.routes.get_document_relevance(i: timApp.document.docinfo.DocInfo) int[source]#

Returns document relevance value or first non-null parent relevance value. If no relevance was found until root, return default relevance value.

Parameters

i – Document.

Returns

Relevance value.

timApp.item.routes.get_item(item_id: int)[source]#
timApp.item.routes.get_items(folder: str, recurse=False)[source]#
timApp.item.routes.get_linked_groups(i: timApp.item.item.Item) tuple[list[timApp.user.usergroup.UserGroupWithSisuInfo], list[str]][source]#
timApp.item.routes.get_linked_groups_route(item_id: int)[source]#
timApp.item.routes.get_module_ids(js_paths: list[str])[source]#
timApp.item.routes.get_partial_document(doc: timApp.document.document.Document, view_range: Union[timApp.item.partitioning.RequestedViewRange, timApp.item.partitioning.IndexedViewRange]) tuple[list[timApp.document.docparagraph.DocParagraph], timApp.item.partitioning.IndexedViewRange][source]#
timApp.item.routes.get_relevance_route(item_id: int)[source]#

Returns item relevance or first non-null parent relevance. If no relevance was found until root, return default relevance.

Parameters

item_id – Item id.

Returns

Relevance object and whether it was inherited or not set (default).

timApp.item.routes.get_viewrange(doc_id: int, index: int, forwards: int)[source]#
timApp.item.routes.get_viewrange_with_header_id(doc_id: int, header_id: str)[source]#

Route for getting suitable view range for index links.

Parameters
  • doc_id – Document id.

  • header_id – Header id (HTML-attribute id, not the paragraph id).

Returns

View range starting from the header paragraph.

timApp.item.routes.goto_view(item_path, model: timApp.document.viewparams.ViewParams) Union[flask.wrappers.Response, tuple[Any, int]][source]#
timApp.item.routes.index_page()[source]#
timApp.item.routes.index_redirect()[source]#
timApp.item.routes.is_exam_mode(settings: timApp.document.docsettings.DocSettings, rights: dict)[source]#
timApp.item.routes.items_route(folder: str | None = None, folder_id: int | None = None, recursive: bool = False, include_rights: bool = False)[source]#
timApp.item.routes.lecture_view(doc_path)[source]#
timApp.item.routes.par_info(doc_id, par_id)[source]#
timApp.item.routes.preload_personal_folder_and_breadcrumbs(current_user: timApp.user.user.User, doc_info: timApp.document.docinfo.DocInfo)[source]#
timApp.item.routes.render_doc_view(doc_info: timApp.document.docinfo.DocInfo, m: timApp.document.docviewparams.DocViewParams, view_ctx: timApp.document.viewcontext.ViewContext, current_user: timApp.user.user.User, clear_cache: bool) timApp.document.docrenderresult.DocRenderResult[source]#
timApp.item.routes.render_login(item: timApp.document.document.Document | None) Union[flask.wrappers.Response, tuple[Any, int]][source]#
timApp.item.routes.reset_blockrelevance(item_id: int)[source]#

Reset (delete) block relevance.

Parameters

item_id – Item id.

Returns

Ok response.

timApp.item.routes.review_view(doc_name)[source]#
timApp.item.routes.see_answers_view(doc_path)[source]#
timApp.item.routes.set_blockrelevance(item_id: int, value: int)[source]#

Add block relevance or edit if it already exists for the block.

Parameters
  • value – The relevance value.

  • item_id – Item id.

Returns

Ok response.

timApp.item.routes.set_piece_size(pieceSize: int)[source]#

Add cookie for user defined view range (if isn’t set, doc won’t be partitioned).

timApp.item.routes.should_hide_paragraphs(settings: timApp.document.docsettings.DocSettings, rights: dict)[source]#
timApp.item.routes.should_hide_sidemenu(settings: timApp.document.docsettings.DocSettings, rights: dict)[source]#
timApp.item.routes.should_hide_top_buttons(settings: timApp.document.docsettings.DocSettings, rights: dict)[source]#
timApp.item.routes.show_slide(doc_path)[source]#
timApp.item.routes.show_time(s)[source]#
timApp.item.routes.slide_view(doc_path)[source]#
timApp.item.routes.teacher_view(doc_path)[source]#
timApp.item.routes.unset_piece_size()[source]#
timApp.item.routes.velp_view(doc_path)[source]#
timApp.item.routes.view(item_path: str, route: timApp.document.viewcontext.ViewRoute, render_doc: bool = True) Union[flask.wrappers.Response, tuple[Any, int]][source]#
timApp.item.routes.view_document(doc_path)[source]#

timApp.item.routes_tags module#

Routes related to tags.

class timApp.item.routes_tags.TagInfo(name: str, type: timApp.item.tag.TagType, expires: datetime.datetime | None = None, block_id: int | None = None)[source]#

Bases: object

block_id: int | None = None#
expires: datetime.datetime | None = None#
name: str#
to_tag() timApp.item.tag.Tag[source]#
type: timApp.item.tag.TagType#
timApp.item.routes_tags.add_tag(doc: str, tags: list[timApp.item.routes_tags.TagInfo]) flask.wrappers.Response[source]#

Adds a tag-document entry into the database.

Parameters
  • doc – The target document.

  • tags – Tags to add.

:returns Tag adding success response.

timApp.item.routes_tags.add_tags(d: timApp.document.docinfo.DocInfo, tags: list[timApp.item.routes_tags.TagInfo]) None[source]#
timApp.item.routes_tags.check_tag_access(tag: timApp.item.tag.Tag, check_group: bool = True) None[source]#

Checks whether the user is allowed to make changes to the tag type. If not allowed, gives abort response.

Parameters
  • check_group – Whether to check group tag right. Should be false when deleting a tag.

  • tag – The tag to check.

timApp.item.routes_tags.commit_and_ok() flask.wrappers.Response[source]#
timApp.item.routes_tags.edit_tag(doc: str, old_tag: timApp.item.routes_tags.TagInfo, new_tag: timApp.item.routes_tags.TagInfo) flask.wrappers.Response[source]#

Replaces a tag-document entry in the database with new one.

Parameters
  • doc – The target document.

  • old_tag – Tag to remove

  • new_tag – Tag to replace old tag with

:returns Edit success response.

timApp.item.routes_tags.get_all_tags() flask.wrappers.Response[source]#

Gets the list of all unique tags used in any document, regardless of expiration. :returns The list of all unique tag names as list of strings.

timApp.item.routes_tags.get_tagged_document_by_id(doc_id: int) flask.wrappers.Response[source]#

Gets a document and its tags by id. :param doc_id: Searched document id. :return: A DocEntry with tags.

timApp.item.routes_tags.get_tagged_documents() flask.wrappers.Response[source]#

Gets a list of documents that have a certain tag. Options: - Search exact or partial words. - Case sensitivity - Get all other tags in the document as well or don’t fetch them. :returns Response containing list of documents with the searched tag.

timApp.item.routes_tags.get_tags(doc: str) flask.wrappers.Response[source]#

Gets the list of a document’s tags.

Parameters

doc – The target document.

:returns The list of document’s Tag-objects converted into JSON.

timApp.item.routes_tags.remove_tag(doc: str, tag: timApp.item.routes_tags.TagInfo) flask.wrappers.Response[source]#

Removes a tag-document entry from the database.

Parameters
  • doc – The target document.

  • tag – Tag to remove

:returns Removal success response.

timApp.item.routes_tags.set_group_tags(doc: str, groups: list[str], tags: list[timApp.item.routes_tags.TagInfo], groups_expire: datetime.datetime | None = None) flask.wrappers.Response[source]#

timApp.item.scoreboard module#

class timApp.item.scoreboard.DocScoreInfo(doc: timApp.document.docinfo.DocInfo, total: float, maxTotal: float, tasks: list[timApp.item.scoreboard.TaskScoreInfo])[source]#

Bases: object

doc: timApp.document.docinfo.DocInfo#
maxTotal: float#
tasks: list[timApp.item.scoreboard.TaskScoreInfo]#
total: float#
class timApp.item.scoreboard.TaskScoreInfo(taskName: str, fragId: str, points: float, maxPoints: float)[source]#

Bases: object

fragId: str#
maxPoints: float#
points: float#
taskName: str#
timApp.item.scoreboard.get_score_infos(folder: timApp.folder.folder.Folder, doc_paths: list[str], user_ctx: timApp.document.usercontext.UserContext, lang_id: Optional[str] = None) list[timApp.item.scoreboard.DocScoreInfo][source]#
timApp.item.scoreboard.get_score_infos_if_enabled(doc_info: timApp.document.docinfo.DocInfo, doc_settings: timApp.document.docsettings.DocSettings, user_ctx: timApp.document.usercontext.UserContext) list[timApp.item.scoreboard.DocScoreInfo] | None[source]#

timApp.item.tag module#

class timApp.item.tag.Tag(**kwargs)[source]#

Bases: sqlalchemy.ext.declarative.api.Model

A tag with associated document id, tag name, type and expiration date.

block#
block_id#
expires#
get_group_name() str | None[source]#
property has_tag_special_chars#

Checks whether the tag name has characters other than (lower or upper case) a-ö, numbers 0-9, slashes, underscores, spaces or other allowed characters. characters. :return:

name#
type#
class timApp.item.tag.TagType(value)[source]#

Bases: enum.Enum

Type for a Tag.

CourseCode = 2#

The Tag is a course code.

Regular = 1#

A regular tag.

Subject = 3#

The Tag is the name for a subject.

timApp.item.taskblock module#

class timApp.item.taskblock.TaskBlock(**kwargs)[source]#

Bases: sqlalchemy.ext.declarative.api.Model

block#
static get_block_by_task(task_id: str) timApp.item.block.Block | None[source]#
static get_by_task(task_id: str) timApp.item.taskblock.TaskBlock | None[source]#
id#
task_id#
timApp.item.taskblock.insert_task_block(task_id: str, owner_groups: list[timApp.user.usergroup.UserGroup]) timApp.item.taskblock.TaskBlock[source]#

timApp.item.validation module#

class timApp.item.validation.ItemValidationRule(check_write_perm: bool = True, require_login: bool = True)[source]#

Bases: object

Rules for item validation.

check_write_perm: bool#

Whether to check for write permission of containing folder.

require_login: bool#
timApp.item.validation.has_special_chars(item_path: str)[source]#
timApp.item.validation.validate_item(item_path: str, item_type: timApp.item.block.BlockType, validation_rule: Optional[timApp.item.validation.ItemValidationRule] = None)[source]#
timApp.item.validation.validate_item_and_create_intermediate_folders(item_path: str, item_type: timApp.item.block.BlockType, owner_group: Optional[timApp.user.usergroup.UserGroup] = None, validation_rule: Optional[timApp.item.validation.ItemValidationRule] = None)[source]#
timApp.item.validation.validate_uploaded_document_content(file_content)[source]#

Module contents#