Commit f236d898 authored by Georgios Dagkakis's avatar Georgios Dagkakis

Revert "products and several BTs: Use constructUrlFor for some url calculations"

This reverts commit 45bb448f.

Since it caused a regression in saving portal_components.
To be re-thought and re-implemented
parent 2f23ba9a
...@@ -60,6 +60,4 @@ if document.getValidationState() not in validation_state: ...@@ -60,6 +60,4 @@ if document.getValidationState() not in validation_state:
web_section = context.getWebSectionValue() web_section = context.getWebSectionValue()
if web_section is None: if web_section is None:
web_section = context web_section = context
return web_section.constructUrlFor( return "%s/%s" % (web_section.absolute_url(), reference)
document_reference=reference
)
...@@ -10,9 +10,8 @@ ...@@ -10,9 +10,8 @@
came_from_valid python: not came_from or url_topmost_document.isURLAncestorOf(came_from);"> came_from_valid python: not came_from or url_topmost_document.isURLAncestorOf(came_from);">
<tal:block tal:condition="isAnon"> <tal:block tal:condition="isAnon">
<tal:block tal:define="dummy python: response.expireCookie('__ac', path='/'); <tal:block tal:define="dummy python: response.expireCookie('__ac', path='/');
parameter_dict python: {'portal_status_message': here.Base_translateString('Login and/or password is incorrect.')}; url python: '%s/login_form?portal_status_message=%s' % (here.absolute_url(), here.Base_translateString('Login and/or password is incorrect.'));
parameter_dict python: parameter_dict.update({'came_from': came_from}) if came_from else parameter_dict; url python: came_from and '%s&amp;came_from=%s' % (url, came_from) or url;
url python: here.constructUrlFor(form_id='login_form', parameter_dict=parameter_dict);
dummy python: response.redirect(url);" /> dummy python: response.redirect(url);" />
</tal:block> </tal:block>
<tal:block tal:condition="not: isAnon"> <tal:block tal:condition="not: isAnon">
...@@ -20,8 +19,8 @@ ...@@ -20,8 +19,8 @@
<tal:block tal:define="dummy python: response.redirect(came_from or here.getPermanentURL(here));" /> <tal:block tal:define="dummy python: response.redirect(came_from or here.getPermanentURL(here));" />
</tal:block> </tal:block>
<tal:block tal:condition="not: came_from_valid"> <tal:block tal:condition="not: came_from_valid">
<tal:block tal:define="dummy python: response.redirect(url_topmost_document.constructUrlFor(parameter_dict={'portal_status_message': here.Base_translateString('Redirection to an external site prevented.')}))" /> <tal:block tal:define="dummy python: response.redirect('%s?portal_status_message=%s' % (url_topmost_document.absolute_url(), here.Base_translateString('Redirection to an external site prevented.')));" />
</tal:block> </tal:block>
</tal:block> </tal:block>
</tal:block> </tal:block>
</tal:block> </tal:block>
\ No newline at end of file
...@@ -4,6 +4,6 @@ ...@@ -4,6 +4,6 @@
""" """
if document.hasReference(): if document.hasReference():
file_name = document.Document_getStandardFileName() file_name = document.Document_getStandardFileName()
return context.constructUrlFor(document_reference=file_name) return "%s/%s" % (context.absolute_url(), file_name)
else: else:
return context.constructUrlFor(form_id='view' if view else None) return "%s%s" % (document.getAbsoluteUrl(),view and '/view' or '')
...@@ -15,17 +15,16 @@ default_language = web_section.getLayoutProperty("default_available_language", d ...@@ -15,17 +15,16 @@ default_language = web_section.getLayoutProperty("default_available_language", d
website_url_set = {} website_url_set = {}
#simplify code of Base_doLanguage, can't ues Base_doLanguage directly #simplify code of Base_doLanguage, can't ues Base_doLanguage directly
root_website_url = web_section.getOriginalDocument().constructUrlFor() root_website_url = web_section.getOriginalDocument().absolute_url()
website_url_pattern = r'^%s(?:%s)*(/|$)' % ( website_url_pattern = r'^%s(?:%s)*(/|$)' % (
re.escape(root_website_url), re.escape(root_website_url),
'|'.join('/' + re.escape(x) for x in available_language_set)) '|'.join('/' + re.escape(x) for x in available_language_set))
for language in available_language_set: for language in available_language_set:
web_section_url = web_section.constructUrlFor()
if language == default_language: if language == default_language:
website_url_set[language] = re.sub(website_url_pattern, r'%s/\1' % root_website_url, web_section_url) website_url_set[language] = re.sub(website_url_pattern, r'%s/\1' % root_website_url, web_section.absolute_url())
else: else:
website_url_set[language]= re.sub(website_url_pattern, r'%s/%s/\1' % (root_website_url, language), web_section_url) website_url_set[language]= re.sub(website_url_pattern, r'%s/%s/\1' % (root_website_url, language), web_section.absolute_url())
view_as_web_method = default_web_page.getTypeBasedMethod( view_as_web_method = default_web_page.getTypeBasedMethod(
"viewAsWeb", "viewAsWeb",
......
...@@ -192,11 +192,13 @@ if dialog_method != update_method and clean_kw.get('deferred_style', 0): ...@@ -192,11 +192,13 @@ if dialog_method != update_method and clean_kw.get('deferred_style', 0):
request.set('deferred_style_dialog_method', dialog_method) request.set('deferred_style_dialog_method', dialog_method)
dialog_method = 'Base_activateSimpleView' dialog_method = 'Base_activateSimpleView'
url_params_string = make_query(clean_kw)
# XXX: We always redirect in report mode to make sure portal_skin # XXX: We always redirect in report mode to make sure portal_skin
# parameter is taken into account by SkinTool. # parameter is taken into account by SkinTool.
# If url is too long, we do not redirect to avoid crash. # If url is too long, we do not redirect to avoid crash.
# XXX: 2000 is an arbitrary value resulted from trial and error. # XXX: 2000 is an arbitrary value resulted from trial and error.
if (not(can_redirect) or len(make_query(clean_kw)) > 2000): if (not(can_redirect) or len(url_params_string) > 2000):
if dialog_method != update_method: if dialog_method != update_method:
# When we are not executing the update action, we have to change the skin # When we are not executing the update action, we have to change the skin
# manually, # manually,
...@@ -224,11 +226,22 @@ if (not(can_redirect) or len(make_query(clean_kw)) > 2000): ...@@ -224,11 +226,22 @@ if (not(can_redirect) or len(make_query(clean_kw)) > 2000):
request.set('URL', '%s/%s' % (context.absolute_url(), dialog_method)) request.set('URL', '%s/%s' % (context.absolute_url(), dialog_method))
return dialog_form(**kw) return dialog_form(**kw)
redirect_url = context.constructUrlFor( if error_message != '':
form_id=dialog_method, redirect_url = '%s/%s?%s' % ( context.absolute_url()
parameter_dict={'portal_status_message': error_message} if error_message != '' \ , dialog_method
else clean_kw , 'portal_status_message=%s' % error_message
) )
elif url_params_string != '':
redirect_url = '%s/%s?%s' % ( context.absolute_url()
, dialog_method
, url_params_string
)
else:
redirect_url = '%s/%s' % ( context.absolute_url()
, dialog_method
)
return request.RESPONSE.redirect(redirect_url) return request.RESPONSE.redirect(redirect_url)
# vim: syntax=python # vim: syntax=python
...@@ -25,16 +25,9 @@ if dialog_id not in ('', None): ...@@ -25,16 +25,9 @@ if dialog_id not in ('', None):
# Prevent users who don't have rights to edit the object from # Prevent users who don't have rights to edit the object from
# editing it by calling the Base_edit script with correct # editing it by calling the Base_edit script with correct
# parameters directly. # parameters directly.
if not silent_mode and not request.AUTHENTICATED_USER.has_permission('Modify portal content', context) : if not silent_mode and not request.AUTHENTICATED_USER.has_permission('Modify portal content', context) :
redirect_url = context.constructUrlFor( msg = Base_translateString("You do not have the permissions to edit the object.")
form_id=form_id, redirect_url = '%s/%s?selection_index=%s&selection_name=%s&%s' % (context.absolute_url(), form_id, selection_index, selection_name, 'portal_status_message=%s' % msg)
parameter_dict={
'selection_index': selection_index,
'selection_name': selection_name,
'portal_status_message': Base_translateString("You do not have the permissions to edit the object.")
}
)
return request['RESPONSE'].redirect(redirect_url) return request['RESPONSE'].redirect(redirect_url)
# Get the form # Get the form
...@@ -76,7 +69,7 @@ def editListBox(listbox_field, listbox): ...@@ -76,7 +69,7 @@ def editListBox(listbox_field, listbox):
if hasattr(value, 'edit'): if hasattr(value, 'edit'):
encapsulated_editor_list.append(value) encapsulated_editor_list.append(value)
else: else:
if value == '': if value == '':
value = None value = None
cleaned_v[key] = value cleaned_v[key] = value
...@@ -239,7 +232,7 @@ try: ...@@ -239,7 +232,7 @@ try:
elif(field_meta_type == 'MatrixBox'): elif(field_meta_type == 'MatrixBox'):
editMatrixBox(field, request.get(field.id)) editMatrixBox(field, request.get(field.id))
# Return parsed values # Return parsed values
if silent_mode: return (kw, encapsulated_editor_list), 'edit' if silent_mode: return (kw, encapsulated_editor_list), 'edit'
# Maybe we should build a list of objects we need # Maybe we should build a list of objects we need
...@@ -255,6 +248,12 @@ if message_only: ...@@ -255,6 +248,12 @@ if message_only:
ignore_layout = int(ignore_layout) ignore_layout = int(ignore_layout)
editable_mode = int(editable_mode) editable_mode = int(editable_mode)
spp = context.getPhysicalPath()
spp =list(spp)
s_url = request["SERVER_URL"]
spp.insert(0,s_url)
#calculate direct the url instead of using absolute_url
new_url = '/'.join(spp)
# for web mode, we should use 'view' instead of passed form_id # for web mode, we should use 'view' instead of passed form_id
# after 'Save & View'. # after 'Save & View'.
...@@ -263,26 +262,26 @@ if context.REQUEST.get('is_web_mode', False) and \ ...@@ -263,26 +262,26 @@ if context.REQUEST.get('is_web_mode', False) and \
form_id = 'view' form_id = 'view'
if not selection_index: if not selection_index:
redirect_url = context.constructUrlFor( redirect_url = '%s/%s?ignore_layout:int=%s&editable_mode:int=%s&portal_status_message=%s' % (
form_id=form_id, context.absolute_url(),
parameter_dict={ form_id,
'ignore_layout': ignore_layout, ignore_layout,
'editable_mode': editable_mode, editable_mode,
'portal_status_message': message, message)
}
)
else: else:
redirect_url = context.constructUrlFor( redirect_url = '%s/%s?selection_index=%s&selection_name=%s&ignore_layout:int=%s&editable_mode=%s&portal_status_message=%s' % (
form_id=form_id, context.absolute_url(),
parameter_dict={ form_id,
'selection_index': selection_index, selection_index,
'selection_name': selection_name, selection_name,
'ignore_layout': ignore_layout, ignore_layout,
'editable_mode': editable_mode, editable_mode,
'portal_status_message': message, message)
}
)
result = request['RESPONSE'].redirect(redirect_url) result = request['RESPONSE'].redirect(redirect_url)
if silent_mode: return result, 'redirect' if silent_mode: return result, 'redirect'
return result return result
...@@ -9,7 +9,7 @@ if website is not None and website.isStaticLanguageSelection(): ...@@ -9,7 +9,7 @@ if website is not None and website.isStaticLanguageSelection():
# Web Mode # Web Mode
root_website = website.getOriginalDocument() root_website = website.getOriginalDocument()
default_language = root_website.getDefaultAvailableLanguage() default_language = root_website.getDefaultAvailableLanguage()
root_website_url = root_website.constructUrlFor() root_website_url = root_website.absolute_url()
website_url_pattern = r'^%s(?:%s)*(/|$)' % ( website_url_pattern = r'^%s(?:%s)*(/|$)' % (
re.escape(root_website_url), re.escape(root_website_url),
'|'.join('/' + re.escape(x) for x in root_website.getAvailableLanguageList())) '|'.join('/' + re.escape(x) for x in root_website.getAvailableLanguageList()))
...@@ -24,7 +24,7 @@ if website is not None and website.isStaticLanguageSelection(): ...@@ -24,7 +24,7 @@ if website is not None and website.isStaticLanguageSelection():
if select_language == default_language: if select_language == default_language:
redirect_url = root_website_url redirect_url = root_website_url
else: else:
redirect_url = root_website.constructUrlFor(document_reference=select_language) redirect_url = root_website_url + '/' + select_language
return context.REQUEST.RESPONSE.redirect(redirect_url) return context.REQUEST.RESPONSE.redirect(redirect_url)
else: else:
# ERP5 Mode # ERP5 Mode
......
...@@ -3,37 +3,30 @@ ...@@ -3,37 +3,30 @@
page from a script. It should probably be extended, reviewed and documented page from a script. It should probably be extended, reviewed and documented
so that less code is copied and pasted in dialog scripts. so that less code is copied and pasted in dialog scripts.
TODO: improve API and extensively document. ERP5Site_redirect may TODO: improve API and extensively document. ERP5Site_redirect may
be redundant. be redundant.
""" """
from ZTUtils import make_query # BBB: originally, form_id was the first positional argument
if not redirect_url or '/' not in redirect_url:
form_id = redirect_url or kw.pop('form_id', None)
redirect_url = context.absolute_url()
if form_id:
redirect_url += '/' + form_id
from ZTUtils import make_query
request = context.getPortalObject().REQUEST request = context.getPortalObject().REQUEST
request_form = request.form request_form = request.form
request_form.update(kw) request_form.update(kw)
request_form = context.ERP5Site_filterParameterList(request_form) request_form = context.ERP5Site_filterParameterList(request_form)
request_form.update(keep_items) request_form.update(keep_items)
parameter_dict = dict([(k, v) for k, v in request_form.items() if k and v is not None])
if not redirect_url or '/' not in redirect_url: parameters = make_query(dict([(k, v) for k, v in request_form.items() if k and v is not None]))
# Used when redirect_url is not given explicitely and we redirect to an ERP5 document if len(parameters):
# BBB: originally, form_id was the first positional argument if '?' in redirect_url:
form_id = redirect_url or kw.pop('form_id', None) separator = '&'
redirect_url = context.constructUrlFor( else:
form_id=form_id, separator = '?'
parameter_dict=parameter_dict, redirect_url = '%s%s%s' % (redirect_url, separator, parameters)
)
else:
# Used if redirect_url is given explicitely (e.g. if we redirect to external web page)
# so constructUrlFor is not usable,
# since we have no document to redirect using is as context.
parameters = make_query(parameter_dict)
if len(parameters):
if '?' in redirect_url:
separator = '&'
else:
separator = '?'
redirect_url = '%s%s%s' % (redirect_url, separator, parameters)
if abort_transaction: if abort_transaction:
from zExceptions import Redirect from zExceptions import Redirect
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
local_parameter_list local_parameter_list | python: {}; local_parameter_list local_parameter_list | python: {};
action_context python: portal.restrictedTraverse(request.get('object_path', '?'), here); action_context python: portal.restrictedTraverse(request.get('object_path', '?'), here);
global actions python: here.Base_filterDuplicateActions(portal.portal_actions.listFilteredActionsFor(action_context)); global actions python: here.Base_filterDuplicateActions(portal.portal_actions.listFilteredActionsFor(action_context));
global url python: here.constructUrlFor(); global url here/absolute_url;
global current_form_id python: local_parameter_list.get('dialog_id', local_parameter_list.get('form_id', 'view')); global current_form_id python: local_parameter_list.get('dialog_id', local_parameter_list.get('form_id', 'view'));
dummy python: request.set('current_form_id', current_form_id); dummy python: request.set('current_form_id', current_form_id);
global current_url python: '%s/%s' % (url, current_form_id); global current_url python: '%s/%s' % (url, current_form_id);
......
portal = context.getPortalObject() portal = context.getPortalObject()
if portal.portal_skins.updateSkinCookie(): if portal.portal_skins.updateSkinCookie():
portal.setupCurrentSkin() portal.setupCurrentSkin()
came_from = REQUEST.get("came_from") url = REQUEST.get("came_from")
if portal.portal_membership.isAnonymousUser(): if portal.portal_membership.isAnonymousUser():
RESPONSE.expireCookie("__ac", path="/") RESPONSE.expireCookie("__ac", path="/")
parameter_dict = {'portal_status_message': context.Base_translateString("Login and/or password is incorrect.")} url = "%s/login_form?portal_status_message=%s" % (
if came_from: context.absolute_url(),
parameter_dict['came_from'] = came_from context.Base_translateString("Login and/or password is incorrect.")
url = context.constructUrlFor( + ("&amp;came_from=" + url if url else ""))
form_id='login_form', elif not url:
parameter_dict=parameter_dict url = context.absolute_url()
)
elif came_from:
url = came_from
else:
url = context.constructUrlFor()
topmost_url_document = context.Base_getURLTopmostDocumentValue() topmost_url_document = context.Base_getURLTopmostDocumentValue()
if not topmost_url_document.isURLAncestorOf(url): if not topmost_url_document.isURLAncestorOf(url):
return context.ERP5Site_redirect(topmost_url_document.constructUrlFor(), return context.ERP5Site_redirect(topmost_url_document.absolute_url(),
keep_items={'portal_status_message': 'Redirection to an external site prevented.'}) keep_items={'portal_status_message': 'Redirection to an external site prevented.'})
return RESPONSE.redirect(url) return RESPONSE.redirect(url)
...@@ -506,7 +506,7 @@ class FolderMixIn(ExtensionClass.Base): ...@@ -506,7 +506,7 @@ class FolderMixIn(ExtensionClass.Base):
not access any document in given path, not access any document in given path,
hence it does not compute the inner acquisition path. hence it does not compute the inner acquisition path.
""" """
document_url = self.constructUrlFor() document_url = self.absolute_url()
parsed_given_url = urlparse(given_url) parsed_given_url = urlparse(given_url)
parsed_document_url = urlparse(document_url) parsed_document_url = urlparse(document_url)
# XXX note that the following check: # XXX note that the following check:
......
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