common_settings.py 3.1 KB
Newer Older
1 2 3
# -*- coding: utf-8 -*-
""" Common settings

4 5 6 7 8 9 10 11 12
Model instantiate the database table as well as the UI configuration.
It is tune to only satisfy the need of the controller, function pair.

Note:
    The model expose to controllers several global variables:

        * auth
        * directSvc

13 14 15 16
"""
import plugin_dbui as dbui

from datetime import datetime
17 18 19 20 21 22 23
from plugin_event import (EvtModelCore,
                          EvtModelReport,
                          EvtModelSelector,
                          EvtUiCore,
                          EvtUiReport,
                          EvtUiSelector,
                          EvtUiViewport)
24

25 26 27
ctrl = request.controller
fnct = request.function

28
#.............................................................................
29
#
30
# Language
31
#
32 33 34

T.set_current_languages("en", "en-gb", "en-us")     # mother tongue
T.force("fr-fr")                                    # user language
35 36
T.lazy = False                                      # immediate translation

37
#.............................................................................
38
#
39
# Plugin dbui configuration
40
#
41 42
is_dbui = (ctrl == "plugin_dbui") and \
          fnct in ("debug", "documentations", "dbui_conf", "index")
43

44 45 46 47 48 49 50
if is_dbui:
    dbui.Dbui.initialise_paths(
        app_css="static/track_events/resources/css/my.css",
        app_debug="static/track_events/src",
        app_lg="static/track_events/locale/myapp-lang-fr.js",
        app_libmin="static/track_events-min.js",
        app_script="static/app.js")
51 52 53

#.............................................................................
#
54
# Create the database models
55
#
56

57 58
is_db = (ctrl == "plugin_dbui" and fnct in ("call", "csv", "dbui_conf")) or \
        (ctrl == "report")
59

60 61 62 63
if is_db:
    EvtModelCore(db, T)
    EvtModelReport(db, T)
    EvtModelSelector(virtdb, db, T)
64 65 66

#.............................................................................
#
67
# Configure the user interface
68 69
#

70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
if ctrl == "plugin_dbui" and fnct in ("call", "dbui_conf"):

    dbui.Dbui.initialise_ui()
    directSvc = dbui.Dbui.start_directSvc()

    # common configuration for forms and grids
    tables = ["auth_group",
              "auth_membership",
              "auth_user",
              "domains",
              "events",
              "fundings",
              "graphs",
              "history",
              "lists",
              "metrics1d",
              "metrics2d",
              "object_categories",
              "objects",
              "people",
              "people_categories",
              "projects",
              "teams"]

    dbui.configure_forms(tables, plugins=["pFormToolTip"], width=350)

    dbui.configure_grids(tables, plugins=["pGridRowEditorConfirmDelete",
                                          "pGridRowEditorContextMenu",
                                          "pGridRowEditorDblClick",
                                          "pGridToolbar"])

    # tune the user interface
    EvtUiCore(db, T)
    EvtUiReport(db, T)

    selector_panel = EvtUiSelector.selector(virtdb, db, T)

    # configure the main viewport
108 109
    if fnct == "dbui_conf":
        EvtUiViewport(db, T, selector_panel)