Commit 01310e93 authored by Jérome Perrin's avatar Jérome Perrin

Use "portal_status_level" in redirections

In ERP5JS when redirecting we can use `portal_status_level` to control the appearance of the notification.

This updates the cases when user action could not be performed to redirect with an error level, so that notification appears in orange, not in green (in ERP5JS - in erp5_xhtml_style this has no effect).

accounting, base, trade were updated

See merge request !1303
parents b3ad06f2 66499d9e
Pipeline #12037 passed with stage
in 0 seconds
......@@ -22,8 +22,11 @@ portal.portal_selections.setSelectionParamsFor('accounting_create_related_paymen
if len(object_list) >= 1000:
return context.Base_redirect(
form_id,
keep_items={'portal_status_message': translateString(
'Refusing to process more than 1000 objects, check your selection.')})
keep_items={
'portal_status_message': translateString(
'Refusing to process more than 1000 objects, check your selection.'),
'portal_status_level': 'error',
})
tag = 'payment_creation_%s' % random.randint(0, 1000)
activated = 0
......@@ -35,8 +38,10 @@ for obj in object_list:
return context.Base_redirect(
form_id,
abort_transaction=True,
keep_items={'portal_status_message': translateString(
'Payment creation already in progress, abandon.')})
keep_items={
'portal_status_message': translateString('Payment creation already in progress, abandon.'),
'portal_status_level': 'error',
})
obj.activate(tag=tag).Invoice_createRelatedPaymentTransaction(
node=node,
payment_mode=payment_mode,
......@@ -47,8 +52,10 @@ for obj in object_list:
if not activated:
return context.Base_redirect(
form_id,
keep_items={'portal_status_message': translateString(
'No invoice in your selection.')})
keep_items={
'portal_status_message': translateString( 'No invoice in your selection.'),
'portal_status_level': 'error',
})
# activate something on the folder
context.activate(after_tag=tag).getTitle()
......
......@@ -13,9 +13,10 @@ else:
# XXX prevent to call this on the whole module:
if len(object_list) >= 1000:
return context.Base_redirect(form_id,
keep_items=dict(portal_status_message=
translateString(
'Refusing to process more than 1000 objects, check your selection.')))
keep_items=dict(
portal_status_message=translateString('Refusing to process more than 1000 objects, check your selection.'),
portal_status_level='error',
))
tag = 'reversal_creation_%s' % random.randint(0, 1000)
activated = 0
......@@ -36,9 +37,12 @@ for obj in object_list:
activated += 1
if not activated:
return context.Base_redirect(form_id,
keep_items=dict(portal_status_message=
translateString('No valid transaction in your selection.')))
return context.Base_redirect(
form_id,
keep_items=dict(
portal_status_message=translateString('No valid transaction in your selection.'),
portal_status_level='error',
))
# activate something on the folder
context.activate(after_tag=tag).getTitle()
......
......@@ -18,9 +18,12 @@ for line in line_list:
# redirect to previous page without doing the conversion
if exchange_rate is None:
return context.Base_redirect(form_id,
return context.Base_redirect(
form_id,
keep_items=dict(
portal_status_message=context.Base_translateString('No exchange ratio found.')))
portal_status_message=context.Base_translateString('No exchange ratio found.'),
portal_status_level='error',
))
# update the corresponding price and round it according to the precision of
# the converted currency
......
......@@ -20,10 +20,12 @@ for line in line_list:
start_date=line.getStartDate()))
# redirect to previous page without doing the conversion
if exchange_rate is None:
return context.Base_redirect(form_id,
return context.Base_redirect(
form_id,
keep_items=dict(
portal_status_message=context.Base_translateString('No exchange ratio found.')))
portal_status_message=context.Base_translateString('No exchange ratio found.'),
portal_status_level='error',
))
# update the corresponding price and round it according to the precision of
# the converted currency
......
......@@ -37,7 +37,10 @@ if sum(total_payable_price_details.values()) == 0:
if not batch_mode:
return context.Base_redirect(
form_id,
keep_items={'portal_status_message': Base_translateString('Nothing more to pay.')})
keep_items={
'portal_status_message': Base_translateString('Nothing more to pay.'),
'portal_status_level': 'error'
})
return None
related_payment = portal.accounting_module.newContent(
......
......@@ -19,4 +19,5 @@ return context.Base_redirect(form_id,
keep_items=dict(selection_name=selection_name,
selection_index=selection_index,
cancel_url=cancel_url,
portal_status_message=translateString("Cancelled.")),)
portal_status_message=translateString("Cancelled."),
portal_status_level='error'),)
......@@ -3,7 +3,10 @@ ptype = context.getPortalType()
if not description:
return context.Base_redirect(dialog_id,
keep_items = dict(portal_status_message = translateString("Question can not be empty.",), cancel_url = cancel_url))
keep_items = dict(
portal_status_message=translateString("Question can not be empty.",),
portal_status_level='error',
cancel_url=cancel_url))
query = context.Base_newQuery(description=description)
query_id = query.getId()
......
......@@ -13,7 +13,10 @@ if default_career is None:
return context.Base_redirect(form_id=form_id,
selection_name=selection_name,
selection_index=selection_index,
keep_items={'portal_status_message': message})
keep_items={
'portal_status_message': message,
'portal_status_level': 'error',
})
else:
# Copy and paste the default career.
# Change IDs
......@@ -25,8 +28,10 @@ else:
return context.Base_redirect(form_id=form_id,
selection_name=selection_name,
selection_index=selection_index,
keep_items={'portal_status_message': message})
keep_items={
'portal_status_message': message,
'portal_status_level': 'error',
})
new_start_date = default_career.getStopDate()
cb_data = person.manage_copyObjects(ids=(new_id,))
......
......@@ -14,4 +14,4 @@ else:
context.portal_caches.clearCache(('erp5_content_short',))
context.logout()
return context.Base_redirect()
return context.Base_redirect(dialog_id, keep_items={'portal_status_message': msg})
return context.Base_redirect(dialog_id, keep_items={'portal_status_message': msg, 'portal_status_level': 'error'})
......@@ -28,16 +28,22 @@ elif line_portal_type in portal.getPortalInternalTypeList() + portal.getPortalIn
else:
from Products.ERP5Type.Message import translateString
return context.Base_redirect('view', keep_items=dict(
portal_status_message=translateString('Type of document not known to retrieve section.')))
portal_status_message=translateString('Type of document not known to retrieve section.'),
portal_status_level='error',
))
if len(use_list) == 0:
from Products.ERP5Type.Message import translateString
return context.Base_redirect('view', keep_items=dict(
portal_status_message=translateString('Use preference must be defined.')))
portal_status_message=translateString('Use preference must be defined.'),
portal_status_level='error',
))
if section_uid is None:
from Products.ERP5Type.Message import translateString
return context.Base_redirect('view', keep_items=dict(
portal_status_message=translateString('Section must be defined.')))
portal_status_message=translateString('Section must be defined.'),
portal_status_level='error',
))
return context.Base_renderForm('Delivery_viewDeliveryFastInputDialog', *args, **kw)
......@@ -64,8 +64,10 @@ while count > 0 and len(trade_condition_list) == 0:
tested_base_category_list=tested_base_category_list[:count],
sort_method=sort_method)
if len(trade_condition_list ) == 0:
message = Base_translateString('No trade condition.')
keep_items = {}
if len(trade_condition_list ) == 0 :
keep_items['portal_status_message'] = Base_translateString('No trade condition.')
keep_items['portal_status_level'] = 'error'
else :
# if more than one trade condition is found, simply apply the first one
trade_condition=trade_condition_list[0].getObject()
......@@ -75,8 +77,7 @@ else :
if hasattr(order, 'getReceivedDate') and order.getReceivedDate() is None:
context.setReceivedDate(DateTime())
message = Base_translateString('Order updated.')
keep_items['portal_status_message'] = Base_translateString('Order updated.')
if not batch_mode:
return context.Base_redirect(form_id,
keep_items=dict(portal_status_message=message))
return context.Base_redirect(form_id, keep_items=keep_items)
......@@ -120,7 +120,10 @@ if error is None:
if error is not None:
previous_skin_selection = container.REQUEST.get('previous_skin_selection', None)
context.getPortalObject().changeSkin(previous_skin_selection)
return context.Base_redirect('view', keep_items={'portal_status_message': context.Base_translateString(error, mapping=error_kw)})
return context.Base_redirect('view', keep_items={
'portal_status_message': context.Base_translateString(error, mapping=error_kw),
'portal_status_level': 'error',
})
# Add a line for unit titles
for source_trade in source_trade_dict:
......
......@@ -55,16 +55,18 @@ while count > 0 and len(trade_condition_list) == 0:
tested_base_category_list=tested_base_category_list[:count],
sort_method=sort_method)
keep_items = {}
if len(trade_condition_list ) == 0 :
message = Base_translateString('No trade condition.')
keep_items['portal_status_message'] = Base_translateString('No trade condition.')
keep_items['portal_status_level'] = 'error'
else :
# if more than one trade condition is found, simply apply the first one
trade_condition=trade_condition_list[0].getObject()
order.Order_applyTradeCondition(trade_condition, force=force)
message = Base_translateString('Order updated.')
keep_items['portal_status_message'] = Base_translateString('Order updated.')
if not batch_mode:
return context.Base_redirect(form_id,
keep_items=dict(portal_status_message=message))
return context.Base_redirect(form_id, keep_items=keep_items)
......@@ -55,8 +55,10 @@ while count > 0 and len(trade_condition_list) == 0:
tested_base_category_list=tested_base_category_list[:count],
sort_method=sort_method)
if len(trade_condition_list ) == 0:
message = Base_translateString('No trade condition.')
keep_items = {}
if len(trade_condition_list ) == 0 :
keep_items['portal_status_message'] = Base_translateString('No trade condition.')
keep_items['portal_status_level'] = 'error'
else :
# if more than one trade condition is found, simply apply the first one
trade_condition=trade_condition_list[0].getObject()
......@@ -66,8 +68,7 @@ else :
if hasattr(order, 'getReceivedDate') and order.getReceivedDate() is None:
context.setReceivedDate(DateTime())
message = Base_translateString('Order updated.')
keep_items['portal_status_message'] = Base_translateString('Order updated.')
if not batch_mode:
return context.Base_redirect(form_id,
keep_items=dict(portal_status_message=message))
return context.Base_redirect(form_id, keep_items=keep_items)
......@@ -34,6 +34,7 @@ import mock
import itertools
import transaction
import unittest
import urlparse
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.utils import createZODBPythonScript
from AccessControl.SecurityManagement import newSecurityManager
......@@ -584,7 +585,13 @@ class TestPreferences(UserManagementTestCase):
current_password='bad' + password,
new_password=new_password,
)
self.assertEqual(result, self.portal.absolute_url()+'/portal_preferences/PreferenceTool_viewChangePasswordDialog?portal_status_message=Current%20password%20is%20wrong.')
parsed_url = urlparse.urlparse(result)
self.assertEqual(
parsed_url.path.split('/')[-2:],
['portal_preferences', 'PreferenceTool_viewChangePasswordDialog'])
self.assertEqual(
urlparse.parse_qs(parsed_url.query),
{'portal_status_message': ['Current password is wrong.'], 'portal_status_level': ['error']})
self.login()
self._assertUserExists(login, password)
......
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