Commit f601d7a5 authored by Georgios Dagkakis's avatar Georgios Dagkakis

products and several BTs: Fix calculations of urls when absolute_url

is called in Web Sections or Web Sites.

These expected that absolute_url returned no trailing slash,
so updates in code and page templates were needed
parent 8a9784bd
...@@ -60,4 +60,4 @@ if document.getValidationState() not in validation_state: ...@@ -60,4 +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 "%s/%s" % (web_section.absolute_url(), reference) return "%s%s" % (web_section.absolute_url(), reference)
...@@ -5,12 +5,16 @@ ...@@ -5,12 +5,16 @@
tal:define="dummy here/setupCurrentSkin;" /> tal:define="dummy here/setupCurrentSkin;" />
<tal:block tal:define="response request/RESPONSE; <tal:block tal:define="response request/RESPONSE;
came_from python: request.get('came_from') or request.get('field_came_from'); came_from python: request.get('came_from') or request.get('field_came_from');
absolute_url python: here.absolute_url();
absolute_url python: absolute_url[:-1] if absolute_url.endswith('/') else absolute_url;
isAnon here/portal_membership/isAnonymousUser | nothing; isAnon here/portal_membership/isAnonymousUser | nothing;
url_topmost_document python: here.Base_getURLTopmostDocumentValue(); url_topmost_document python: here.Base_getURLTopmostDocumentValue();
url_topmost_document_absolute_url python: url_topmost_document.absolute_url();
url_topmost_document_absolute_url python: url_topmost_document_absolute_url[:-1] if url_topmost_document_absolute_url.endswith('/') else url_topmost_document_absolute_url;
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='/');
url python: '%s/login_form?portal_status_message=%s' % (here.absolute_url(), here.Base_translateString('Login and/or password is incorrect.')); url python: '%s/login_form?portal_status_message=%s' % (absolute_url, here.Base_translateString('Login and/or password is incorrect.'));
url python: came_from and '%s&amp;came_from=%s' % (url, came_from) or url; url python: came_from and '%s&amp;came_from=%s' % (url, came_from) or url;
dummy python: response.redirect(url);" /> dummy python: response.redirect(url);" />
</tal:block> </tal:block>
...@@ -19,7 +23,7 @@ ...@@ -19,7 +23,7 @@
<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('%s?portal_status_message=%s' % (url_topmost_document.absolute_url(), 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>
......
...@@ -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 "%s/%s" % (context.absolute_url(), file_name) return "%s%s" % (context.absolute_url(), file_name)
else: else:
return "%s%s" % (document.getAbsoluteUrl(),view and '/view' or '') return "%s%s" % (document.getAbsoluteUrl(),view and '/view' or '')
...@@ -16,15 +16,18 @@ website_url_set = {} ...@@ -16,15 +16,18 @@ 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().absolute_url() root_website_url = web_section.getOriginalDocument().absolute_url()
root_website_url = root_website_url[:-1] if root_website_url.endswith('/') else root_website_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.absolute_url()
web_section_url = web_section_url[:-1] if web_section_url.endswith('/') else web_section_url
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.absolute_url()) website_url_set[language] = re.sub(website_url_pattern, r'%s/\1' % root_website_url, web_section_url)
else: else:
website_url_set[language]= re.sub(website_url_pattern, r'%s/%s/\1' % (root_website_url, language), web_section.absolute_url()) website_url_set[language]= re.sub(website_url_pattern, r'%s/%s/\1' % (root_website_url, language), web_section_url)
view_as_web_method = default_web_page.getTypeBasedMethod( view_as_web_method = default_web_page.getTypeBasedMethod(
"viewAsWeb", "viewAsWeb",
......
...@@ -25,9 +25,12 @@ if dialog_id not in ('', None): ...@@ -25,9 +25,12 @@ 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) :
msg = Base_translateString("You do not have the permissions to edit the object.") msg = Base_translateString("You do not have the permissions to edit the object.")
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) context_absolute_url = context.absolute_url()
context_absolute_url = context_absolute_url[:-1] if context_absolute_url.endswith('/') else context_absolute_url
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)
return request['RESPONSE'].redirect(redirect_url) return request['RESPONSE'].redirect(redirect_url)
# Get the form # Get the form
...@@ -69,7 +72,7 @@ def editListBox(listbox_field, listbox): ...@@ -69,7 +72,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
...@@ -232,7 +235,7 @@ try: ...@@ -232,7 +235,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
...@@ -248,12 +251,6 @@ if message_only: ...@@ -248,12 +251,6 @@ 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'.
...@@ -261,18 +258,20 @@ if context.REQUEST.get('is_web_mode', False) and \ ...@@ -261,18 +258,20 @@ if context.REQUEST.get('is_web_mode', False) and \
not editable_mode: not editable_mode:
form_id = 'view' form_id = 'view'
context_absolute_url = context.absolute_url()
context_absolute_url = context_absolute_url[:-1] if context_absolute_url.endswith('/') else context_absolute_url
if not selection_index: if not selection_index:
redirect_url = '%s/%s?ignore_layout:int=%s&editable_mode:int=%s&portal_status_message=%s' % ( redirect_url = '%s/%s?ignore_layout:int=%s&editable_mode:int=%s&portal_status_message=%s' % (
context.absolute_url(), context_absolute_url,
form_id, form_id,
ignore_layout, ignore_layout,
editable_mode, editable_mode,
message) message)
else: else:
redirect_url = '%s/%s?selection_index=%s&selection_name=%s&ignore_layout:int=%s&editable_mode=%s&portal_status_message=%s' % ( redirect_url = '%s/%s?selection_index=%s&selection_name=%s&ignore_layout:int=%s&editable_mode=%s&portal_status_message=%s' % (
context.absolute_url(), context_absolute_url,
form_id, form_id,
selection_index, selection_index,
selection_name, selection_name,
...@@ -280,8 +279,7 @@ else: ...@@ -280,8 +279,7 @@ else:
editable_mode, editable_mode,
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
...@@ -10,6 +10,7 @@ if website is not None and website.isStaticLanguageSelection(): ...@@ -10,6 +10,7 @@ if website is not None and website.isStaticLanguageSelection():
root_website = website.getOriginalDocument() root_website = website.getOriginalDocument()
default_language = root_website.getDefaultAvailableLanguage() default_language = root_website.getDefaultAvailableLanguage()
root_website_url = root_website.absolute_url() root_website_url = root_website.absolute_url()
root_website_url = root_website_url[:-1] if root_website_url.endswith('/') else root_website_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()))
...@@ -22,9 +23,9 @@ if website is not None and website.isStaticLanguageSelection(): ...@@ -22,9 +23,9 @@ if website is not None and website.isStaticLanguageSelection():
referer_url) referer_url)
else: else:
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_url + '/' + 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
......
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
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 here/absolute_url; absolute_url here/absolute_url;
global url python: absolute_url[:-1] if absolute_url.endswith('/') else 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);
...@@ -87,4 +88,4 @@ ...@@ -87,4 +88,4 @@
<tal:block metal:define-macro="http_definitions"> <tal:block metal:define-macro="http_definitions">
<tal:block tal:replace="structure python: modules['ZTUtils'].make_hidden_input(**http_parameter_list)" /> <tal:block tal:replace="structure python: modules['ZTUtils'].make_hidden_input(**http_parameter_list)" />
</tal:block> </tal:block>
</tal:block> </tal:block>
\ No newline at end of file
...@@ -4,8 +4,10 @@ if portal.portal_skins.updateSkinCookie(): ...@@ -4,8 +4,10 @@ if portal.portal_skins.updateSkinCookie():
url = 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="/")
absolute_url = context.absolute_url()
absolute_url = absolute_url[:-1] if absolute_url.endswith('/') else absolute_url
url = "%s/login_form?portal_status_message=%s" % ( url = "%s/login_form?portal_status_message=%s" % (
context.absolute_url(), absolute_url,
context.Base_translateString("Login and/or password is incorrect.") context.Base_translateString("Login and/or password is incorrect.")
+ ("&amp;came_from=" + url if url else "")) + ("&amp;came_from=" + url if url else ""))
elif not url: elif not url:
......
...@@ -522,6 +522,7 @@ class FolderMixIn(ExtensionClass.Base): ...@@ -522,6 +522,7 @@ class FolderMixIn(ExtensionClass.Base):
hence it does not compute the inner acquisition path. hence it does not compute the inner acquisition path.
""" """
document_url = self.absolute_url() document_url = self.absolute_url()
document_url = document_url[:-1] if document_url.endswith('/') else document_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