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

Add the callback INHIBIT_CONTROLLER_INSERT and UPDATE.

parent 62647eea
......@@ -629,6 +629,7 @@
'Temps': 'Temps',
'The "query" is a condition like "db.table1.field1==\'value\'". Something like "db.table1.field1==db.table2.field2" results in a SQL JOIN.': 'The "query" is a condition like "db.table1.field1==\'value\'". Something like "db.table1.field1==db.table2.field2" results in a SQL JOIN.',
'The <i>record id</i> is not well formed.': 'Le <i>record id</i> est mal formé.',
'The category is used twice !': 'La catégorie est utilisée deux fois !',
'The field "%s" is missing ...': 'Le champ "%s" est manquant ...',
'The graph can be rendered as line or stacked chart. The latter is used when the stacked fields are defined. ': 'The graph can be rendered as line or stacked chart. The latter is used when the stacked fields are defined. ',
'The identifier of the record in the invenio store': 'The identifier of the record in the invenio store',
......@@ -638,6 +639,7 @@
'The name of the speaker: P.-Y. Smith': "Nom de l'orateur : P.-Y. Smith",
'The name of the web2py controller running the search: articles, proceedings,...': 'Nom du controller web2py qui effectut la recherche : articles, proceedings,...',
'The name of the web2py controller to run a search: articles, proceedings,...': 'The name of the web2py controller to run a search: articles, proceedings,...',
'The pair (harvester, category) already exists !': 'La paire (moissonneur, catégorie) existe déjà !',
'The project is undefined': "Le projet n'est pas défini",
'The record was validated. It can not be modified or deleted.': "L'enregistrement a été validé. Il ne peut plus être modifié ou détruit.",
'The status is ???': 'Le status est "???"',
......
......@@ -9,6 +9,8 @@ import locale
import plugin_dbui as dbui
from callbacks import (INHIBIT_CASCADE_DELETE,
INHIBIT_CONTROLLER_INSERT,
INHIBIT_CONTROLLER_UPDATE,
INHIBIT_DUPLICATE_PUBLICATION,
INHIBIT_HARVESTER_ON_CATEGORY,
INHIBIT_PUBLICATION_DELETE_ON_OK,
......
# -*- coding: utf-8 -*-
""" controllers
The table my_authors, controllers and harvesters are used
The table my_authors, controllers and harvesters are used
by the harvesters tool.
It define the relation between harvester controllers and
It define the relation between harvester controllers and
publication categories.
"""
......@@ -19,12 +19,16 @@ db.define_table("controllers",
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:
# 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)
\ No newline at end of file
db.controllers.controller.requires = IS_IN_SET(CONTROLLERS)
......@@ -60,6 +60,66 @@ def INHIBIT_CASCADE_DELETE(set_records):
return False
def INHIBIT_CONTROLLER_INSERT(values):
"""Inhibit the insert of duplicate controller.
The pair controller, category is unique
The category is used only once.
Args:
values (dict): data passed to insert.
Returns:
bool: ``True`` when the insert is inhibited
"""
db, T = current.globalenv['db'], current.T
# check the pair
if 'id' in values:
del values['id']
id_rec = get_id(db.controllers, **values)
if id_rec is not None:
db.controllers[CALLBACK_ERRORS] = [
T("Can't insert the harvester."),
T("The pair (harvester, category) already exists !")]
return True
# check the category
id_rec = get_id(db.controllers,
id_categories=values['id_categories'])
if id_rec is None:
return False
db.controllers[CALLBACK_ERRORS] = [
T("Can't insert the harvester."),
T("The category is used twice !")]
return True
def INHIBIT_CONTROLLER_UPDATE(setrow, values):
"""Inhibit the controller on update against identical pair.
A pair is defined by a controller and a category.
Args:
setrow (gluon.dal.Set): set object used for update.
values (dict): the dict of fields passed to update.
Returns:
bool: ``True`` when the update is inhibited.
"""
data = setrow.select().first().as_dict()
data.update(values)
return INHIBIT_CONTROLLER_INSERT(data)
def INHIBIT_DUPLICATE_PUBLICATION(publication):
"""Inhibit the insert operation when the publication already exists.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment