📣 An issue occured with the embedded container registry on October 25 2021, between 10:30 and 12:10 (UTC+2). Any persisting issues should be reported to CC-IN2P3 Support. 🐛

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

Redesign callbacks INHIBIT_DELETE_UNDEF as well as UPDATE.

parent e174c27d
......@@ -155,6 +155,6 @@
'Year': 'Année',
'Year End': 'Year End',
'Year Start': 'Year Start',
'You can not delete the row containing the undefined value.': 'Vous ne pouvez pas détruire la ligne contenant la value indéfini.',
'You can not update the row containing the undefined value.': 'Vous ne pouvez pas modifier la ligne contenant la value indéfini.',
'You can not delete the row containing the undefined value.': 'Vous ne pouvez pas détruire la ligne contenant la valuer indéfini.',
'You can not update the row containing the undefined value.': 'Vous ne pouvez pas modifier la ligne contenant la valuer indéfini.',
}
......@@ -6,6 +6,10 @@ from .dbsvc import CALLBACK_ERRORS
from gluon import current
MSG_DELETE = "You can not delete the row containing the undefined value."
MSG_UPDATE = "You can not update the row containing the undefined value."
def INHIBIT_DELETE_UNDEF(setrows):
"""Inhibit the delete of the record containing the undefined value.
......@@ -17,19 +21,15 @@ def INHIBIT_DELETE_UNDEF(setrows):
true when the record contains the undefined value.
"""
T = current.T
field = setrows.query.first
query = setrows.query
if query.op.__name__ == "eq":
# protection
# the query of the set should be "table.id == 1"
if field._db._adapter.EQ != setrows.query.op:
return False
field = query.first
# inhibit the delete
if field.name == "id" and setrows.query.second == UNDEF_ID:
field._table[CALLBACK_ERRORS] = \
T("You can not delete the row containing the undefined value.")
return True
if field.name == "id" and query.second == UNDEF_ID:
field._table[CALLBACK_ERRORS] = current.T(MSG_DELETE)
return True
return False
......@@ -48,18 +48,14 @@ def INHIBIT_UPDATE_UNDEF(setrows, values):
true when the record contains the undefined value.
"""
T = current.T
field = setrows.query.first
# protection
# the query of the set should be "table.id == 1"
if setrows.query.op != field._db._adapter.EQ:
return False
# inhibit the delete
if field.name == "id" and int(setrows.query.second) == UNDEF_ID:
field._table[CALLBACK_ERRORS] = \
T("You can not update the row containing the undefined value.")
return True
query = setrows.query
if query.op.__name__ == "eq":
field = query.first
if field.name == "id" and int(query.second) == UNDEF_ID:
field._table[CALLBACK_ERRORS] = current.T(MSG_UPDATE)
return True
return False
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