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

Can't delete a reference field used by at least one publication.

parent 70efe6b2
......@@ -62,7 +62,8 @@
'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 delete a publication marked OK.": 'Impossible de détruire une publication marquée OK.',
"Can't delete this record since several publications refer to it.": "Impossible de détruire cet enregistrement car des publications lui font référence.",
"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.',
......@@ -364,6 +365,7 @@
'select...': 'sélectionner...',
'selected': 'sélectionnez',
'Service': 'Service',
'Several publications refer to it.': 'Several publications refer to it.',
'Sort by': 'Trier par',
'Sort field': 'Trier par',
'Sort Field': 'Trier par',
......
......@@ -9,8 +9,9 @@ import locale
import plugin_dbui as dbui
from callbacks import (INHIBIT_PUBLICATION_DELETE_ON_OK,
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
......@@ -57,12 +58,15 @@ db.define_table("authors_roles",
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
......@@ -70,12 +74,14 @@ 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",
......@@ -83,6 +89,7 @@ db.define_table("projects",
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",
......@@ -90,6 +97,7 @@ db.define_table("publishers",
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
......@@ -97,16 +105,21 @@ 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", "text", notnull=True),
migrate="status.table")
db.status._before_delete.append(INHIBIT_CASCADE_DELETE)
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
......
......@@ -8,7 +8,54 @@ from check_tools import (duplicate_article,
duplicate_conference,
duplicate_report)
from gluon import current
from plugin_dbui import CALLBACK_ERRORS, get_id
from plugin_dbui import (CALLBACK_ERRORS,
get_id,
get_where_query)
def INHIBIT_CASCADE_DELETE(set):
"""Inhibit the delete when publications use the reference field.
@type set: gluon.dal.Set
@param set:
@rtype: bool
@return:
"""
db, T = current.globalenv['db'], current.T
field = set.query.first
# protection
# the query of the set should be "table.id == 45"
if field._db._adapter.EQ != set.query.op:
return False
# protection
# check that the table is ones of the publication reference tables
tables = (db.authors_roles,
db.categories,
db.collaborations,
db.countries,
db.projects,
db.publishers,
db.reports,
db.status,
db.teams)
if field._table not in tables:
return False
# inhibit the delete if publications use the reference field
query = get_where_query(db.publications)
query = (query) & (set.query)
if db(query).count():
field._table[CALLBACK_ERRORS] = \
T("Can't delete this record since several publications refer to it.")
return True
return False
def INHIBIT_DUPLICATE_PUBLICATION(publication):
......
......@@ -5,11 +5,12 @@ HEAD
- 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
- Can't delete or updata a publication marked OK.
- Can't delete a reference field used by at least one publication.
- 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.
- Define default values for all string fields.
- Add the action fix_nome in the toolbox.
0.8.2 (Apr 2013)
......
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