common_settings.py 3.39 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
from auth import configure_auth, USER
from gluon import current
24
from gluon.tools import PluginManager
LE GAC Renaud's avatar
LE GAC Renaud committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
from model_app import App
from model_core import Core
from model_harvester import Harvester
from model_report import Report

from plugin_dbui import (configure_forms,
                         configure_grids,
                         Dbui)

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

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

LE GAC Renaud's avatar
LE GAC Renaud committed
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
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
61

62
# ............................................................................
63
#
64
# Language
65
#
66

LE GAC Renaud's avatar
LE GAC Renaud committed
67 68
T.set_current_languages("en", "en-gb", "en-us")  # mother tongue
T.force("fr-fr")                                 # user language
69 70 71
T.lazy = False                                   # immediate translation

# ............................................................................
72
#
73
# Plugin dbui configuration
74 75
#

LE GAC Renaud's avatar
LE GAC Renaud committed
76 77 78 79 80
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")
81 82

# ............................................................................
83
#
84
# Constants
85
#
86

87

88 89
ONE_HOUR = 3600000

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

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

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

# common configuration for forms and grids
LE GAC Renaud's avatar
LE GAC Renaud committed
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
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"]
132

133 134
# 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
135
    tables.remove("categories")
LE GAC Renaud's avatar
LE GAC Renaud committed
136

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

LE GAC Renaud's avatar
LE GAC Renaud committed
139 140 141 142
configure_grids(tables, plugins=["pGridRowEditorConfirmDelete",
                                 "pGridRowEditorContextMenu",
                                 "pGridRowEditorDblClick",
                                 "pGridToolbar"])