Commit 70efe6b2 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add the callback modules

Inhibit delete/update a publication when it is marked OK
Inhibit insert when a publication already exist.
Define default value for all string fields.
parent ae7b0168
......@@ -3,7 +3,15 @@
'"update" is an optional expression like "field1=\'newvalue\'". You cannot update or delete the results of a JOIN': '"update" is an optional expression like "field1=\'newvalue\'". You cannot update or delete the results of a JOIN',
'%Y-%m-%d': '%Y-%m-%d',
'%Y-%m-%d %H:%M:%S': '%Y-%m-%d %H:%M:%S',
'• or publisher and title.': '– ou revue et titre.',
'• or publisher, volume and pages': '– or revue, volume et pages',
'• or title, conference date and town': '– ou titre, date et ville de la conférence',
'• or title, conference title and town': '– ou titre ainsi que le titre et ville de la conférence',
'• title, conference title, date and town': '– titre ainsi que le titre, la ville et la date de la conférence',
'• title, publisher, volume and pages': '– titre, revue, volume et pages',
"'et al.' in authors": "'et al.' dans les authors",
'A report already exists with the same title': 'Un rapport existe deja avec le même titre',
'A talk/proceeding already exists with the same:': 'Un acte ou une présentation existe déja avec le même:',
'Abbreviation': 'Abréviation',
'about': 'à propos',
'ACL': 'ACL',
......@@ -16,6 +24,7 @@
'Agencies': 'Agencies',
'All fields of the form have to be defined !!!': 'Tous les champs doivent ếtre définis !!!',
'Already in the database': 'Publication déjà enregistré dans la base de donnée',
'An article already exists with the same:': 'Un article existe déja avec le même:',
'AP': 'AP',
'Are you sure you want to delete this object?': 'Voulez-vous vraiment détruire cet object ?',
'Articles': 'Articles',
......@@ -53,6 +62,11 @@
'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)': '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)',
"can be applied on any field of the table using the where syntax. don't work with the foreign table (see smart_query in the web2py)": "can be applied on any field of the table using the where syntax. don't work with the foreign table (see smart_query in the web2py)",
"Can't access the MySQL database !!!": "La base de données MySQL n'est pas accesible !!!",
"Can't delete a publication marked OK.": "Impossible de détruire une publication marquée OK.",
"Can't insert the article.": 'Impossible de créer cet article.',
"Can't insert the report.": 'Impossible de créer ce rapport.',
"Can't insert the talk/proceeding.": 'Impossible de créer cet acte ou présentation.',
"Can't updated a publication marked OK.": "Impossible d'actualiser une publication marquée OK.",
'Cannot be empty': 'Cannot be empty',
'CAS': 'CAS',
'categories': 'catégories',
......@@ -339,6 +353,7 @@
'Section': 'Section',
'Sections': 'Sections',
'sections': 'sections',
'See publication id(s) %s': "Voire la(les) publication(s) avec l'id(s) %s",
'Select': 'Sélectionner',
'Select a "category" !!!': 'Sélectionner une "catégorie" !!!',
'Select a "project" !!!': 'Sélectionner un "projet" !!!',
......
......@@ -10,6 +10,7 @@ import plugin_dbui as dbui
from callbacks import (INHIBIT_PUBLICATION_DELETE_ON_OK,
INHIBIT_DUPLICATE_PUBLICATION,
INHIBIT_PUBLICATION_UPDATE_ON_OK)
from datetime import datetime
from gluon.tools import PluginManager
......@@ -200,6 +201,7 @@ db.define_table("publications",
migrate="publications.table")
db.publications._before_delete.append(INHIBIT_PUBLICATION_DELETE_ON_OK)
db.publications._before_insert.append(INHIBIT_DUPLICATE_PUBLICATION)
db.publications._before_update.append(INHIBIT_PUBLICATION_UPDATE_ON_OK)
db.publications.conference_title.filter_in = dbui.CLEAN_SPACES
......
"""a collections of functions to be used in _before_delete, before_insert
and _before_update callbacks.
@author: R. Le Gac
"""
from check_tools import (duplicate_article,
duplicate_conference,
duplicate_report)
from gluon import current
from plugin_dbui import CALLBACK_ERRORS, get_id
def INHIBIT_DUPLICATE_PUBLICATION(publication):
"""Inhibit the insert operation when the publication already exists.
@type publication: dict
@param publication: publications fields passed to insert
@rtype: bool
@return: C{True} when the insert is inhibited
"""
db, T = current.globalenv['db'], current.T
id_category = publication['id_categories']
# articles
id_cats = (get_id(db.categories, code='ACL'),
get_id(db.categories, code='ACLN'))
if id_category in id_cats:
ids = duplicate_article(publication)
if ids:
db.publications[CALLBACK_ERRORS] = [
T("Can't insert the article."),
T("An article already exists with the same:"),
T("• title, publisher, volume and pages"),
T("• or publisher, volume and pages"),
T("• or publisher and title."),
T("See publication id(s) %s") % ', '.join(ids)]
return True
# talks and proceedings
id_cats = (get_id(db.categories, code='ACTI'),
get_id(db.categories, code='ACTN'),
get_id(db.categories, code='COM'))
if id_category in id_cats:
ids = duplicate_conference(publication)
if ids:
db.publications[CALLBACK_ERRORS] = [
T("Can't insert the talk/proceeding."),
T("A talk/proceeding already exists with the same:"),
T("• title, conference title, date and town"),
T("• or title, conference date and town"),
T("• or title, conference title and town"),
T("See publication id(s) %s") % ', '.join(ids)]
return True
# reports
id_cats = (get_id(db.categories, code='AP'),)
if id_category in id_cats:
ids = duplicate_report(publication)
if ids:
db.publications[CALLBACK_ERRORS] = [
T("Can't insert the report."),
T("A report already exists with the same title"),
T("See publication id(s) %s") % ', '.join(ids)]
return True
return False
def INHIBIT_PUBLICATION_DELETE_ON_OK(s):
"""Inhibit the delete operation when the status of the publication is OK.
@type s: gluon.dal.Set
@param s: Set object used for delete.
@rtype: bool
@return: C{True} when the delete is inhibited
"""
db, T = current.globalenv['db'], current.T
id_ok = get_id(db.status, code='OK')
# also call in cascade delete (teams, ...)
# in normal case the query is "publications.id = 567"
# in cascade delete the query is "publications.id_teams IN (21)"
if s.query.first is db.publications.id:
id = s.query.second
if db.publications[id].id_status == id_ok:
db.publications[CALLBACK_ERRORS] = \
T("Can't delete a publication marked OK.")
return True
return False
def INHIBIT_PUBLICATION_UPDATE_ON_OK(s, f):
"""Inhibit the update operation when the status of the publication is OK.
@type s: gluon.dal.Set
@param s: Set object used for update.
@type f: dict
@param f: the dict of publications fields passed to update
@rtype: bool
@return: C{True} when the update is inhibited
"""
db, T = current.globalenv['db'], current.T
id_ok = get_id(db.status, code='OK')
id = f["id"]
if db.publications[id].id_status == id_ok:
db.publications[CALLBACK_ERRORS] = \
T("Can't updated a publication marked OK.")
return True
return False
......@@ -2,12 +2,15 @@
HEAD
- Migrate to plugin_dbui 0.4.13.1
- Add the module check_tools.
- More stringent tests in the validation procedure
including duplicate entries.
- Add the module check_tools and callbacks
- More stringent tests in the "chack and validate" procedure
- Duplicate entries are reject on insert and look for during check.
- Can't delete or updata a publication marked OK
- Add the generic pdf converter to be used in view (view/tex2pdf.html).
- Pdf reports can be generated for "check and validate" and
"run harvester(s)" operations.
- Define default values for each fields of all tables.
- Add the action fix_nome in the toolbox.
0.8.2 (Apr 2013)
- Consolidation version.
......
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