Note
Todo
Docstrings (module, models, utilities)
Models
- class indico.modules.events.notes.models.notes.EventNote(**kwargs)
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs
.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
- allowed_link_types = frozenset({LinkType.event, LinkType.contribution, LinkType.subcontribution, LinkType.session})
The link types that are supported. Can be overridden in the model using the mixin. Affects the table structure, so any changes to it should go along with a migration step!
- category = None
- category_id = None
- contribution
- contribution_id
- create_revision(render_mode, source, user)
Create a new revision if needed and marks it as undeleted if it was.
Any change to the render mode or the source causes a new revision to be created. The user is not taken into account since a user “modifying” a note without changing things is not really a change.
- current_revision
The currently active revision of the note
- current_revision_id
The ID of the current revision
- delete(user)
Mark the note as deleted and adds a new empty revision.
- event
- event_id
- events_backref_name = 'all_notes'
The name of the backref that’s added to the Event model to access all linked objects
- classmethod get_for_linked_object(linked_object, preload_event=True)
Get the note for the given object.
This only returns a note that hasn’t been deleted.
- Parameters:
linked_object – An event, session, contribution or subcontribution.
preload_event – If all notes for the same event should be pre-loaded and cached in the app context.
- classmethod get_or_create(linked_object)
Get the note for the given object or creates a new one.
If there is an existing note for the object, it will be returned even. Otherwise a new note is created.
- html
The rendered HTML of the note
- classmethod html_matches(search_string, exact=False)
Check whether the html content matches a search string.
To be used in a SQLAlchemy filter call.
- Parameters:
search_string – A string to search for
exact – Whether to search for the exact string
- id
The ID of the note
- is_deleted
If the note has been deleted
- link_backref_name = 'note'
The name of the backref that’s added to the linked objects
- link_type
- linked_event
- linked_event_id
- locator
Define a smart locator property.
This behaves pretty much like a normal read-only property and the decorated function should return a dict containing the necessary data to build a URL for the object.
This decorator should usually be applied to a method named
locator
as this name is required for get_locator to find it automatically when just passing the object.If you need more than one locator, you can define it like this:
@locator_property def locator(self): return {...} @locator.other def locator(self): return {...}
The
other
locator can then be accessed by passingobj.locator.other
to the code expecting an object with a locator.
- revisions
The list of all revisions for the note
- session
- session_block = None
- session_block_id = None
- session_id
- subcontribution
- subcontribution_id
- unique_links = True
If only one link per object should be allowed. This may also be a string containing an SQL string to specify the criterion for the unique index to be applied, e.g.
'is_foo = true'
.
- class indico.modules.events.notes.models.notes.EventNoteRevision(**kwargs)
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs
.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
- created_dt
The date/time when the revision was created
- html
The rendered HTML of the note
- id
The ID of the revision
- note_id
The ID of the associated note
- query: IndicoBaseQuery
A SQLAlchemy query for a model. Equivalent to
db.session.query(Model)
. Can be customized per-model by overridingquery_class
.Warning
The query interface is considered legacy in SQLAlchemy. Prefer using
session.execute(select())
instead.
- render_mode
How the note is rendered
- source
The raw source of the note as provided by the user
- user
The user who created the revision
- user_id
The user who created the revision
Utilities
- indico.modules.events.notes.util.build_note_api_data(note)
- indico.modules.events.notes.util.build_note_legacy_api_data(note)
- indico.modules.events.notes.util.can_edit_note(obj, user)
Check if a user can edit the object’s note.
- indico.modules.events.notes.util.check_note_revision(note, previous_revision_id, render_mode, source)
Compare revision IDs to check if the note has been modified.
- indico.modules.events.notes.util.get_scheduled_notes(event)
Get all notes of scheduled items inside an event.
- indico.modules.events.notes.util.render_note(source, mode)
Render a note from source using the specified render mode.