Skip to main content

App types

The type of app can be set in the viktor.config.toml file by means of the app_type entry. App layout, requirements and corresponding feedback errors might differ depending on the chosen app type. Currently, the following types are available:

  • Editor: the app consists of a single editor. Every users gets a 'fresh' editor upon entry and data is not saved.

    Tutorial
  • Simple: the app consists of a single entity type. Users can create, save and edit instances of this type. Entities are shared among multiple users.

    Tutorial
  • Tree: the app consists of multiple entity types in a developer-specified hierarchy. Entities are shared among multiple users.

    Tutorial

Editor-type app

The simplest app structure consists of a single editor only. The user automatically enters the editor when opening the application workspace, with no additional navigation functionalities.

When a user opens the workspace, a unique session is created. Sessions are not shared among multiple users, and are automatically closed when leaving the editor (state is not saved).

info

The following are not available for the 'editor' app type:

Simple-type app

The simple is similar to the editor type, however the user is able to create multiple entities of an entity type and the state of an entity can be saved. Earlier created revisions can be restored if desired. The user enters a folder and can navigate to the desired entity by selecting from the entity table.

Tree-type app

More complex apps, consisting of an entity type hierarchy, can be created by choosing the tree app type.

The app.py file can quickly become cluttered with a lot of code if your app grows in size. For tree-type apps we recommend to separate the code in sub-folders. This can be done by replacing the app.py file with a file called __init__.py within a folder named app and add sub-folders per entity type. Furthermore, it might be desirable to also split the controller and parametrization classes into separate files. For a hypothetical app with entity types BlueType and GreenType this looks as follows:

my-folder
├── app
│ ├── blue_type
│ │ ├── __init__.py
│ │ ├── controller.py
│ │ └── parametrization.py
│ ├── green_type
│ │ ├── __init__.py
│ │ ├── controller.py
│ │ └── parametrization.py
│ └── __init__.py <- this is the new entry point of your app, replacing app.py
├── requirements.txt
└── viktor.config.toml
note

The __init__.py files in the entity type sub-folders are required to make Python treat directories containing the file as packages and can be left empty.

Importing controllers

If the controller class is in a separate file, it can be imported in the app's __init__.py file using Python's import command. For example, a controller class named BlueType in a file blue_type/controller.py can be imported in __init__.py as follows:

from .blue_type.controller import BlueType  # defines entity type 'BlueType'

If the class name itself does not equal the entity type name, you can import as an alias. For example, a class named Controller in a file blue_type/controller.py can be imported in the app's __init__.py file to act as the controller for the BlueType entity type as follows:

from .blue_type.controller import Controller as BlueType  # defines entity type 'BlueType'