• Home
  • API Documentation
  • wte.models – Database Models

wte.models – Database Models¶

The models module contains the database models that are used to abstract the actual database.

class wte.models.Asset(**kwargs)[source]¶

The class:~wte.models.Asset represents any kind of file data. What role the Asset is used in depends on the type.

Instances of Asset have the following attributes:

  • id – The unique database identifier
  • data – The actual file content
  • filename – The filename used for accessing this Asset
  • mimetype – The mimetype of this Asset
  • order – The order to display this Asset in
  • parts – The Part that this Asset is used in
  • type – The type of Asset it is (asset, template, file)
menu(request, part=None)[source]¶

Generate the menu for this Asset. Will distinguish between assets, templates, and files.

wte.models.DB_VERSION = 'c9a72e7ff141'¶

The currently required database version.

class wte.models.Part(**kwargs)[source]¶

The Part class represents the parts from which the teaching content is constructed. It supports the following types: module, tutorial, page, exercise, and task.

Instances of Part have the following attributes:

  • id – The unique database identifier
  • access_rights – JSON structure representing the access rights to this Part
  • assets – List of Asset that act as asset files
  • children – List of Part contained in this Part
  • compiled_content – The compiled HTML generated from the ReST content
  • content – The ReST content for the Part
  • display_mode – The display template mode to use for the Part
  • label – The classification label to use for the Part
  • order – The ordering position of this Part
  • parent_id – The unique database identifier of the parent Part
  • parent – The parent Part
  • progress – The UserPartProgress linked to this Part
  • status – The Part‘s availability status
  • summary – The shortened summary derived from the compiled_content
  • tasks – List of TimedTask that are attached to this Part
  • templates – List of Asset that act as template files
  • title – The title displayed for this Part
  • type – Whether the Part is a module, tutorial, page, exercise, or task.
  • users – The User that are linked to this Part
allow(action, user)[source]¶

Checks whether the given user is allowed to perform the given action. Supports the following actions: view, edit, delete, and users.

Parameters:
  • action (unicode) – The action to check for
  • user (User) – The user to check
Returns:

True if the user may perform the action, False otherwise

Return type:

bool

available_children¶

Returns the list of child Part for which the status attribute is set to “available”.

Returns:The available child Part
Return type:list()
has_role(role, user)[source]¶

Checks if the given user has the given role for this Part. If a list is specified as the role, then the user must have at least one of the specified roles.

Parameters:
  • role (unicode or list) – The role the user must have.
  • user (User) – The user that has to have the role
Returns:

True if the User has the given role, False otherwise

Return type:

bool

menu(request)[source]¶

Generates the menu for the Part.

next¶

Returns the next Part in the list of siblings.

Returns:The next Part sibling
Return type:Part
prev¶

Returns the previous Part in the list of siblings.

Returns:The previous Part sibling
Return type:Part
root()[source]¶

Gets the root Part for the current Part. If the Part has no parent, then returns itself.

Returns:The root Part
Return type:Part
summary¶

Generates the text summary for this Part. The text summary is generated by finding the first tag in the compiled_content and then returning that.

Returns:The content of the first tag in the compiled_content
R_type:unicode
class wte.models.Quiz(**kwargs)[source]¶

The Quiz represents a Quiz in the database.

Instances of QuizAnswer have the following attributes:

  • id - The unique database identifier
  • answers - All QuizAnswer that belong to this Quiz
  • part_id - The unique identifier of the User the Part belongs to
  • name - The name of the Quiz.
  • questions - JSON-encoded list of question-name / question-title pairs
  • title - The title to show to the user
class wte.models.QuizAnswer(**kwargs)[source]¶

The class:~wte.models.QuizAnswer represents an answer to a QuizQuestion in a Quiz.

Instances of QuizAnswer have the following attributes:

  • id - The unique database identifier
  • attempts - How many attempts the user has had
  • final_answer - The final answer the user provided
  • final_correct - Whether the final answer was correct
  • initial_answer - The first answer the user provided
  • initial_correct - Whether the first answer was correct
  • question - The name of the QuizQuestion.
  • quiz_id - The unique identifier of the Quiz the QuizAnswer belongs to
  • quiz - The Quiz identified by quiz_id
  • user_id - The unique identifier of the User the QuizAnswer belongs to
class wte.models.TimedTask(**kwargs)[source]¶

The class:~wte.models.TimedTask represents a task that is to be run at a specific time in the future.

Instances of TimedTask have the following attributes:

  • id – The unique database identifier
  • part_id – The unique identifier of the Part the TimedTask belongs to
  • name – The name of this TimedTask
  • title – The title of this TimedTask
  • timestamp – The timestamp at which to execute this TimedTask
  • _options – The task options as JSON (do not use directly, use options)
delta¶

Get the timedelta between the TimedTask‘s timestamp and datetime.now().

menu(request, part)[source]¶

Generate the menu for this TimedTask.

options¶

Get / Set the options for this TimedTask.

When setting options, the new options must be of type dict.

When getting options, the options will be returned as a dict.

class wte.models.UserPartProgress(**kwargs)[source]¶

The UserPartProgress represents the progress a User has made through a Part.

Instances of UserPartProgress have the following attributes:

  • id – The unique database identifier
  • current_id – The unique database identifier of the current Part
  • current – The current Part
  • files – The Asset that are linked to this UserPartProgress
  • part_id – The unique identifier of the Part
  • part – The Part that this represents the progress in
  • user_id – The unique identifier of the User
  • user – The User for which this represents the progress
  • visited – A MutableDict via a JSONUnicodeText that stores information on the visited child Parts.
allow(action, user)[source]¶

Checks whether the given user is allowed to perform the given action. Supports the following action: view.

Parameters:
  • action (unicode) – The action to check for
  • user (User) – The user to check
Returns:

True if the user may perform the action, False otherwise

Return type:

bool

class wte.models.UserPartRole(**kwargs)[source]¶

The UserPartRole links users to Part that have a type “module”. They represent the role the User plays for that Part.

Instances of UserPartRole have the following attributes:

  • id – The unique database identifier
  • part_id – The unique database identifier of the linked Part
  • part – The linked Part
  • role – The role the User plays in the Part
  • user_id – The unique database identifier of the linked User
  • user – The linked User
wte.models.parts_assets = Table('parts_assets', MetaData(bind=None), Column('part_id', Integer(), ForeignKey('parts.id'), table=<parts_assets>, primary_key=True, nullable=False), Column('asset_id', Integer(), ForeignKey('assets.id'), table=<parts_assets>, primary_key=True, nullable=False), schema=None)¶

sqlalchemy.Table to link Part and Asset.

wte.models.progress_assets = Table('progress_assets', MetaData(bind=None), Column('progress_id', Integer(), ForeignKey('user_part_progress.id'), table=<progress_assets>, primary_key=True, nullable=False), Column('asset_id', Integer(), ForeignKey('assets.id'), table=<progress_assets>, primary_key=True, nullable=False), schema=None)¶

sqlalchemy.Table to link Part and Asset.

  • wte.helpers.frontend – Helpers for the frontend display
  • wte.scripts – Administration scripts