Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
w2pext
plugin_dbui
Commits
8294960b
Commit
8294960b
authored
May 02, 2017
by
LE GAC Renaud
Browse files
Refactor models by creating modules.
parent
c6e4938d
Changes
32
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
109 additions
and
569 deletions
+109
-569
models/access.py
models/access.py
+0
-19
models/db0_categories.py
models/db0_categories.py
+0
-13
models/db0_collaborations.py
models/db0_collaborations.py
+0
-7
models/db0_countries_.py
models/db0_countries_.py
+0
-12
models/db0_new_fields.py
models/db0_new_fields.py
+0
-13
models/db0_preferences.py
models/db0_preferences.py
+0
-12
models/db0_projects.py
models/db0_projects.py
+0
-7
models/db0_publishers.py
models/db0_publishers.py
+0
-8
models/db0_reports.py
models/db0_reports.py
+0
-7
models/db0_teams.py
models/db0_teams.py
+0
-9
models/db1_harvesters.py
models/db1_harvesters.py
+0
-47
models/db1_publications.py
models/db1_publications.py
+0
-55
models/main.py
models/main.py
+109
-0
models/ui_categories.py
models/ui_categories.py
+0
-51
models/ui_collaborations.py
models/ui_collaborations.py
+0
-27
models/ui_countries.py
models/ui_countries.py
+0
-27
models/ui_harvesters.py
models/ui_harvesters.py
+0
-37
models/ui_new_fields.py
models/ui_new_fields.py
+0
-39
models/ui_projects.py
models/ui_projects.py
+0
-27
models/ui_publications.py
models/ui_publications.py
+0
-152
No files found.
models/access.py
deleted
100644 → 0
View file @
c6e4938d
# -*- coding: utf-8 -*-
""" access
setup the connection to the databases
"""
# ............................................................................
#
# sqlite database
#
db
=
DAL
(
'sqlite://storage.sqlite'
,
lazy_tables
=
True
,
migrate
=
True
)
# ............................................................................
#
# virtual database
#
virtdb
=
DAL
(
None
)
models/db0_categories.py
deleted
100644 → 0
View file @
c6e4938d
# -*- coding: utf-8 -*-
""" categories
"""
tp_code
=
"The code has to be in upper case."
db
.
define_table
(
"categories"
,
Field
(
"code"
,
"string"
,
comment
=
tp_code
,
notnull
=
True
,
unique
=
True
),
Field
(
"definition"
,
"text"
,
notnull
=
True
),
migrate
=
"categories.table"
)
db
.
categories
.
_before_delete
.
append
(
dbui
.
INHIBIT_DELETE_UNDEF
)
db
.
categories
.
_before_update
.
append
(
dbui
.
INHIBIT_UPDATE_UNDEF
)
\ No newline at end of file
models/db0_collaborations.py
deleted
100644 → 0
View file @
c6e4938d
# -*- coding: utf-8 -*-
""" Collaborations
"""
db
.
define_table
(
"collaborations"
,
Field
(
"collaboration"
,
"string"
,
notnull
=
True
,
unique
=
True
),
migrate
=
"collaborations.table"
)
\ No newline at end of file
models/db0_countries_.py
deleted
100644 → 0
View file @
c6e4938d
# -*- coding: utf-8 -*-
""" countries
"""
db
.
define_table
(
"countries"
,
Field
(
"country"
,
"string"
,
notnull
=
True
,
unique
=
True
),
Field
(
"abbreviation"
,
"string"
,
notnull
=
True
),
migrate
=
"countries.table"
)
db
.
countries
.
_before_delete
.
append
(
country_delete
)
db
.
countries
.
_before_insert
.
append
(
country_insert
)
db
.
countries
.
_before_update
.
append
(
country_update
)
\ No newline at end of file
models/db0_new_fields.py
deleted
100644 → 0
View file @
c6e4938d
# -*- coding: utf-8 -*-
""" new_fields
"""
db
.
define_table
(
"new_fields"
,
Field
(
"string"
,
"string"
),
Field
(
"list_string"
,
"list:string"
),
Field
(
"dictionary"
,
"json"
),
Field
(
"python_code"
,
"text"
),
migrate
=
"new_fields.table"
)
# NOTE: if we remove the json validator its seem to work ?
db
.
new_fields
.
dictionary
.
requires
=
None
\ No newline at end of file
models/db0_preferences.py
deleted
100644 → 0
View file @
c6e4938d
# -*- coding: utf-8 -*-
""" preferences
"""
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"
)
# NOTE: if we remove the json validator its seem to work ?
db
.
preferences
.
value
.
requires
=
None
\ No newline at end of file
models/db0_projects.py
deleted
100644 → 0
View file @
c6e4938d
# -*- coding: utf-8 -*-
""" projects
"""
db
.
define_table
(
"projects"
,
Field
(
"project"
,
"string"
,
notnull
=
True
,
unique
=
True
),
migrate
=
"projects.table"
)
\ No newline at end of file
models/db0_publishers.py
deleted
100644 → 0
View file @
c6e4938d
# -*- coding: utf-8 -*-
""" publishers
"""
db
.
define_table
(
"publishers"
,
Field
(
"publisher"
,
"string"
,
notnull
=
True
,
unique
=
True
),
Field
(
"abbreviation"
,
"string"
,
notnull
=
True
),
migrate
=
"publishers.table"
)
\ No newline at end of file
models/db0_reports.py
deleted
100644 → 0
View file @
c6e4938d
# -*- coding: utf-8 -*-
""" reports
"""
db
.
define_table
(
"reports"
,
Field
(
"type"
,
"string"
,
notnull
=
True
,
unique
=
True
),
migrate
=
"reports.table"
)
\ No newline at end of file
models/db0_teams.py
deleted
100644 → 0
View file @
c6e4938d
# -*- coding: utf-8 -*-
""" teams
"""
db
.
define_table
(
"teams"
,
Field
(
"team"
,
"string"
,
notnull
=
True
,
unique
=
True
),
migrate
=
"teams.table"
)
db
.
teams
.
team
.
filter_in
=
dbui
.
CLEAN_SPACES
\ No newline at end of file
models/db1_harvesters.py
deleted
100644 → 0
View file @
c6e4938d
# -*- coding: utf-8 -*-
""" harvesters
"""
tp_category
=
\
"Publication category associated to the record."
tp_collections
=
\
"List of collections separated by commma: LHCb Papers, LHCb Talks"
tp_controller
=
\
"The name of the web2py controller running the search: articles, proceedings,..."
tp_host
=
\
"Address of the invenio store where the search is performed."
tp_max_records
=
\
"Maximum number of records which can be retrieved from a search."
tp_ratio
=
\
"Parameter for fuzzy string search."
db
.
define_table
(
"harvesters"
,
Field
(
"id_teams"
,
"reference teams"
,
default
=
undef_id
,
label
=
'Team'
),
Field
(
"id_projects"
,
"reference projects"
,
default
=
undef_id
,
label
=
'Project'
),
Field
(
"controller"
,
"string"
,
default
=
'articles'
,
notnull
=
True
,
comment
=
tp_controller
),
Field
(
"host"
,
"string"
,
notnull
=
True
,
default
=
'cdsweb.cern.ch'
,
label
=
'Store'
,
comment
=
tp_host
),
Field
(
"collections"
,
"string"
,
comment
=
tp_collections
),
Field
(
"ratio"
,
"double"
,
notnull
=
True
,
default
=
1.0
,
comment
=
tp_ratio
),
Field
(
"id_categories"
,
"reference categories"
,
default
=
1
,
label
=
'Category'
,
comment
=
tp_category
),
migrate
=
"harvesters.table"
)
db
.
harvesters
.
controller
.
requires
=
\
IS_IN_SET
([
'articles'
,
'notes'
,
'preprints'
,
'proceedings'
,
'reports'
,
'talks'
,
'theses'
])
# TEST THE DIFFERENT SYNTAX DEFINING FOREIGN KEY
db
.
harvesters
.
id_categories
.
requires
=
\
IS_IN_DB
(
db
,
'categories.id'
,
'categories.code'
)
db
.
harvesters
.
id_projects
.
requires
=
\
IS_IN_DB
(
db
,
'projects.project'
)
#db.harvesters.id_teams.requires = \
#IS_IN_DB(db, 'teams.id', 'teams.team')
db
.
harvesters
.
ratio
.
requires
=
\
IS_FLOAT_IN_RANGE
(
0.
,
1.0
)
\ No newline at end of file
models/db1_publications.py
deleted
100644 → 0
View file @
c6e4938d
# -*- coding: utf-8 -*-
""" publications
"""
tp_authors
=
\
"""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."""
tp_authors_cppm
=
\
"""List of authors separated by comma: P.-Y. Doe, J. Smith"""
tp_first
=
"first page"
tp_last
=
"last_page"
tp_report_numbers
=
\
"""List of report identifier separated by comma:
LHCb-PROC-2008-04, arXiv:0906.1516 """
tp_speaker
=
\
"""The name of the speaker: P.-Y. Smith"""
db
.
define_table
(
"publications"
,
Field
(
"title"
,
"text"
,
notnull
=
True
),
Field
(
"authors"
,
"string"
,
notnull
=
True
,
comment
=
tp_authors
),
Field
(
"id_collaborations"
,
'reference collaborations'
,
default
=
undef_id
,
label
=
"Collaboration"
),
Field
(
"id_publishers"
,
'reference publishers'
,
default
=
undef_id
,
label
=
"Publisher"
),
Field
(
"year"
,
"integer"
,
notnull
=
True
,
default
=
year
,
requires
=
IS_INT_IN_RANGE
(
1900
,
year
+
1
)),
Field
(
"doi"
,
"string"
),
Field
(
"volume"
,
"integer"
,
requires
=
IS_EMPTY_OR
(
IS_INT_IN_RANGE
(
1
,
None
))),
Field
(
"first_page"
,
"integer"
,
requires
=
IS_EMPTY_OR
(
IS_INT_IN_RANGE
(
1
,
None
)),
comment
=
tp_first
),
Field
(
"last_page"
,
"integer"
,
requires
=
IS_EMPTY_OR
(
IS_INT_IN_RANGE
(
1
,
None
)),
comment
=
tp_last
),
Field
(
"e_print"
,
"string"
,
requires
=
IS_EMPTY_OR
(
IS_URL
())),
Field
(
"conference_title"
,
"text"
,
label
=
'Title'
),
Field
(
"conference_url"
,
"string"
,
label
=
'url'
,
requires
=
IS_EMPTY_OR
(
IS_URL
())),
Field
(
"conference_start"
,
"date"
,
label
=
'Start date'
),
Field
(
"conference_end"
,
"date"
,
label
=
'End date'
),
Field
(
"conference_town"
,
"string"
,
label
=
'Town'
),
Field
(
"id_countries"
,
'reference countries'
,
default
=
undef_id
,
label
=
'Country'
),
Field
(
"conference_speaker"
,
"string"
,
label
=
'Speaker'
,
comment
=
tp_speaker
),
Field
(
"report_numbers"
,
"string"
,
comment
=
tp_report_numbers
),
Field
(
"id_reports"
,
'reference reports'
,
default
=
undef_id
,
label
=
"Report type"
),
Field
(
"authors_cppm"
,
"text"
,
notnull
=
True
,
comment
=
tp_authors_cppm
),
Field
(
"id_teams"
,
'reference teams'
,
default
=
undef_id
,
label
=
'Team'
),
Field
(
"id_projects"
,
'reference projects'
,
default
=
undef_id
,
label
=
'Projects'
),
Field
(
"id_categories"
,
'reference categories'
,
default
=
undef_id
,
label
=
'AERES'
),
migrate
=
"publications.table"
)
# use different techniques to define foreign field
db
.
publications
.
id_categories
.
requires
=
\
IS_IN_DB
(
db
,
'categories.id'
,
'categories.code'
)
db
.
publications
.
id_publishers
.
requires
=
IS_IN_DB
(
db
,
'publishers.abbreviation'
)
db
.
publications
.
id_projects
.
requires
=
IS_IN_DB
(
db
,
db
.
projects
.
project
)
models/
common_settings
.py
→
models/
main
.py
View file @
8294960b
# -*- 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
plugin_dbui
as
dbui
from
gluon
import
current
from
model_core
import
Core
from
model_selector
import
Selector
from
plugin_dbui
import
configure_forms
,
configure_grids
,
Dbui
from
ui_core
import
CoreUI
from
ui_selector
import
SelectorUI
from
ui_viewport
import
ViewportUi
# ............................................................................
#
# Connection to databases
#
db
=
DAL
(
'sqlite://storage.sqlite'
,
lazy_tables
=
False
,
migrate
=
True
)
virtdb
=
DAL
(
None
)
from
callbacks
import
country_delete
,
country_insert
,
country_update
from
datetime
import
datetime
from
gluon.tools
import
PluginManager
current
.
db
=
db
current
.
virtdb
=
virtdb
# ............................................................................
#
# Language
#
T
.
set_current_languages
(
"en"
,
"en-gb"
,
"en-us"
)
# mother tongue
T
.
force
(
"fr-fr"
)
# user language
T
.
lazy
=
True
# no
immediate translation
T
.
set_current_languages
(
"en"
,
"en-gb"
,
"en-us"
)
# mother tongue
T
.
force
(
"fr-fr"
)
# user language
T
.
lazy
=
True
#
immediate translation
# ............................................................................
#
# Configure plugin_dbui
#
plg_dbui
=
dbui
.
Dbui
plg_dbui
.
define_paths
(
Dbui
.
define_paths
(
app_about
=
"static/plugin_dbui/ABOUT.html"
,
# app_css=None,
app_db_schema
=
None
,
...
...
@@ -42,24 +68,22 @@ plg_dbui.define_paths(
# dbui_libmin="static/plugin_dbui/dbui-debug.js"
)
plg_dbui
.
initialise_ui
()
directSvc
=
plg_dbui
.
start_directSvc
()
# ............................................................................
#
# C
onstant
s
# C
reate the database model
s
#
undef
=
T
(
dbui
.
UNDEF
)
undef_id
=
dbui
.
UNDEF_ID
year
=
datetime
.
now
().
year
Core
.
define_tables
(
db
,
T
)
Selector
.
define_tables
(
virtdb
,
db
,
T
)
# ............................................................................
#
# Co
mmon configuration for forms and grids
# Co
nfigure the user interface
#
Dbui
.
initialise_ui
()
directSvc
=
Dbui
.
start_directSvc
()
# Common configuration for forms and grids
tables
=
[
"categories"
,
"collaborations"
,
"countries"
,
...
...
@@ -71,10 +95,15 @@ tables = ["categories",
"reports"
,
"teams"
]
dbui
.
configure_forms
(
tables
,
plugins
=
[
"pFormToolTip"
],
width
=
300
)
configure_forms
(
tables
,
plugins
=
[
"pFormToolTip"
],
width
=
300
)
configure_grids
(
tables
,
plugins
=
[
"pGridRowEditorConfirmDelete"
,
"pGridRowEditorContextMenu"
,
"pGridRowEditorDblClick"
,
"pGridToolbar"
])
dbui
.
configure_grids
(
tables
,
plugins
=
[
"pGridRowEditorConfirmDelete"
,
"pGridRowEditorContextMenu"
,
"pGridRowEditorDblClick"
,
"pGridToolbar"
])
CoreUI
.
configure
(
db
,
T
)
SelectorUI
.
configure
(
virtdb
,
db
,
T
)
ViewportUi
.
configure
(
virtdb
,
db
,
T
)
models/ui_categories.py
deleted
100644 → 0
View file @
c6e4938d
# -*- coding: utf-8 -*-
""" categories widgets
"""
#-------------------------------------------------------------------------------
#
# FIELDS CONFIGURATiON
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# FORM CONFIGURATiON
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# GRID CONFIGURATiON
#
#-------------------------------------------------------------------------------
gridModifier
=
dbui
.
GridModifier
(
'categories'
)
gridModifier
.
configure
(
plugins
=
[
'pGridPaging'
,
'pMathJax'
])
gridModifier
.
configure_column
(
'code'
,
width
=
10
)
gridModifier
.
set_rownumbering
(
True
)
gridModifier
.
append_filter
((
'code'
,
'contains'
,
T
(
'bla bla...'
)))
gridModifier
.
configure_filters
(
plugins
=
[
'pFormToolTip'
],
width
=
300
)
gridModifier
.
configure_gridWithFilter
(
selectorTitle
=
'MyFoo'
)
#
# Example of buffered rendering
# In that case the full store is loaded but only few row are rendered in the grid
#
# plugin = dict(ptype='bufferedrenderer',
# leadingBufferZone=0,
# trailingBufferZone=0)
# gridModifier.append_plugins(plugin)
#-------------------------------------------------------------------------------
#
# STORE CONFIGURATiON
#
#-------------------------------------------------------------------------------
# example of buffered store
#
# storeModifier = dbui.StoreModifier('categories')
# storeModifier.set_buffered()
models/ui_collaborations.py
deleted
100644 → 0
View file @
c6e4938d
# -*- coding: utf-8 -*-
""" Collaborations widgets
"""
#-------------------------------------------------------------------------------
#
# FIELDS CONFIGURATiON
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# FORM CONFIGURATiON
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# GRID CONFIGURATiON
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# STORE CONFIGURATiON
#
#-------------------------------------------------------------------------------
models/ui_countries.py
deleted
100644 → 0
View file @
c6e4938d
# -*- coding: utf-8 -*-
""" countries widgets
"""
#-------------------------------------------------------------------------------
#
# FIELDS CONFIGURATiON
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# FORM CONFIGURATiON
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# GRID CONFIGURATiON
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# STORE CONFIGURATiON
#
#-------------------------------------------------------------------------------
models/ui_harvesters.py
deleted
100644 → 0
View file @
c6e4938d
# -*- coding: utf-8 -*-
""" harvesters widgets
"""
#-------------------------------------------------------------------------------
#
# FIELDS CONFIGURATiON
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# FORM CONFIGURATiON
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# GRID CONFIGURATiON
#
#-------------------------------------------------------------------------------
gridModifier
=
dbui
.
GridModifier
(
'harvesters'
)
gridModifier
.
append_filter
((
'id_teams'
,
'=='
,
T
(
'is equal to'
)))
# gridModifier.append_filter(('id_projects', '==', T('is equal to')))
gridModifier
.
append_filter
((
'controller'
,
'contains'
,
T
(
'contains'
)))
# gridModifier.append_filter(('host', 'contains', T('contains')))
# gridModifier.append_filter(('id_categories', '==', T('is equal to')))
gridModifier
.
configure_filters
(
plugins
=
[
'pFormToolTip'
],
width
=
300
)
gridModifier
.
configure_gridWithFilter
(
selectorTitle
=
'Filter'
)
#-------------------------------------------------------------------------------
#
# STORE CONFIGURATiON
#
#-------------------------------------------------------------------------------
models/ui_new_fields.py
deleted
100644 → 0
View file @
c6e4938d
# -*- coding: utf-8 -*-
""" new_fields widgets
"""
#-------------------------------------------------------------------------------
#
# FIELDS CONFIGURATiON
#
#-------------------------------------------------------------------------------
fieldsModifier
=
dbui
.
FieldsModifier
(
'new_fields'
)
fieldsModifier
.
configure_field
(
'dictionary'
,
headers
=
[
'foo'
,
'faa'
],
modifyKeys
=
True
,
value
=
{
"string"
:
"test"
,
"boolean"
:
False
,
"integer"
:
0
,
"float"
:
0.01
,
"date"
:
"not implemented"
})
fieldsModifier
.
configure_field
(
'python_code'
,
xtype
=
'xaceeditorfield'
)
#-------------------------------------------------------------------------------
#
# FORM CONFIGURATiON
#
#-------------------------------------------------------------------------------
formModifier
=
dbui
.
FormModifier
(
'new_fields'
)
formModifier
.
configure
(
width
=
400
)
#-------------------------------------------------------------------------------
#
# GRID CONFIGURATiON
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# STORE CONFIGURATiON
#
#-------------------------------------------------------------------------------
models/ui_projects.py
deleted
100644 → 0
View file @
c6e4938d
# -*- coding: utf-8 -*-
""" projects widgets
"""
#-------------------------------------------------------------------------------
#
# FIELDS CONFIGURATiON
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# FORM CONFIGURATiON
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# GRID CONFIGURATiON
#
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
#
# STORE CONFIGURATiON
#
#-------------------------------------------------------------------------------
models/ui_publications.py
deleted
100644 → 0
View file @
c6e4938d
# -*- coding: utf-8 -*-
""" publications widgets
"""
#-------------------------------------------------------------------------------
#
# FIELDS CONFIGURATiON
#
#-------------------------------------------------------------------------------
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
)
fieldsModifier
.
merge_fields
(
'first_page'
,
'last_page'
,
fieldLabel
=
T
(
'Pages'
))
fieldsModifier
.
merge_fields
(
'conference_start'
,
'conference_end'
,
fieldLabel
=
T
(
'Dates'
))
#-------------------------------------------------------------------------------
#
# FORM CONFIGURATiON
#
#-------------------------------------------------------------------------------
formModifier
=
dbui
.
FormModifier
(
'publications'
)
formModifier
.
merge_fields
(
'title'
,
'authors'
,
'id_collaborations'
,
'id_publishers'
,
'year'
,
'doi'
,
'volume'
,
'first_page'
,
'e_print'
,
title
=
T
(
'General'
))
formModifier
.
merge_fields
(
'conference_title'
,
'conference_url'
,
'conference_start'
,
'conference_town'
,
'id_countries'
,
'conference_speaker'
,
title
=
T
(
'Conference'
))
formModifier
.
merge_fields
(
'report_numbers'
,
'id_reports'
,
title
=
T
(
'Report'
))
formModifier
.
merge_fields
(
'authors_cppm'
,
'id_teams'
,