main.py 2.91 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 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 108
""" main

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.

Note:
    Expose to controllers several global variables:

        * app
        * auth
        * db
        * virtdb
        * directSvc

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

"""
from gluon import current
from model_core import Core
from model_selector import Selector
from plugin_dbui import configure_forms, configure_grids, Dbui
from ui_core import CoreUI
from ui_selector import SelectorUI
from ui_viewport import ViewportUi

# ............................................................................
#
# Connection to databases
#

db = DAL('sqlite://storage.sqlite', lazy_tables=False, migrate=True)
virtdb = DAL(None)

current.db = db
current.virtdb = virtdb

# ............................................................................
#
# Language
#

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

# ............................................................................
#
# Configure plugin_dbui
#

Dbui.define_paths(
    app_about="static/plugin_dbui/ABOUT.html",
    # app_css=None,
    app_db_schema=None,
    app_changelog="static/plugin_dbui/CHANGELOG",
    app_git="https://gitlab.in2p3.fr/w2pext/plugin_dbui.git",
    app_html_api="static/plugin_dbui/docs/api/index.html",
    app_html_jsduck="static/plugin_dbui/docs/jsduck/index.html",
    app_html_reference="static/plugin_dbui/docs/reference/index.html",
    app_html_user=None,
    # app_libmin=None,
    app_pdf_api="static/plugin_dbui/docs/pdf/dbui_api.pdf",
    app_pdf_reference="static/plugin_dbui/docs/pdf/dbui_reference.pdf",
    app_script="static/app.js",
    app_script_dir="static/scripts",
    # dbui_libmin="static/plugin_dbui/dbui-debug.js"
)

# ............................................................................
#
# Create the database models
#
Core.define_tables(db, T)
Selector.define_tables(virtdb, db, T)

# ............................................................................
#
# Configure the user interface
#

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

# Common configuration for forms and grids
tables = ["categories",
          "collaborations",
          "countries",
          "harvesters",
          "new_fields",
          "projects",
          "publishers",
          "publications",
          "reports",
          "teams"]

configure_forms(tables, plugins=["pFormToolTip"], width=300)

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

CoreUI.configure(db, T)
SelectorUI.configure(virtdb, db, T)
ViewportUi.configure(virtdb, db, T)