views¶
Module: espressodb.base.views
|
The default index view. |
|
View which guides the user in creating a nested model population script. |
|
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., thetodo
andcolumn
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 treetree
- cloumn-tables pairs which have been specified by the user. The column name reflects recursice column names. See thecolumn
key.column
- the current column name. This name might be a combination of nested column dependencies likecolumnA_columnB
and so on.
Both the
todo
andtree
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
andcolumn
session
context to empty values.
-
static
get_choice
(form, session)[source]¶ Reads form and sets
root
model if not present insession
.- Parameters
form (
ModelSelectForm
) – The valid form.session (
Dict
[str
,Any
]) – The current session. Will be updated ifroot is None
.
- Return type
-
get_next
(model, session, parse_tree=True)[source]¶ Updates the
todo
list by working through present entries.- Parameters
model (
Base
) – The currentcolumn
model.parse_tree (
bool
) – Adds possible user choices for dependencies of currentcolumn
if True totodo
list.session (
Dict
[str
,Any
]) – The current session. Will be updated ifroot is None
.
This method works the following way:
Add current select model to tree if present.
Parse the tree of the current model if
parse_tree
usingespressodb.base.utilities.models.iter_tree()
.Update
todo
if present (see below) else return (render result view).
The
todo
update works as follows:Pop the first entry in the
todo
list and add this entry tocolumn
Find possible tables which can be chosen for this model. This modifies the
column
context.If there is more then one choices, ask the user which model to select. This means returning back to the form query page.
Pick the only option if there is just one choice, and recursively call this method for this choice.
-
post
(request, *args, **kwargs)[source]¶ Processes the selected model and prepares the next choices.
The
session
context is modified in the following way:If the form is valid, extract the current column-table choice using
PopulationView.get_choice()
.Get the next column-table option the user has to specify using
PopulationView.get_next()
.Return a new column-table from for the user to answer if not done yet.
Redirect to
PopulationResultView
if there is nothing to do.
-
template_name
= 'select-table.html'¶ The used template file.