views

Module: espressodb.base.views

IndexView(**kwargs)

The default index view.

PopulationView(**kwargs)

View which guides the user in creating a nested model population script.

PopulationResultView(**kwargs)

View which presents the result of the population query process.


Views for the base module

class IndexView(**kwargs)[source]

The default index view.

template_name = 'index.html'

The used template file.

class PopulationResultView(**kwargs)[source]

View which presents the result of the population query process.

This view generates a Python script which can be used to query or create nested models once the user has filled out columns in script.

get(request)[source]

Presents the population results.

Modifies the session. E.g., the todo and column entries are deleted.

template_name = 'present-populate.html'

The used template file.

class PopulationView(**kwargs)[source]

View which guides the user in creating a nested model population script.

This view queries which model the user wants to populate. If the model has Foreign Keys, it queries the user which table to select in case there are multiple options (in case there is just one, this table will be selceted).

The logic works as follows, the root table might depend on other tables which might depend on other tables as well. This defines a tree of tables where each ForeignKey of the current table column needs to be matched against possible table options. This view iterates user choices and queries the user for open column-table pairs.

This view uses the request session (e.g, cookies) to store previously selected values. Thus there exist no unique link for the view.

The following keywords are used to identify the nested dependencies:
  • root - the model on top of the tree (e.g, the first choosen table)

  • todo - tables which need to be specified by the user to parse the tree

  • tree - cloumn-tables pairs which have been specified by the user. The column name reflects recursice column names. See the column key.

  • column - the current column name. This name might be a combination of nested column dependencies like columnA_columnB and so on.

Both the todo and tree lists are odered such that models are created bottom up to create an executable script.

Warning

The querying logic breaks if the user navigates backwards.

form_class

alias of espressodb.base.forms.ModelSelectForm

get(request)[source]

Initializes from which queries the user about tables for population.

Initializes the root, todo, tree and column session context to empty values.

static get_choice(form, session)[source]

Reads form and sets root model if not present in session.

Parameters
  • form (ModelSelectForm) – The valid form.

  • session (Dict[str, Any]) – The current session. Will be updated if root is None.

Return type

Base

get_next(model, session, parse_tree=True)[source]

Updates the todo list by working through present entries.

Parameters
  • model (Base) – The current column model.

  • parse_tree (bool) – Adds possible user choices for dependencies of current column if True to todo list.

  • session (Dict[str, Any]) – The current session. Will be updated if root is None.

This method works the following way:

  1. Add current select model to tree if present.

  2. Parse the tree of the current model if parse_tree using espressodb.base.utilities.models.iter_tree().

  3. Update todo if present (see below) else return (render result view).

The todo update works as follows:

  1. Pop the first entry in the todo list and add this entry to column

  2. Find possible tables which can be chosen for this model. This modifies the column context.

  3. If there is more then one choices, ask the user which model to select. This means returning back to the form query page.

  4. Pick the only option if there is just one choice, and recursively call this method for this choice.

Return type

Tuple[Base, List[Base]]

post(request, *args, **kwargs)[source]

Processes the selected model and prepares the next choices.

The session context is modified in the following way:

  1. If the form is valid, extract the current column-table choice using PopulationView.get_choice().

  2. Get the next column-table option the user has to specify using PopulationView.get_next().

  3. Return a new column-table from for the user to answer if not done yet.

  4. Redirect to PopulationResultView if there is nothing to do.

template_name = 'select-table.html'

The used template file.