main.py 4.26 KB
Newer Older
1
# -*- coding: utf-8 -*-
2
""" main
3

4 5 6
Instantiate the database connection, model database tables and configure the
user interface. It is tune to only satisfy the need of the controller,
function pair.
7 8

Note:
9
    Expose to controllers several global variables:
10 11

        * auth
12 13
        * db
        * virtdb
14 15
        * directSvc

16 17
    They can be retrieved in module via the protocol "current".

18
"""
19 20 21
from _mydb import DBURIS
from gluon import current

LE GAC Renaud's avatar
LE GAC Renaud committed
22 23 24 25
from plugin_dbui import (configure_forms,
                         configure_grids,
                         Dbui)

26 27
from plugin_event import (configure_auth,
                          Core,
LE GAC Renaud's avatar
LE GAC Renaud committed
28 29 30 31 32 33
                          CoreUi,
                          Event,
                          Report,
                          ReportUi,
                          Selector,
                          ViewportUi)
34

35 36 37 38
# ............................................................................
#
# Connection to databases
#
39

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
try:
    mysql = DBURIS[request.application]
    db = DAL(mysql,
             lazy_tables=False,
             migrate_enabled=False,
             pool_size=10)

except RuntimeError:
    raise HTTP(500, T("Can't access the MySQL database !!!"))

virtdb = DAL(None)

current.db = db
current.virtdb = virtdb

# ............................................................................
#
# Authentication
#

auth = configure_auth(db, migrate_user=False)
current.auth = auth
62

63
# ............................................................................
64
#
65
# Language
66
#
67 68 69

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
70
T.lazy = True                                       # lazy translation
71

72
# ............................................................................
73
#
74
# Plugin dbui configuration
75
#
76 77 78 79 80 81
ctrl = request.controller
fnct = request.function

is_dbui = \
    (ctrl == "plugin_dbui") \
    and fnct in ("debug", "documentations", "dbui_conf", "index")
82

83
if is_dbui:
LE GAC Renaud's avatar
LE GAC Renaud committed
84
    Dbui.define_paths(
85
        app_about="static/plugin_event/ABOUT.html",
86
        app_css=None,
87
        app_changelog="static/plugin_event/CHANGELOG",
88
        app_db_schema="static/plugin_event/docs/database.png",
89
        app_debug=None,
90 91 92
        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",
93
        app_lg=None,
94
        app_license="static/plugin_event/LICENSE",
95
        app_libmin="static/plugin_event/event-min.js",
96 97
        app_pdf_api="static/plugin_event/docs/pdf/event_api.pdf",
        app_pdf_user="static/plugin_event/docs/pdf/event_user.pdf",
98
        app_script="static/app.js")
99

LE GAC Renaud's avatar
LE GAC Renaud committed
100
    Event.define_paths("fr")
101

102
# ............................................................................
103
#
104
# Create the database models
105
#
106

107 108 109
is_db = \
    (ctrl == "plugin_dbui" and fnct in ("call", "csv", "dbui_conf")) \
    or (ctrl == "plugin_event")
110

111
if is_db:
112 113

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

LE GAC Renaud's avatar
LE GAC Renaud committed
116 117 118
    Core.define_tables(db, T)
    Report.define_tables(db, T)
    Selector.define_tables(virtdb, db, T)
119

120
# ............................................................................
121
#
122
# Configure the user interface
123 124
#

125 126
if ctrl == "plugin_dbui" and fnct in ("call", "dbui_conf"):

LE GAC Renaud's avatar
LE GAC Renaud committed
127 128
    Dbui.initialise_ui()
    directSvc = Dbui.start_directSvc()
129 130 131 132 133 134 135 136

    # 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
137
              "lists2",
138
              "metrics2d2",
139 140 141 142 143 144 145
              "object_categories",
              "objects",
              "people",
              "people_categories",
              "projects",
              "teams"]

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

LE GAC Renaud's avatar
LE GAC Renaud committed
148 149 150 151 152 153
    configure_grids(
        tables,
        plugins=["pGridRowEditorConfirmDelete",
                 "pGridRowEditorContextMenu",
                 "pGridRowEditorDblClick",
                 "pGridToolbar"])
154

155 156 157
    # configure the user interface for the main tables
    CoreUi.configure(db, T)
    ReportUi.configure(db, T)
158

159
    # configure the viewport
160
    if fnct == "dbui_conf":
161
        ViewportUi.configure(db, T, virtdb)