Show
Ignore:
Timestamp:
02/27/08 16:21:32 (2 years ago)
Author:
JensDiemer
Message:

NEW internal page handling:
-internal pages doesn't store in the database.
-additional CSS/JS files linked as normal static files.
-new path constants in the settings.py
See also:  http://pylucid.org/phpBB2/viewtopic.php?t=198
TODO: refactory the insall section and the plugin manager for this. Remove the unused InternalPage? model.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pylucid/PyLucid/system/BasePlugin.py

    r1419 r1449  
    3232""" 
    3333 
    34 import pprint 
     34import os, pprint 
    3535 
     36from django.conf import settings 
    3637from django.utils.safestring import mark_safe 
    3738 
    38 from PyLucid.db.internal_pages import get_internal_page 
    3939from PyLucid.tools.content_processors import apply_markup, \ 
    4040                                                        render_string_template 
    4141from PyLucid.tools.utils import escape 
    42  
     42from PyLucid.system.internal_page import InternalPage, InternalPageNotFound 
    4343 
    4444 
    4545class PyLucidBasePlugin(object): 
    4646 
    47     # A simple cache for the internal pages. Because if a plugin use very 
    48     # 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) 
    5050 
    51     def __init__(self, context, response): 
    5251        self.context    = context 
    5352        self.response   = response 
     
    7574 
    7675 
    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): 
    9777        """ 
    9878        insert the additional JavaScript and StyleSheet data into the global 
    9979        context. 
     80        page_style.replace_add_data() puts the file links into the page. 
    10081        """ 
    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, 
    11089            }) 
    111  
    112         # append the JavaScript data 
    113         add("content_js", "js_data") 
    114  
    115         # append the StyleSheet data 
    116         add("content_css", "css_data") 
    117  
    11890 
    11991    def _get_rendered_template(self, internal_page_name, context, debug=False): 
     
    12193        return a rendered internal page 
    12294        """ 
    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 
    124102 
    125         content_html = internal_page.content_html 
     103        self._add_js_css_data(internal_page_name) 
    126104 
    127         self._add_js_css_data(internal_page) 
     105        html = self.__render(content, context, debug) 
    128106 
    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) 
    130110 
    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 
    134112        return html 
    135113 
     
    139117        """ 
    140118        html = self._get_rendered_template(internal_page_name, context, debug) 
    141         html = mark_safe(html) # turn djngo auto-escaping off 
    142119        self.response.write(html) 
    143120