common_settings.py 3.69 KB
Newer Older
1
# -*- coding: utf-8 -*-
LE GAC Renaud's avatar
LE GAC Renaud committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
""" 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".
18 19

"""
LE GAC Renaud's avatar
LE GAC Renaud committed
20
from _mydb import DBURIS
21

LE GAC Renaud's avatar
LE GAC Renaud committed
22 23 24 25 26 27
from auth import configure_auth, USER
from gluon import current
from model_app import App
from model_core import Core
from model_harvester import Harvester
from model_report import Report
LE GAC Renaud's avatar
LE GAC Renaud committed
28
from model_selector import Selector
LE GAC Renaud's avatar
LE GAC Renaud committed
29 30 31 32 33

from plugin_dbui import (configure_forms,
                         configure_grids,
                         Dbui)

34 35 36 37 38 39 40 41 42
from ui_app import AppUI
from ui_auth import AuthUI
from ui_core import CoreUI
from ui_harvester import HarvesterUI
from ui_report import ReportUI
from ui_selector import SelectorUI
from ui_viewport import ViewportUi


LE GAC Renaud's avatar
LE GAC Renaud committed
43 44 45 46 47 48 49 50 51 52 53
# ............................................................................
#
# Connection to databases
#

try:
    mysql = DBURIS[request.application]
    db = DAL(mysql,
             lazy_tables=False,
             migrate_enabled=False,
             pool_size=10)
54

LE GAC Renaud's avatar
LE GAC Renaud committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
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
70

71
# ............................................................................
72
#
73
# Language
74
#
75

LE GAC Renaud's avatar
LE GAC Renaud committed
76 77
T.set_current_languages("en", "en-gb", "en-us")  # mother tongue
T.force("fr-fr")                                 # user language
78 79 80
T.lazy = False                                   # immediate translation

# ............................................................................
81
#
82
# Plugin dbui configuration
83 84
#

LE GAC Renaud's avatar
LE GAC Renaud committed
85 86 87 88 89
Dbui.define_paths(
    app_css="static/my.css",
    app_lg="static/limbra/locale/limbra-lang-fr.js",
    app_libmin="static/limbra-min.js",
    app_script="static/app.js")
90

LE GAC Renaud's avatar
LE GAC Renaud committed
91 92 93 94 95 96 97 98
# ............................................................................
#
# Create the database models
#
App.define_tables(db, T)
Core.define_tables(db, T)
Harvester.define_tables(db, T)
Report.define_tables(db, T)
LE GAC Renaud's avatar
LE GAC Renaud committed
99
Selector.define_tables(virtdb, db, T)
100

101
# ............................................................................
102
#
LE GAC Renaud's avatar
LE GAC Renaud committed
103
# Configure the user interface
104
#
105

LE GAC Renaud's avatar
LE GAC Renaud committed
106 107
Dbui.initialise_ui()
directSvc = Dbui.start_directSvc()
108 109

# common configuration for forms and grids
LE GAC Renaud's avatar
LE GAC Renaud committed
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
tables = ["application",
          "auth_group",
          "auth_membership",
          "auth_user",
          "authors_roles",
          "axes",
          "categories",
          "collaborations",
          "controllers",
          "countries",
          "harvesters",
          "graphs",
          "lists",
          "metrics",
          "my_authors",
          "organisation",
          "projects",
          "publications",
          "publishers",
          "renderers",
          "reports",
          "sections",
          "status",
          "teams"]
134

135 136
# a user see the categories table but he/she can not modify it.
if session.role == USER:
LE GAC Renaud's avatar
LE GAC Renaud committed
137
    tables.remove("categories")
LE GAC Renaud's avatar
LE GAC Renaud committed
138

139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
configure_forms(
    tables,
    plugins=["pFormToolTip"],
    width=350)

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

AppUI.configure(db, T)
AuthUI.configure(db, T)
CoreUI.configure(db, T)
HarvesterUI.configure(db, T)
ReportUI.configure(db, T)
SelectorUI.configure(virtdb, db, T)

ViewportUi.configure(db, T, virtdb)

160