forked from django-cms/django-cms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changed logic of plugin media rendering to be done in a middleware to…
… enable non-page placeholders to register media files added the ability to invalidate the menu cache made CMSPluginBase.get_plugin_media context aware
- Loading branch information
ojii
committed
Apr 13, 2010
1 parent
a81390f
commit e57c58a
Showing
13 changed files
with
72 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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 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 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,34 @@ | ||
from django.forms.widgets import Media | ||
from django.utils.encoding import smart_unicode | ||
from django.conf import settings | ||
from cms.middleware.toolbar import HTML_TYPES | ||
|
||
def inster_before_tag(string, tag, insertion): | ||
no_case = string.lower() | ||
index = no_case.find("<%s" % tag.lower()) | ||
if index > -1: | ||
start_tag = index | ||
return string[:start_tag] + insertion + string[start_tag:] | ||
else: | ||
return string | ||
|
||
class PlaceholderMediaMiddleware(object): | ||
def inject_media(self, request, response): | ||
if request.is_ajax(): | ||
return False | ||
if response.status_code != 200: | ||
return False | ||
if not response['Content-Type'].split(';')[0] in HTML_TYPES: | ||
return False | ||
if request.path_info.startswith(settings.MEDIA_URL): | ||
return False | ||
return True | ||
|
||
def process_request(self, request): | ||
request.placeholder_media = Media() | ||
|
||
def process_response(self, request, response): | ||
if self.inject_media(request, response): | ||
response.content = inster_before_tag(smart_unicode(response.content), | ||
u'/head', smart_unicode(request.placeholder_media.render())) | ||
return response |
This file contains 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 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 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 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 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 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 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 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 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 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