Skip to content
Snippets Groups Projects
Commit 3b5bb2e7 authored by legac's avatar legac
Browse files

Improved the files organization of the model.

parent 4aa0b71b
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
""" access
setup the connection to the databases
"""
db = DAL('sqlite://storage.sqlite', migrate=True)
...@@ -2,13 +2,14 @@ ...@@ -2,13 +2,14 @@
""" db """ db
Defined the database tables for your applications. Defined the database tables for your applications.
Initialized the dbui plugins
""" """
import locale import locale
from datetime import datetime from datetime import datetime
from gluon.tools import PluginManager from gluon.tools import PluginManager
dbui = local_import('plugin_dbui')
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# #
# plugin configuration parameters # plugin configuration parameters
...@@ -26,8 +27,6 @@ plugins.dbui.app_script_dir = 'static/scripts' # relative directory static/scri ...@@ -26,8 +27,6 @@ plugins.dbui.app_script_dir = 'static/scripts' # relative directory static/scri
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# #
# set the languages for the application # set the languages for the application
# The language has also to be defined in the internationalization service,
# locale, since it is use latter on to order list in alphabetic order.
# #
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
T.set_current_languages('en', 'en-gb', 'en-us') # mother tongue T.set_current_languages('en', 'en-gb', 'en-us') # mother tongue
...@@ -38,10 +37,12 @@ locale.setlocale(locale.LC_ALL, "fr_FR.UTF-8") ...@@ -38,10 +37,12 @@ locale.setlocale(locale.LC_ALL, "fr_FR.UTF-8")
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# #
# connection to the database # set constants
# #
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
db = DAL('sqlite://storage.sqlite') # if not, use SQLite or other DB undef = T(dbui.UNDEF)
undef_id = dbui.UNDEF_ID
year = datetime.now().year
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# #
...@@ -98,13 +99,13 @@ tp_ratio = \ ...@@ -98,13 +99,13 @@ tp_ratio = \
"Parameter for fuzzy string search." "Parameter for fuzzy string search."
db.define_table("harvesters", db.define_table("harvesters",
Field("id_teams", db.teams, default=1, label='Team'), Field("id_teams", db.teams, default=undef_id, label='Team'),
Field("controller", "string", notnull=True, comment=tp_controller), Field("controller", "string", notnull=True, comment=tp_controller),
Field("host", "string", notnull=True, default='cdsweb.cern.ch', comment=tp_host), Field("host", "string", notnull=True, default='cdsweb.cern.ch', comment=tp_host),
Field("collections", "string", comment=tp_collections), Field("collections", "string", comment=tp_collections),
Field("max_records", "integer", notnull=True, default=200, comment=tp_max_records), Field("max_records", "integer", notnull=True, default=200, comment=tp_max_records),
Field("ratio", "double", notnull=True, default=1.0, comment=tp_ratio), Field("ratio", "double", notnull=True, default=1.0, comment=tp_ratio),
Field("id_categories", db.categories, default=1, label='Category', comment=tp_category)) Field("id_categories", db.categories, default=undef_id, label='Category', comment=tp_category))
db.harvesters.controller.requires = \ db.harvesters.controller.requires = \
IS_IN_SET(['articles', 'proceedings', 'reports', 'talks']) IS_IN_SET(['articles', 'proceedings', 'reports', 'talks'])
...@@ -124,22 +125,6 @@ IS_FLOAT_IN_RANGE(0., 1.0) ...@@ -124,22 +125,6 @@ IS_FLOAT_IN_RANGE(0., 1.0)
# Publications table # Publications table
# #
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
#
# Regular expression defining authors, authors_cppm and speaker
#
#match_authors = \
#IS_MATCH(r'(((, )?([A-Z]\.(-[A-Z]\.)?)( [A-Z][a-z]+)+( et al.)?)+)')
#
#match_authors_cppm = \
#IS_MATCH(r'((, )?([A-Z]\.(-[A-Z]\.)?)( [A-Z][a-z]+)+)+')
#match_report_numbers = \
#IS_MATCH(r'')
#match_speaker = IS_MATCH(r'[A-Z]\.(-[A-Z]\.)?( [A-Z][a-z]+)+')
year = datetime.now().year
tp_authors = \ tp_authors = \
"""List of authors separated by commma: J. Doe, P.-Y. Smith """List of authors separated by commma: J. Doe, P.-Y. Smith
For large collaboration the first author followed by et al.: J. Doe et al.""" For large collaboration the first author followed by et al.: J. Doe et al."""
...@@ -157,8 +142,8 @@ tp_speaker = \ ...@@ -157,8 +142,8 @@ tp_speaker = \
db.define_table("publications", db.define_table("publications",
Field("title", "text", notnull=True), Field("title", "text", notnull=True),
Field("authors", "string", notnull=True, comment=tp_authors), Field("authors", "string", notnull=True, comment=tp_authors),
Field("id_collaborations", db.collaborations, default=1, label="Collaboration"), Field("id_collaborations", db.collaborations, default=undef_id, label="Collaboration"),
Field("id_publishers", db.publishers, default=1, label="Publisher"), Field("id_publishers", db.publishers, default=undef_id, label="Publisher"),
Field("year", "integer", notnull=True, default=year, requires=IS_INT_IN_RANGE(1900, year+1)), Field("year", "integer", notnull=True, default=year, requires=IS_INT_IN_RANGE(1900, year+1)),
Field("doi", "string"), Field("doi", "string"),
Field("volume", "integer", requires=IS_EMPTY_OR(IS_INT_IN_RANGE(1, None))), Field("volume", "integer", requires=IS_EMPTY_OR(IS_INT_IN_RANGE(1, None))),
...@@ -170,14 +155,14 @@ db.define_table("publications", ...@@ -170,14 +155,14 @@ db.define_table("publications",
Field("conference_start", "date", label='Start date'), Field("conference_start", "date", label='Start date'),
Field("conference_end", "date", label='End date'), Field("conference_end", "date", label='End date'),
Field("conference_town", "string", label='Town'), Field("conference_town", "string", label='Town'),
Field("id_countries", db.countries, default=1, label='Country'), Field("id_countries", db.countries, default=undef_id, label='Country'),
Field("conference_speaker", "string", label='Speaker', comment=tp_speaker), Field("conference_speaker", "string", label='Speaker', comment=tp_speaker),
Field("report_numbers", "string", comment=tp_report_numbers), Field("report_numbers", "string", comment=tp_report_numbers),
Field("id_reports", db.reports, default=1, label="Report type"), Field("id_reports", db.reports, default=undef_id, label="Report type"),
Field("authors_cppm", "text", notnull=True, comment=tp_authors_cppm), Field("authors_cppm", "text", notnull=True, comment=tp_authors_cppm),
Field("id_teams", db.teams, default=1, label='Team'), Field("id_teams", db.teams, default=undef_id, label='Team'),
Field("id_projects", db.projects, default=1, label='Projects'), Field("id_projects", db.projects, default=undef_id, label='Projects'),
Field("id_categories", db.categories, default=1, label='AERES')) Field("id_categories", db.categories, default=undef_id, label='AERES'))
db.publications.id_categories.requires = \ db.publications.id_categories.requires = \
IS_IN_DB(db, 'categories.id', 'categories.code') IS_IN_DB(db, 'categories.id', 'categories.code')
......
...@@ -4,10 +4,6 @@ ...@@ -4,10 +4,6 @@
Insert defaults values in the tables Insert defaults values in the tables
""" """
dbui = local_import('plugin_dbui')
undef = T(dbui.UNDEF)
undef_id = dbui.UNDEF_ID
if not db(db.categories.id).count(): if not db(db.categories.id).count():
db.categories.insert(id=undef_id, code=undef, definition=undef) db.categories.insert(id=undef_id, code=undef, definition=undef)
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" dummy """ virtdb
Defined tables in a dummy database. Defined tables in a virtual database.
They are used to build forms in order to generate url, .... They are used to build forms in order to generate url, ....
taking benefit of the web2py validators taking benefit of the web2py validators
...@@ -9,12 +9,12 @@ ...@@ -9,12 +9,12 @@
""" """
dummy = DAL(None) virtdb = DAL(None)
# the report node with selector # the report node with selector
tp_string = "tool tip for the string" tp_string = "tool tip for the string"
dummy.define_table("foo1", virtdb.define_table("foo1",
Field('my_string', 'string', comment=tp_string), Field('my_string', 'string', comment=tp_string),
Field('my_int', 'integer', requires=IS_INT_IN_RANGE(0, 100)), Field('my_int', 'integer', requires=IS_INT_IN_RANGE(0, 100)),
Field('my_date', 'date'), Field('my_date', 'date'),
......
# -*- coding: utf-8 -*-
""" widgets fields
"""
#
# Modify publications fields
#
fieldsModifier = dbui.FieldsModifier('publications')
fieldsModifier.configure_field('conference_start', format='Y-m-d')
fieldsModifier.configure_field('conference_end', format='Y-m-d')
fieldsModifier.configure_field('year', maxValue=datetime.now().year)
#
# Merge fields for the publication form
#
fieldsModifier.merge_fields('first_page',
'last_page',
fieldLabel=T('Pages'),
defaults={'flex': 1})
fieldsModifier.merge_fields('conference_start',
'conference_end',
fieldLabel=T('Dates'),
defaults={'flex': 1})
\ No newline at end of file
# -*- coding: utf-8 -*-
""" widgets forms
"""
#
# add plugin to all forms
#
dbui.configure_forms(db, plugins=['pFormToolTip'])
#
# Create fieldSet for the publication form
#
formModifier = dbui.FormModifier('publications')
formModifier.merge_fields('title',
'authors',
'id_collaborations',
'id_publishers',
'year',
'doi',
'volume',
'first_page',
'e_print',
title=T('General'),
flex=1)
formModifier.merge_fields('conference_title',
'conference_url',
'conference_start',
'conference_town',
'id_countries',
'conference_speaker',
dbui.Spacer(height=26*3),
title=T('Conference'),
flex=1)
formModifier.merge_fields('report_numbers',
'id_reports',
dbui.Spacer(height=220),
title=T('Report'),
flex=1)
formModifier.merge_fields('authors_cppm',
'id_teams',
'id_projects',
'id_categories',
dbui.Spacer(height=26*5),
title='CPPM',
flex=1)
#
# Organize fieldSet within a TabPanel embedded in the publication form
#
formModifier.set_mapper(dbui.map_tabpanel)
#
# Polish the look and feel of the publication form
# NOTE: the width/height define the size of the window
# when running the form from the grid. The defaults defines the height
# of the fieldSet allowing a fine tuning of the form layout.
#
formModifier.configure(buttonAlign='right',
labelWidth=100,
labelAlign='right',
width=400,
height=380,
defaults={'height': 320})
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" widgets """ widgets grids
Customize forms and grids widgets
""" """
from datetime import datetime
dbui = local_import('plugin_dbui')
# #
# add plugin to all grids and to all forms # add plugin to all grids
# #
dbui.configure_grids(db, plugins=['pGridRowEditorConfirmDelete', dbui.configure_grids(db, plugins=['pGridRowEditorConfirmDelete',
'pGridRowEditorContextMenu', 'pGridRowEditorContextMenu',
'pGridRowEditorDblClick', 'pGridRowEditorDblClick',
'pGridExport']) 'pGridExport'])
dbui.configure_forms(db, plugins=['pFormToolTip'])
#
# Modify publications fields
#
fieldsModifier = dbui.FieldsModifier('publications')
#
# Setup date format and default values
#
fieldsModifier.configure_field('conference_start',
format='Y-m-d')
fieldsModifier.configure_field('conference_end',
format='Y-m-d')
fieldsModifier.configure_field('year',
maxValue=datetime.now().year)
#
# Create composite fields for the publication form
#
fieldsModifier.merge_fields('first_page',
'last_page',
fieldLabel=T('Pages'),
defaults={'flex': 1})
fieldsModifier.merge_fields('conference_start',
'conference_end',
fieldLabel=T('Dates'),
defaults={'flex': 1})
#
# Create fieldSet for the publication form
#
formModifier = dbui.FormModifier('publications')
formModifier.merge_fields('title',
'authors',
'id_collaborations',
'id_publishers',
'year',
'doi',
'volume',
'first_page',
'e_print',
title=T('General'),
flex=1)
formModifier.merge_fields('conference_title',
'conference_url',
'conference_start',
'conference_town',
'id_countries',
'conference_speaker',
dbui.Spacer(height=26*3),
title=T('Conference'),
flex=1)
formModifier.merge_fields('report_numbers',
'id_reports',
dbui.Spacer(height=220),
title=T('Report'),
flex=1)
formModifier.merge_fields('authors_cppm',
'id_teams',
'id_projects',
'id_categories',
dbui.Spacer(height=26*5),
title='CPPM',
flex=1)
#
# Organize fieldSet within a TabPanel embedded in the publication form
#
formModifier.set_mapper(dbui.map_tabpanel)
#
# Polish the look and feel of the publication form
# NOTE: the width/height define the size of the window
# when running the form from the grid. The defaults defines the height
# of the fieldSet allowing a fine tuning of the form layout.
# #
formModifier.configure(buttonAlign='right', # Polish categories grid
labelWidth=100,
labelAlign='right',
width=400,
height=380,
defaults={'height': 320})
#
# fine tune categories grid
# #
gridModifier = dbui.GridModifier('categories') gridModifier = dbui.GridModifier('categories')
gridModifier.configure_column('code', width=10) gridModifier.configure_column('code', width=10)
...@@ -189,39 +92,3 @@ filters = [('year', '==', T('select publication for a given year')), ...@@ -189,39 +92,3 @@ filters = [('year', '==', T('select publication for a given year')),
gridModifier.set_filters(*filters, gridModifier.set_filters(*filters,
plugins=['pFormToolTip'], plugins=['pFormToolTip'],
width=300) width=300)
#
# order store for technical table
#
storeModifier = dbui.StoreModifier('teams')
storeModifier.orderby(~db.teams.team)
#
# The navigation tree
#
formNode = dbui.Node(T('Forms'))
configurator = lambda tablename: dbui.to_formPanel(db[tablename])
formNode.add_children(db.tables, func=configurator)
gridNode = dbui.Node(T('Tables'))
configurator = lambda tablename: dbui.to_gridPanel(db[tablename])
gridNode.add_children(db.tables, func=configurator)
reportNode = dbui.Node(T('Reports'))
node = dbui.Panel(html="salut ma poule")
reportNode.add_child(T('report_1'), node)
fields = dbui.to_fields(dummy.foo1)
selector = dbui.FieldSet(items=fields, plugins=['pFormToolTip'],
title=T('Select'))
node = dbui.PanelWithUrlSelector(baseUrl=URL('reports', 'report_2'),
isMathJax=dbui.is_mathjax(),
panelCfg=dbui.Panel(),
selectorCfg=selector,
selectorCollapsible=False)
reportNode.add_child(T('report_2'), node)
viewportModifier = dbui.ViewportModifier()
viewportModifier.append_plugins('pViewportLogin')
viewportModifier.configure(logged=True)
viewportModifier.add_node(formNode, gridNode, reportNode)
# -*- coding: utf-8 -*-
""" widgets stores
"""
#
# order store contents for technical tables
#
storeModifier = dbui.StoreModifier('teams')
storeModifier.orderby(~db.teams.team)
# -*- coding: utf-8 -*-
""" widgets viewport
"""
#
# The form node
#
formNode = dbui.Node(T('Forms'))
configurator = lambda tablename: dbui.to_formPanel(db[tablename])
formNode.add_children(db.tables, func=configurator)
#
# the grid node
#
gridNode = dbui.Node(T('Tables'))
configurator = lambda tablename: dbui.to_gridPanel(db[tablename])
gridNode.add_children(db.tables, func=configurator)
#
# the report node
#
reportNode = dbui.Node(T('Reports'))
node = dbui.Panel(html="salut ma poule")
reportNode.add_child(T('report_1'), node)
fields = dbui.to_fields(virtdb.foo1)
selector = dbui.FieldSet(items=fields, plugins=['pFormToolTip'],
title=T('Select'))
node = dbui.PanelWithUrlSelector(baseUrl=URL('reports', 'report_2'),
isMathJax=dbui.is_mathjax(),
panelCfg=dbui.Panel(),
selectorCfg=selector,
selectorCollapsible=False)
reportNode.add_child(T('report_2'), node)
#
# The viewport with its navigation tree
#
print "hello", reportNode
viewportModifier = dbui.ViewportModifier()
viewportModifier.append_plugins('pViewportLogin')
viewportModifier.configure(logged=True)
viewportModifier.add_node(formNode, gridNode, reportNode)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment