-
-
Notifications
You must be signed in to change notification settings - Fork 203
Automatically set the ajax_load request parameter. #4188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from Products.CMFPlone.testing import PRODUCTS_CMFPLONE_INTEGRATION_TESTING | ||
from zope.component import getMultiAdapter | ||
from zope.event import notify | ||
from zope.traversing.interfaces import BeforeTraverseEvent | ||
|
||
import unittest | ||
|
||
|
||
class TestMainTemplate(unittest.TestCase): | ||
layer = PRODUCTS_CMFPLONE_INTEGRATION_TESTING | ||
|
||
def setUp(self): | ||
self.portal = self.layer["portal"] | ||
self.request = self.layer["request"] | ||
|
||
def test_request_containment(self): | ||
"""Very basic test to show that the following works: | ||
`"ajax_load" in request` | ||
instead of: | ||
`request.get("ajax_load", MARKER) is not MARKER1` | ||
""" | ||
request = self.request.clone() | ||
request.form["ajax_load"] = True | ||
self.assertTrue("ajax_load" in request.form) | ||
self.assertTrue("ajax_load" in request) | ||
|
||
def test_main_template_standard(self): | ||
view = getMultiAdapter((self.portal, self.request), name="main_template") | ||
self.assertEqual(view.template_name, "templates/main_template.pt") | ||
|
||
def test_main_template_ajax_parameter(self): | ||
request = self.request.clone() | ||
request.form["ajax_load"] = True | ||
view = getMultiAdapter((self.portal, request), name="main_template") | ||
self.assertEqual(view.template_name, "templates/ajax_main_template.pt") | ||
|
||
def test_main_template_ajax_manually(self): | ||
request = self.request.clone() | ||
request.set("ajax_load", True) | ||
view = getMultiAdapter((self.portal, request), name="main_template") | ||
self.assertEqual(view.template_name, "templates/ajax_main_template.pt") | ||
|
||
def test_main_template_auto(self): | ||
request = self.request.clone() | ||
request.environ["HTTP_X_REQUESTED_WITH"] = "XMLHttpRequest" | ||
# Manually trigger the BeforeTraverseEvent to set the ajax_load | ||
# parameter - using restrictedTraverse would not work here | ||
notify(BeforeTraverseEvent(self.portal, request)) | ||
view = getMultiAdapter((self.portal, request), name="main_template") | ||
self.assertEqual(view.template_name, "templates/ajax_main_template.pt") | ||
|
||
def test_main_template_noauto_if_set(self): | ||
request = self.request.clone() | ||
request.form["ajax_load"] = "False" | ||
request.environ["HTTP_X_REQUESTED_WITH"] = "XMLHttpRequest" | ||
# Manually trigger the BeforeTraverseEvent to set the ajax_load | ||
# parameter - using restrictedTraverse would not work here | ||
notify(BeforeTraverseEvent(self.portal, request)) | ||
view = getMultiAdapter((self.portal, request), name="main_template") | ||
self.assertEqual(view.template_name, "templates/main_template.pt") | ||
|
||
def test_main_template_no_ajax_1(self): | ||
request = self.request.clone() | ||
request.form["ajax_load"] = False | ||
view = getMultiAdapter((self.portal, request), name="main_template") | ||
self.assertEqual(view.template_name, "templates/main_template.pt") | ||
|
||
def test_main_template_no_ajax_2(self): | ||
request = self.request.clone() | ||
request.form["ajax_load"] = "0" | ||
view = getMultiAdapter((self.portal, request), name="main_template") | ||
self.assertEqual(view.template_name, "templates/main_template.pt") | ||
|
||
def test_main_template_no_ajax_3(self): | ||
request = self.request.clone() | ||
request.form["ajax_load"] = "off" | ||
view = getMultiAdapter((self.portal, request), name="main_template") | ||
self.assertEqual(view.template_name, "templates/main_template.pt") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Automatically set the ajax_load request parameter. | ||
|
||
Zope maintains the "HTTP_X_REQUESTED_WITH" request header. If this is set to | ||
"XMLHttpRequest", we have an AJAX request. In this case the ajax_load parameter | ||
is set to True directly on the request object. | ||
If the ajax_load parameter was already set to a true-ish or false-ish value, it | ||
is not overwritten. | ||
|
||
This should make use for the ajax_main_template for any AJAX request, | ||
regardless if the ajax_load parameter was manually set or not and potentially | ||
speed up Plone Classic UI rendering. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea why this
ajax_main_template
hasajax_load=False
in the first place. This variable seems really obscure defined like this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree.
But I think it's maybe needed by other templates and was incorrectly defined due to a copy paste error.
I did now looked it up and saw:
ajax_load python:True
toajax_load python:False
happened in this commit at some Barceloneta LTS syncing:954942a
Now it makes sense.
But no big deal apparently that it was defined incorrectly, because everything was working just fine.