Commit 102c190a authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

New files organisation for the model.

parent 210bc490
# -*- coding: utf-8 -*-
""" access
setup the connection to the databases
setup the connection to the databases.
Define constants for the different role
"""
DB_MYSQL = 'mysql://GesProd:Prod_CPPM@maretude.in2p3.fr/GesProd'
......@@ -10,12 +11,26 @@ MIGRATE = False
ID_ADMIN, ADMIN, DEF_ADMIN = 1, 'admin', 'administrators, librairians,...'
ID_USER, USER, DEF_USER = 2, 'user', 'liaisons, team leaders,...'
#-------------------------------------------------------------------------------
#
# connect to the database
# MYSQL database
#
#-------------------------------------------------------------------------------
# try:
# db = DAL(DB_MYSQL, migrate_enabled=MIGRATE, pool_size=10)
# except:
# raise HTTP(500, T("Can't access the MySQL database !!!"))
#-------------------------------------------------------------------------------
#
# SQLITE database (test)
#
#-------------------------------------------------------------------------------
db = DAL('sqlite://storage.sqlite', migrate_enabled=MIGRATE)
#-------------------------------------------------------------------------------
#
# virtual database
#
#-------------------------------------------------------------------------------
virtdb = DAL(None)
# -*- coding: utf-8 -*-
""" Common settings
"""
import filters
import locale
import plugin_dbui as dbui
from callbacks import (INHIBIT_CASCADE_DELETE,
INHIBIT_DUPLICATE_PUBLICATION,
INHIBIT_PUBLICATION_DELETE_ON_OK,
INHIBIT_PUBLICATION_UPDATE_ON_OK)
from datetime import datetime
from gluon.tools import PluginManager
import harvest_tools
#-------------------------------------------------------------------------------
#
# PLUGIN DBUI
#
#-------------------------------------------------------------------------------
plugins = PluginManager()
plugins.dbui.app_css = 'static/my.css'
#plugins.dbui.app_js_dir = None
#plugins.dbui.app_libmin = None
#plugins.dbui.app_script = None
plugins.dbui.app_script_dir = 'static/scripts'
#-------------------------------------------------------------------------------
#
# LANGUAGE
#
#-------------------------------------------------------------------------------
T.set_current_languages('en', 'en-gb', 'en-us') # mother tongue
T.force('fr-fr') # user language
T.lazy = False # immediate translation
locale.setlocale(locale.LC_ALL, "fr_FR.UTF-8")
#-------------------------------------------------------------------------------
#
# CONSTANTS
#
#-------------------------------------------------------------------------------
undef = T(dbui.UNDEF)
undef_id = dbui.UNDEF_ID
year = datetime.now().year
DIRS = ['ASC', 'DESC']
AXES = ['', 'categories', 'projects', 'teams', 'time']
AXES_2 = ['categories', 'projects', 'publishers', 'teams', 'time']
ONE_HOUR = 3600000
MODE_DRY_RUN = T(harvest_tools.DRY_RUN)
MODE_CHANGE_STATUS = T('change status')
MODE_LOAD_IN_DB = T('load in the database')
#-------------------------------------------------------------------------------
#
# COMMON CONFIGURATION FOR FORMS AND GRIDS
#
#-------------------------------------------------------------------------------
tables = ['authors_roles',
'axes',
'categories',
'collaborations',
'controllers',
'countries',
'cppm_authors',
'harvesters',
'lists',
'metrics',
'organisations',
'projects',
'publications',
'publishers',
'renderers',
'reports',
'sections',
'status',
'teams']
dbui.configure_forms(db, plugins=['pFormToolTip'], width=350)
dbui.configure_grids(tables, plugins=['pGridRowEditorConfirmDelete',
'pGridRowEditorContextMenu',
'pGridRowEditorDblClick',
'pGridToolbar'])
# -*- coding: utf-8 -*-
""" authors_roles
It defined the role of the CPPM authors.
"""
db.define_table("authors_roles",
Field("role", "string", notnull=True, unique=True),
Field("definition", "text", default="", notnull=True),
migrate="authors_roles.table")
db.authors_roles._before_delete.append(INHIBIT_CASCADE_DELETE)
\ No newline at end of file
# -*- 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", notnull=True),
Field("granularity", "string", notnull=True),
migrate="axes.table")
\ No newline at end of file
# -*- coding: utf-8 -*-
""" categories
"""
db.define_table("categories",
Field("code", "string", notnull=True, unique=True),
Field("usual", "string", default=""),
Field("definition", "text", notnull=True),
migrate="categories.table")
db.categories._before_delete.append(INHIBIT_CASCADE_DELETE)
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
"""
db.define_table("collaborations",
Field("collaboration", "string", notnull=True, unique=True),
migrate="collaborations.table")
db.collaborations._before_delete.append(INHIBIT_CASCADE_DELETE)
db.collaborations.collaboration.filter_in = filters.CLEAN_COLLABORATION
\ No newline at end of file
# -*- coding: utf-8 -*-
""" controllers
The table cppm_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 web2py controller to run a search: articles, proceedings,...")
db.define_table("controllers",
Field("controller", "string", comment=tp_controller, notnull=True),
Field("id_categories", "reference categories", comment=tp_category, default=undef_id, label='Category'),
migrate="controllers.table")
db.controllers.controller.filter_in = dbui.CLEAN_SPACES
\ No newline at end of file
# -*- coding: utf-8 -*-
""" countries
"""
db.define_table("countries",
Field("country", "string", notnull=True, unique=True),
migrate="countries.table")
db.countries._before_delete.append(INHIBIT_CASCADE_DELETE)
db.countries.country.filter_in = dbui.CLEAN_SPACES
\ No newline at end of file
# -*- coding: utf-8 -*-
""" projects
"""
db.define_table("projects",
Field("project", "string", notnull=True, unique=True),
Field("agencies", "string", default=""),
migrate="projects.table")
db.projects._before_delete.append(INHIBIT_CASCADE_DELETE)
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", default="", label="Review"),
Field("abbreviation", "string", notnull=True, unique=True),
migrate="publishers.table")
db.publishers._before_delete.append(INHIBIT_CASCADE_DELETE)
db.publishers.publisher.filter_in = dbui.CLEAN_SPACES
db.publishers.abbreviation.filter_in = filters.CLEAN_REVIEW
\ 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", 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", notnull=True, unique=True),
migrate="reports.table")
db.reports._before_delete.append(INHIBIT_CASCADE_DELETE)
\ No newline at end of file
# -*- coding: utf-8 -*-
""" status
"""
db.define_table("status",
Field("code", "string", notnull=True, unique=True),
Field("definition", "text", notnull=True),
migrate="status.table")
db.status._before_delete.append(INHIBIT_CASCADE_DELETE)
\ No newline at end of file
# -*- coding: utf-8 -*-
""" teams
"""
db.define_table("teams",
Field("team", "string", notnull=True, unique=True),
Field("domain", "string", default=""),
migrate="teams.table")
db.teams._before_delete.append(INHIBIT_CASCADE_DELETE)
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 -*-
""" cppm_authors
The table cppm_authors, controllers and harvesters are used
by the harvesters tool.
It is the recovery table use by harvesters.
It defines a list of authors for each projects and each year.
"""
tp_authors_cppm = \
T("List of authors belonging to CPPM, separated by comma: P.-Y. Doe, J. Smith")
db.define_table("cppm_authors",
Field("year", "integer", default=year, notnull=True),
Field("id_teams", "reference teams", label='Team', notnull=True),
Field("id_projects", "reference projects", label='Project', notnull=True),
Field("authors", "text", comment=tp_authors_cppm, notnull=True),
migrate="cppm_authors.table")
db.cppm_authors.year.requires = IS_INT_IN_RANGE(1900, year+1)
\ No newline at end of file
# -*- coding: utf-8 -*-
""" harvesters
The table cppm_authors, controllers and harvesters are used
by the harvesters tool.
"""
tp_collections = \
T("List of collections separated by commma: LHCb Papers, LHCb Talks")
tp_host = \
T("Address of the invenio store where the search is performed.")
tp_ratio = \
T("Parameter for fuzzy string search.")
db.define_table("harvesters",
Field("id_teams", "reference teams", label='Team', notnull=True),
Field("id_projects", "reference projects", label='Project', notnull=True),
Field("controller", "string", comment=tp_controller, label='Harvest', notnull=True),
Field("host", "string", comment=tp_host, default='cdsweb.cern.ch', label='Store', notnull=True),
Field("collections", "string", comment=tp_collections, default=""),
Field("ratio", "double", comment=tp_ratio, default=1.0, notnull=True),
Field("id_categories", "reference categories", comment=tp_category, default=undef_id, label='Category'),
migrate="harvesters.table")
db.harvesters.collections.filter_in = dbui.CLEAN_SPACES
db.harvesters.controller.filter_in = dbui.CLEAN_SPACES
db.harvesters.host.filter_in = dbui.CLEAN_SPACES
db.harvesters.controller.requires = IS_IN_DB(db, 'controllers.controller')
db.harvesters.ratio.requires = IS_FLOAT_IN_RANGE(0., 1.0)
\ No newline at end of file
# -*- coding: utf-8 -*-
""" lists
The table axes, lists, sections and renderers are used by the lists tool.
"""
tp_axis_label = \
T("Axis values are used to defined the title of each level in section. "
"This field allow to replace some values by another ones. "
'Rule: label1: "value1", label2: "value2",....')
tp_sections = \
T("List of sections separated by a comma: Articles, Proceedings.")
db.define_table("lists",
Field("list", "string", notnull=True),
Field("definition", "text", default=""),
Field("sections", "text", comment=tp_sections, notnull=True),
Field("section_level_1", "string", default="", label=T("Level 1")),
Field("section_level_2", "string", default="", label=T("Level 2")),
Field("section_level_3", "string", default="", label=T("Level 3")),
Field("section_level_4", "string", default="", label=T("Level 4")),
Field("axis_granularity_categories", "string", default="usual", label=T("Categories")),
Field("axis_granularity_projects", "string", default="project", label=T("Projects")),
Field("axis_granularity_teams", "string", default="team", label=T("Teams")),
Field("axis_granularity_time", "string", default="year", label=T("Time")),
Field("axis_direction_categories", "string", default="ASC"),
Field("axis_direction_projects", "string", default="ASC"),
Field("axis_direction_teams", "string", default="ASC"),
Field("axis_direction_time", "string", default="ASC"),
Field("axis_label_converters", "text", comment=tp_axis_label, default="", label="Converters"),
Field("header_flag", "boolean", default=True, label="Header"),
Field("footer_flag", "boolean", default=True, label="Footer"),
migrate="lists.table")
db.lists.list.filter_in = dbui.CLEAN_SPACES
db.lists.sections.filter_in = dbui.CLEAN_SPACES
db.lists.axis_direction_categories.requires = IS_IN_SET(DIRS)
db.lists.axis_direction_projects.requires = IS_IN_SET(DIRS)
db.lists.axis_direction_teams.requires = IS_IN_SET(DIRS)
db.lists.axis_direction_time.requires = IS_IN_SET(DIRS)
se = set(db.categories.fields).difference(['id', 'definition'])
db.lists.axis_granularity_categories.requires = IS_IN_SET(se)
se = set(db.projects.fields).difference(['id', 'definition'])
db.lists.axis_granularity_projects.requires = IS_IN_SET(se)
se = set(db.teams.fields).difference(['id', 'definition'])
db.lists.axis_granularity_teams.requires = IS_IN_SET(se)
db.lists.axis_granularity_time.requires = IS_IN_SET(['year'])
db.lists.section_level_1.requires = IS_IN_SET(AXES)
db.lists.section_level_2.requires = IS_IN_SET(AXES)
db.lists.section_level_3.requires = IS_IN_SET(AXES)
db.lists.section_level_4.requires = IS_IN_SET(AXES)
\ No newline at end of file
# -*- coding: utf-8 -*-
""" metrics
"""
tp_axis_label = \
T("Axis values are used to defined the title of each level in section. "
"This field allow to replace some values by another ones. "
'Rule: label1: "value1", label2: "value2",....')
tp_conditions = \
T("can be applied on any field of the table using the SQL WHERE syntax. "
"Be aware that foreign key are not resolved (see smart_query in the web2py)")
db.define_table("metrics",
Field("metric", "string", notnull=True),
Field("definition", "text", default=""),
Field("axis_columns", "string", label=T('Columns'), notnull=True),
Field("axis_rows", "string", label=T('Rows'), notnull=True),
Field("axis_granularity_categories", "string", default="usual", label=T("Categories")),
Field("axis_granularity_projects", "string", default="project", label=T("Projects")),
Field("axis_granularity_publishers", "string", default="publisher", label=T("Publishers")),
Field("axis_granularity_teams", "string", default="team", label=T("Teams")),
Field("axis_granularity_time", "string", default="year", label=T("Time")),
Field("axis_direction_categories", "string", default="ASC"),
Field("axis_direction_projects", "string", default="ASC"),
Field("axis_direction_publishers", "string", default="ASC"),
Field("axis_direction_teams", "string", default="ASC"),
Field("axis_direction_time", "string", default="ASC"),
Field("axis_label_converters", "text", comment=tp_axis_label, default="", label="Converters"),
Field("conditions", "text", comment=tp_conditions, default=""),
Field("header_flag", "boolean", default=True, label="Header"),
Field("footer_flag", "boolean", default=True, label="Footer"),
migrate="metrics.table")
db.metrics.metric.filter_in = dbui.CLEAN_SPACES
db.metrics.axis_columns.requires = IS_IN_SET(AXES_2)
db.metrics.axis_direction_categories.requires = IS_IN_SET(DIRS)
db.metrics.axis_direction_projects.requires = IS_IN_SET(DIRS)
db.metrics.axis_direction_publishers.requires = IS_IN_SET(DIRS)
db.metrics.axis_direction_teams.requires = IS_IN_SET(DIRS)
db.metrics.axis_direction_time.requires = IS_IN_SET(DIRS)
se = set(db.categories.fields).difference(['id', 'definition'])
db.metrics.axis_granularity_categories.requires = IS_IN_SET(se)
se = set(db.projects.fields).difference(['id', 'definition'])
db.metrics.axis_granularity_projects.requires = IS_IN_SET(se)
se = set(db.publishers.fields).difference(['id', 'definition'])
db.metrics.axis_granularity_publishers.requires = IS_IN_SET(se)
se = set(db.teams.fields).difference(['id', 'definition'])
db.metrics.axis_granularity_teams.requires = IS_IN_SET(se)
db.metrics.axis_granularity_time.requires = IS_IN_SET(['year'])
db.metrics.axis_rows.requires = IS_IN_SET(AXES_2)
\ No newline at end of file
# -*- coding: utf-8 -*-
""" organisations
It defines the relation between teams and projects.
"""
db.define_table("organisation",
Field("id_teams", "reference teams", default=undef_id, label='Team'),
Field("id_projects", "reference projects", default=undef_id, label='Project'),
migrate="organisation.table")
\ No newline at end of file
# -*- coding: utf-8 -*-
""" db
""" publications
Core tables for the applications.
"""
import filters
import locale
import plugin_dbui as dbui
from callbacks import (INHIBIT_CASCADE_DELETE,
INHIBIT_DUPLICATE_PUBLICATION,
INHIBIT_PUBLICATION_DELETE_ON_OK,
INHIBIT_PUBLICATION_UPDATE_ON_OK)
from datetime import datetime
from gluon.tools import PluginManager
#-------------------------------------------------------------------------------
#
# plugin configuration parameters
#
#-------------------------------------------------------------------------------
plugins = PluginManager()
plugins.dbui.app_css = 'static/my.css'
#plugins.dbui.app_js_dir = None
#plugins.dbui.app_libmin = None
#plugins.dbui.app_script = None
plugins.dbui.app_script_dir = 'static/scripts'
#-------------------------------------------------------------------------------
#
# set the languages for the application
#
#-------------------------------------------------------------------------------
T.set_current_languages('en', 'en-gb', 'en-us') # mother tongue
T.force('fr-fr') # user language
T.lazy = False # immediate translation
locale.setlocale(locale.LC_ALL, "fr_FR.UTF-8")
#-------------------------------------------------------------------------------
#
# set constants
#
#-------------------------------------------------------------------------------
undef = T(dbui.UNDEF)
undef_id = dbui.UNDEF_ID
year = datetime.now().year
#-------------------------------------------------------------------------------
#
# basic tables
#
#-------------------------------------------------------------------------------
db.define_table("authors_roles",
Field("role", "string", notnull=True, unique=True),
Field("definition", "text", default="", notnull=True),
migrate="authors_roles.table")
db.authors_roles._before_delete.append(INHIBIT_CASCADE_DELETE)
db.define_table("categories",
Field("code", "string", notnull=True, unique=True),
Field("usual", "string", default=""),
Field("definition", "text", notnull=True),
migrate="categories.table")
db.categories._before_delete.append(INHIBIT_CASCADE_DELETE)
db.categories.code.filter_in = dbui.CLEAN_SPACES
db.categories.usual.filter_in = dbui.CLEAN_SPACES
db.define_table("collaborations",
Field("collaboration", "string", notnull=True, unique=True),
migrate="collaborations.table")
db.collaborations._before_delete.append(INHIBIT_CASCADE_DELETE)
db.collaborations.collaboration.filter_in = filters.CLEAN_COLLABORATION
db.define_table("countries",
Field("country", "string", notnull=True, unique=True),
migrate="countries.table")
db.countries._before_delete.append(INHIBIT_CASCADE_DELETE)
db.countries.country.filter_in = dbui.CLEAN_SPACES
db.define_table("projects",
Field("project", "string", notnull=True, unique=True),
Field("agencies", "string", default=""),
migrate="projects.table")
db.projects._before_delete.append(INHIBIT_CASCADE_DELETE)
db.projects.project.filter_in = dbui.CLEAN_SPACES
db.define_table("publishers",
Field("publisher", "string", default="", label="Review"),
Field("abbreviation", "string", notnull=True, unique=True),
migrate="publishers.table")
db.publishers._before_delete.append(INHIBIT_CASCADE_DELETE)
db.publishers.publisher.filter_in = dbui.CLEAN_SPACES
db.publishers.abbreviation.filter_in = filters.CLEAN_REVIEW
db.define_table("reports",
Field("type", "string", notnull=True, unique=True),
migrate="reports.table")
db.reports._before_delete.append(INHIBIT_CASCADE_DELETE)
db.define_table("status",
Field("code", "string", notnull=True, unique=True),
Field("definition", <