Changeset 1449 for trunk/pylucid/PyLucid/system/BasePlugin.py
- Timestamp:
- 02/27/08 16:21:32 (9 months ago)
- Files:
-
- 1 modified
-
trunk/pylucid/PyLucid/system/BasePlugin.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pylucid/PyLucid/system/BasePlugin.py
r1419 r1449 32 32 """ 33 33 34 import pprint34 import os, pprint 35 35 36 from django.conf import settings 36 37 from django.utils.safestring import mark_safe 37 38 38 from PyLucid.db.internal_pages import get_internal_page39 39 from PyLucid.tools.content_processors import apply_markup, \ 40 40 render_string_template 41 41 from PyLucid.tools.utils import escape 42 42 from PyLucid.system.internal_page import InternalPage, InternalPageNotFound 43 43 44 44 45 45 class PyLucidBasePlugin(object): 46 46 47 # A simple cache for the internal pages. Because if a plugin use very48 # often a small template, we have many database queries!49 _internal_page_cache = {}47 def __init__(self, context, response): 48 self.plugin_name = self.__class__.__name__ 49 self.internal_page = InternalPage(context, self.plugin_name) 50 50 51 def __init__(self, context, response):52 51 self.context = context 53 52 self.response = response … … 75 74 76 75 77 def _get_template(self, internal_page_name): 78 """ 79 Retuned the internal page object. 80 Get the plugin name throu the superior class name. 81 Use a simple cache to hold down the database access. 82 """ 83 if internal_page_name in self._internal_page_cache: 84 return self._internal_page_cache[internal_page_name] 85 86 plugin_name = self.__class__.__name__ 87 internal_page = get_internal_page(plugin_name, internal_page_name) 88 89 if not self.request.debug: 90 # Use the cache only if DEBUG is off -> For development the cache 91 # is hindering, if we change the internal page content. 92 self._internal_page_cache[internal_page_name] = internal_page 93 94 return internal_page 95 96 def _add_js_css_data(self, internal_page): 76 def _add_js_css_data(self, internal_page_name): 97 77 """ 98 78 insert the additional JavaScript and StyleSheet data into the global 99 79 context. 80 page_style.replace_add_data() puts the file links into the page. 100 81 """ 101 def add(attr_name, key): 102 content = getattr(internal_page, attr_name) 103 if content == "": 104 # Nothig to append ;) 105 return 106 107 self.context[key].append({ 108 "from_info": "internal page: '%s'" % internal_page.name, 109 "data": content, 82 for slug in ("js", "css"): 83 url = self.internal_page.get_url(internal_page_name, slug) 84 if url == None: 85 continue 86 self.context["%s_data" % slug].append({ 87 "plugin_name": self.plugin_name, 88 "url": url, 110 89 }) 111 112 # append the JavaScript data113 add("content_js", "js_data")114 115 # append the StyleSheet data116 add("content_css", "css_data")117 118 90 119 91 def _get_rendered_template(self, internal_page_name, context, debug=False): … … 121 93 return a rendered internal page 122 94 """ 123 internal_page = self._get_template(internal_page_name) 95 try: 96 content = self.internal_page.get_content(internal_page_name, "html") 97 except InternalPageNotFound: 98 self.page_msg.red( 99 "Internal page '%s' not found!" % internal_page_name 100 ) 101 return 124 102 125 content_html = internal_page.content_html103 self._add_js_css_data(internal_page_name) 126 104 127 self._add_js_css_data(internal_page)105 html = self.__render(content, context, debug) 128 106 129 html = self.__render(content_html, context, debug) 107 # FIXME: Should be remove the markup function in internal pages? 108 # markup_object = internal_page.markup 109 # html = apply_markup(html, self.context, markup_object) 130 110 131 markup_object = internal_page.markup 132 html = apply_markup(html, self.context, markup_object) 133 111 html = mark_safe(html) # turn djngo auto-escaping off 134 112 return html 135 113 … … 139 117 """ 140 118 html = self._get_rendered_template(internal_page_name, context, debug) 141 html = mark_safe(html) # turn djngo auto-escaping off142 119 self.response.write(html) 143 120
