Commit ce27f9c0 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add the modules/model_xx.py.

parent a4f42353
# -*- coding: utf-8 -*-
""" access
Define constants for the different role.
Access to the databases.
"""
from _mydb import DBURIS
# Migration flags
MIGRATE = False
MIGRATE_USER = False
# Roles
ID_ADMIN, ADMIN, DEF_ADMIN = 1, 'admin', 'administrators, librairians,...'
ID_USER, USER, DEF_USER = 2, 'user', 'liaisons, team leaders,...'
# MYSQL database
try:
mysql = DBURIS[request.application]
db = DAL(mysql, lazy_tables=False, migrate_enabled=MIGRATE, pool_size=10)
except:
raise HTTP(500, T("Can't access the MySQL database !!!"))
# virtual database
virtdb = DAL(None)
# -*- coding: utf-8 -*-
""" authentication
user identification and role
"""
from gluon.tools import Auth
#
# User logging
# Approval is required for newly registered users
#
auth = Auth(db, hmac_key=Auth.get_or_create_key())
auth.define_tables(migrate=MIGRATE_USER)
auth.settings.create_user_groups = False
auth.settings.mailer = None
auth.settings.registration_requires_approval = True
auth.settings.registration_requires_verification = False
auth.settings.remember_me_form = False
auth.settings.reset_password_requires_verification = True
# go to the login page after change password, logout and registration
auth.settings.change_password_next = URL('user', args='login')
auth.settings.logout_next = URL('user', args='login')
auth.settings.register_next = URL('user', args='login')
# create user and admin groups
if not db(db.auth_group.id).count():
db.auth_group.insert(id=ID_ADMIN, role=ADMIN, description=T(DEF_ADMIN))
db.auth_group.insert(id=ID_USER, role=USER, description=T(DEF_USER))
# Newly registered users go in the user group
auth.settings.everybody_group_id = ID_USER
# The first user is auto approved and get all privilege (admin)
if not db(db.auth_user.id).count():
auth.settings.everybody_group_id = ID_ADMIN
auth.settings.registration_requires_approval = False
# tune authentication fields for the extJS interface
db.auth_user.registration_key.readable = True
db.auth_user.registration_key.writable = True
db.auth_membership.user_id.label = 'User'
db.auth_membership.group_id.label = 'Group'
db.auth_membership.user_id.requires = \
IS_IN_DB(db, 'auth_user.last_name')
# HACK
# JSON conversion of datetime failed in the action plugin_dbui.dbui_conf
# Convert the date in advance help
# TODO: implement a proper datetime conversion when running json.dumps()
db.auth_event.time_stamp.default = db.auth_event.time_stamp.default.isoformat()
db.auth_cas.created_on.default = db.auth_cas.created_on.default.isoformat()
# -*- coding: utf-8 -*-
""" Common settings
""" 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".
"""
import datetime
import filters
import harvest_tools
import plugin_dbui as dbui
from callbacks import (INHIBIT_CASCADE_DELETE,
INHIBIT_CONTROLLER_INSERT,
INHIBIT_CONTROLLER_UPDATE,
INHIBIT_DUPLICATE_PUBLICATION,
INHIBIT_HARVESTER,
INHIBIT_PUBLICATION_DELETE_ON_OK,
INHIBIT_PUBLICATION_UPDATE_ON_OK)
from _mydb import DBURIS
from auth import configure_auth, USER
from gluon import current
from gluon.tools import PluginManager
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)
from regex import (REG_COLLABORATION,
REG_CONF_DATES,
REG_DEFENSE,
REG_SUBMITTED,
REG_VALID_ORIGIN)
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
# ............................................................................
#
# Language
#
T.set_current_languages('en', 'en-gb', 'en-us') # mother tongue
T.force('fr-fr') # user language
T.set_current_languages("en", "en-gb", "en-us") # mother tongue
T.force("fr-fr") # user language
T.lazy = False # immediate translation
# ............................................................................
......@@ -37,91 +73,70 @@ T.lazy = False # immediate translation
# Plugin dbui configuration
#
dbui.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')
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")
# ............................................................................
#
# Constants
#
undef = T(dbui.UNDEF)
undef_id = dbui.UNDEF_ID
year = datetime.datetime.now().year
CONTROLLERS = ['articles',
'notes',
'preprints',
'proceedings',
'reports',
'talks',
'theses']
DIRS = ['ASC', 'DESC']
CAT_USUAL = [T('article'),
T('book'),
T('patent'),
T('poster'),
T('proceeding'),
T('report'),
T('talk'),
T('thesis'),
undef]
CAT_USUAL.sort()
MODE_DRY_RUN = T(harvest_tools.DRY_RUN)
MODE_CHANGE_STATUS = T('change status')
MODE_LOAD_IN_DB = T('load in the database')
ONE_HOUR = 3600000
STORES = ['cds.cern.ch', 'inspirehep.net']
# ............................................................................
#
# Create the database models
#
App.define_tables(db, T)
Core.define_tables(db, T)
Harvester.define_tables(db, T)
Report.define_tables(db, T)
# ............................................................................
#
# Configure the user interface
# Configure the user interface
#
dbui.Dbui.initialise_ui()
directSvc = dbui.Dbui.start_directSvc()
Dbui.initialise_ui()
directSvc = Dbui.start_directSvc()
# common configuration for forms and grids
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']
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"]
# a user see the categories table but he/she can not modify it.
if session.role == USER:
tables.remove('categories')
tables.remove("categories")
dbui.configure_forms(tables, plugins=['pFormToolTip'], width=350)
configure_forms(tables, plugins=["pFormToolTip"], width=350)
dbui.configure_grids(tables, plugins=['pGridRowEditorConfirmDelete',
'pGridRowEditorContextMenu',
'pGridRowEditorDblClick',
'pGridToolbar'])
configure_grids(tables, plugins=["pGridRowEditorConfirmDelete",
"pGridRowEditorContextMenu",
"pGridRowEditorDblClick",
"pGridToolbar"])
# -*- coding: utf-8 -*-
""" affiliation_rules
"""
db.define_table("affiliation_keys",
Field("key_u", "string", length=255, notnull=True),
Field("key_v", "string", length=255, notnull=False),
migrate="affiliation_keys.table")
\ No newline at end of file
# -*- coding: utf-8 -*-
""" authors_roles
It defined the role of the CPPM authors.
"""
db.define_table("authors_roles",
Field("role", "string", length=255, default="", notnull=True),
migrate="authors_roles.table")
db.authors_roles._before_delete.append(INHIBIT_CASCADE_DELETE)
db.authors_roles._before_delete.append(dbui.INHIBIT_DELETE_UNDEF)
db.authors_roles._before_update.append(dbui.INHIBIT_UPDATE_UNDEF)
# -*- coding: utf-8 -*-
""" axes
The table axes, lists, sections and renderers are used by the lists tool.
It defines the relation between axis and granularity
"""
db.define_table("axes",
Field("axis", "string", length=255, notnull=True),
Field("granularity", "string", length=255, notnull=True),
Field("tr_axis", "string", length=255, notnull=True),
Field("tr_granularity", "string", length=255, notnull=True),
migrate="axes.table")
\ No newline at end of file
# -*- coding: utf-8 -*-
""" categories
"""
db.define_table("categories",
Field("code", "string", length=255, notnull=True, unique=True),
Field("usual", "string", length=255, default=""),
Field("definition", "text", notnull=True),
migrate="categories.table")
db.categories._before_delete.append(INHIBIT_CASCADE_DELETE)
db.categories._before_delete.append(dbui.INHIBIT_DELETE_UNDEF)
db.categories._before_update.append(dbui.INHIBIT_UPDATE_UNDEF)
db.categories.usual.requires = dbui.IS_IN_USET(CAT_USUAL)
db.categories.code.filter_in = dbui.CLEAN_SPACES
db.categories.usual.filter_in = dbui.CLEAN_SPACES
\ No newline at end of file
# -*- coding: utf-8 -*-
""" collaborations
"""
tp_collaboration = \
T("Collaboration(s) signing the publication: "
"CMS Collaboration or CMS and LHCb Collaborations or "
"ATLAS Collaboration, CMS Collaboration or "
"Heavy Flavour Averaging Group or "
"CTA Consortium.")
tp_synonyms = \
T("List of synonyms, one entry per row.")
db.define_table("collaborations",
Field("collaboration", "string", length=255, comment=tp_collaboration, notnull=True, unique=True),
Field("synonyms", "list:string", comment=tp_synonyms),
migrate="collaborations.table")
db.collaborations._before_delete.append(INHIBIT_CASCADE_DELETE)
db.collaborations._before_delete.append(dbui.INHIBIT_DELETE_UNDEF)
db.collaborations._before_update.append(dbui.INHIBIT_UPDATE_UNDEF)
db.collaborations.collaboration.filter_in = filters.CLEAN_COLLABORATION
db.collaborations.synonyms.filter_in = filters.CLEAN_COLLABORATION_SYNONYM
db.collaborations.collaboration.requires = IS_MATCH(REG_COLLABORATION)
\ No newline at end of file
# -*- coding: utf-8 -*-
""" controllers
The table my_authors, controllers and harvesters are used
by the harvesters tool.
It define the relation between harvester controllers and
publication categories.
"""
tp_category = \
T("Publication category associated to the found records.")
tp_controller = \
T("The name of the harvester.")
db.define_table("controllers",
Field("controller", "string", length=255, comment=tp_controller, label='Harvester', notnull=True),
Field("id_categories", "reference categories", comment=tp_category, default=undef_id, label='Category'),
migrate="controllers.table")
db.controllers._before_insert.append(INHIBIT_CONTROLLER_INSERT)
db.controllers._before_update.append(INHIBIT_CONTROLLER_UPDATE)
db.controllers.controller.filter_in = dbui.CLEAN_SPACES
# NOTE:
#
# the list of controllers corresponds to those defined in the harvest_tools.
# The method get_harvester_tool defines the relation between the controller
# and the harvester class.
#
db.controllers.controller.requires = IS_IN_SET(CONTROLLERS)
# -*- coding: utf-8 -*-
""" countries
"""
db.define_table("countries",
Field("country", "string", length=255, notnull=True, unique=True),
Field("synonyms", "list:string", comment=tp_synonyms),
migrate="countries.table")
db.countries._before_delete.append(INHIBIT_CASCADE_DELETE)
db.countries._before_delete.append(dbui.INHIBIT_DELETE_UNDEF)
db.countries._before_update.append(dbui.INHIBIT_UPDATE_UNDEF)
db.countries.country.filter_in = dbui.CLEAN_SPACES
\ No newline at end of file
# -*- coding: utf-8 -*-
""" preferences
"""
from gluon import current
from gluon.storage import Storage
db.define_table("preferences",
Field("property", "string", length=255, notnull=True, unique=True),
Field("value", "json", length=255),
Field("definition", "text", notnull=True),
migrate="preferences.table")
db.preferences.value.requires = None
#-------------------------------------------------------------------------------
#
# APPLICATION PREFERENCES
#
#-------------------------------------------------------------------------------
app = Storage()
for row in db(db.preferences).select():
app[row.property] = row.value
# add local variable
app["reg_institute"] = ""
app["institute"] = None
current.app = app
# -*- coding: utf-8 -*-
""" projects
"""
db.define_table("projects",
Field("project", "string", length=255, notnull=True, unique=True),
Field("agencies", "string", length=255, default=""),
migrate="projects.table")
db.projects._before_delete.append(INHIBIT_CASCADE_DELETE)
db.projects._before_delete.append(dbui.INHIBIT_DELETE_UNDEF)
db.projects._before_update.append(dbui.INHIBIT_UPDATE_UNDEF)
db.projects.project.filter_in = dbui.CLEAN_SPACES
\ No newline at end of file
# -*- coding: utf-8 -*-
""" publishers
"""
db.define_table("publishers",
Field("publisher", "string", length=255, default="", label="Review"),
Field("abbreviation", "string", length=255, notnull=True, unique=True),
Field("synonyms", "list:string", comment=tp_synonyms),
migrate="publishers.table")
db.publishers._before_delete.append(INHIBIT_CASCADE_DELETE)
db.publishers._before_delete.append(dbui.INHIBIT_DELETE_UNDEF)
db.publishers._before_update.append(dbui.INHIBIT_UPDATE_UNDEF)
db.publishers.publisher.filter_in = dbui.CLEAN_SPACES
db.publishers.abbreviation.filter_in = dbui.CLEAN_SPACES
\ No newline at end of file
# -*- coding: utf-8 -*-
""" renderers
The table axes, lists, sections and renderers are used by the lists tool.
"""
tp_postprocessing = \
T("Name of a function located in the modules list_postprocessing. "
"Can be a list of name separated by comma.")
tp_template = \
T("String containing blabla and the database fields to be displayed. "
"The substitution mechanism is: {tablename.fieldname} or {foreigntablename.fieldname}")
db.define_table("renderers",
Field("renderer", "string", length=255, notnull=True),
Field("template", "text", comment=tp_template, notnull=True),
Field("postprocessing", "text", comment=tp_postprocessing, default=""),
Field("definition", "text", default=""),
migrate="renderers.table")
\ No newline at end of file
# -*- coding: utf-8 -*-
""" reports
"""
db.define_table("reports",
Field("type", "string", length=255, notnull=True, unique=True),
migrate="reports.table")
db.reports._before_delete.append(INHIBIT_CASCADE_DELETE)
db.reports._before_delete.append(dbui.INHIBIT_DELETE_UNDEF)
db.reports._before_update.append(dbui.INHIBIT_UPDATE_UNDEF)
# -*- coding: utf-8 -*-
""" status
"""
db.define_table("status",
Field("code", "string", length=255, notnull=True, unique=True),
Field("definition", "text", notnull=True),
migrate="status.table")
db.status._before_delete.append(INHIBIT_CASCADE_DELETE)
db.status._before_delete.append(dbui.INHIBIT_DELETE_UNDEF)
db.status._before_update.append(dbui.INHIBIT_UPDATE_UNDEF)
# -*- coding: utf-8 -*-
""" teams
"""
db.define_table("teams",
Field("team", "string", length=255, notnull=True, unique=True),
Field("domain", "string", length=255, default=""),
migrate="teams.table")
db.teams._before_delete.append(INHIBIT_CASCADE_DELETE)
db.teams._before_delete.append(dbui.INHIBIT_DELETE_UNDEF)
db.teams._before_update.append(dbui.INHIBIT_UPDATE_UNDEF)
db.teams.team.filter_in = dbui.CLEAN_SPACES
db.teams.domain.filter_in = dbui.CLEAN_SPACES
\ No newline at end of file
# -*- coding: utf-8 -*-
""" graphs
"""
tp_stacked = \
T("The graph can be rendered as line or stacked chart. "
"The latter is used when the stacked fields are defined. ")
db.define_table("graphs",
Field("graph", "string", length=255, notnull=True),
Field("definition", "text", default=""),
Field('stack_axis', 'string', length=255, comment=tp_stacked),
Field('stack_granularity', 'string', length=255),
migrate="graphs.table")
db.graphs.graph.filter_in = dbui.CLEAN_SPACES
# -*- coding: utf-8 -*-
""" harvesters
The table my_authors, controllers and harvesters are used
by the harvesters tool.
"""