common_settings.py 3.47 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
"""
LE GAC Renaud's avatar
LE GAC Renaud committed
14 15 16 17 18 19 20 21 22 23 24
from plugin_dbui import (configure_forms,
                         configure_grids,
                         Dbui)

from plugin_event import (Core,
                          CoreUi,
                          Event,
                          Report,
                          ReportUi,
                          Selector,
                          ViewportUi)
25 26


27 28 29
ctrl = request.controller
fnct = request.function

30
# ............................................................................
31
#
32
# Language
33
#
34 35 36

T.set_current_languages("en", "en-gb", "en-us")     # mother tongue
T.force("fr-fr")                                    # user language
LE GAC Renaud's avatar
LE GAC Renaud committed
37
T.lazy = True                                       # lazy translation
38

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

46
if is_dbui:
LE GAC Renaud's avatar
LE GAC Renaud committed
47
    Dbui.define_paths(
48
        app_about="static/plugin_event/ABOUT.html",
49
        app_css=None,
50
        app_changelog="static/plugin_event/CHANGELOG",
51
        app_db_schema="static/plugin_event/docs/database.png",
52
        app_debug=None,
53 54 55
        app_html_api="static/plugin_event/docs/api/index.html",
        app_html_jsduck="static/plugin_event/docs/jsduck/index.html",
        app_html_user="static/plugin_event/docs/user/index.html",
56
        app_lg=None,
57
        app_license="static/plugin_event/LICENSE",
58
        app_libmin="static/plugin_event/event-min.js",
59 60
        app_pdf_api="static/plugin_event/docs/pdf/event_api.pdf",
        app_pdf_user="static/plugin_event/docs/pdf/event_user.pdf",
61
        app_script="static/app.js")
62

LE GAC Renaud's avatar
LE GAC Renaud committed
63
    Event.define_paths("fr")
64

65
# ............................................................................
66
#
67
# Create the database models
68
#
69

70 71
is_db = (ctrl == "plugin_dbui" and fnct in ("call", "csv", "dbui_conf")) \
        or (ctrl == "plugin_event")
72

73
if is_db:
74 75

    # register source for the reporting
LE GAC Renaud's avatar
LE GAC Renaud committed
76
    Event.register_sources()
77

LE GAC Renaud's avatar
LE GAC Renaud committed
78 79 80
    Core.define_tables(db, T)
    Report.define_tables(db, T)
    Selector.define_tables(virtdb, db, T)
81

82
# ............................................................................
83
#
84
# Configure the user interface
85 86
#

87 88
if ctrl == "plugin_dbui" and fnct in ("call", "dbui_conf"):

LE GAC Renaud's avatar
LE GAC Renaud committed
89 90
    Dbui.initialise_ui()
    directSvc = Dbui.start_directSvc()
91 92 93 94 95 96 97 98

    # common configuration for forms and grids
    tables = ["auth_group",
              "auth_membership",
              "auth_user",
              "domains",
              "events",
              "fundings",
LE GAC Renaud's avatar
LE GAC Renaud committed
99
              "lists2",
100
              "metrics2d2",
101 102 103 104 105 106 107
              "object_categories",
              "objects",
              "people",
              "people_categories",
              "projects",
              "teams"]

LE GAC Renaud's avatar
LE GAC Renaud committed
108
    configure_forms(tables, plugins=["pFormToolTip"], width=350)
109

LE GAC Renaud's avatar
LE GAC Renaud committed
110 111 112 113 114 115
    configure_grids(
        tables,
        plugins=["pGridRowEditorConfirmDelete",
                 "pGridRowEditorContextMenu",
                 "pGridRowEditorDblClick",
                 "pGridToolbar"])
116 117

    # tune the user interface
LE GAC Renaud's avatar
LE GAC Renaud committed
118 119
    CoreUi.define(db, T)
    ReportUi.define(db, T)
120 121

    # configure the main viewport
122
    if fnct == "dbui_conf":
LE GAC Renaud's avatar
LE GAC Renaud committed
123
        ViewportUi.define(db, T, virtdb)