Changeset 1449

Show
Ignore:
Timestamp:
27.02.2008 16:21:32 (3 months 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:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/pylucid/PyLucid/install/BaseInstall.py

    r1343 r1449  
    44""" 
    55 
    6 import sys, os 
     6import sys, os, posixpath 
    77 
    88from PyLucid import PYLUCID_VERSION_STRING 
     
    107107 
    108108        self.request = request 
     109 
     110        media_url = posixpath.join( 
     111            settings.MEDIA_URL, settings.PYLUCID_MEDIA_DIR, "" 
     112        ) # With appended slash, for backward compatible 
    109113        self.context = { 
    110114            "output": "", 
    111115            "request": request, 
    112             "PyLucid_media_url": settings.PYLUCID_MEDIA_URL
     116            "PyLucid_media_url": media_url
    113117            "version": PYLUCID_VERSION_STRING, 
    114118            "current_working_dir": os.getcwd(), 
  • trunk/pylucid/PyLucid/plugins_internal/auth/auth.py

    r1440 r1449  
    4242__version__ = "$Rev$" 
    4343 
    44 import datetime 
     44import datetime, posixpath 
    4545 
    4646from django.http import HttpResponseRedirect 
     
    317317        next_url = self.request.POST.get('next_url',self.URLs['scriptRoot']) 
    318318        salt = js_login_data.salt 
     319 
     320        media_url = posixpath.join( 
     321            settings.MEDIA_URL, settings.PYLUCID_MEDIA_DIR, 
     322        ) 
    319323        context = { 
    320324            "username": user.username, 
     
    322326            "salt": salt, 
    323327            "next_url": next_url, 
    324             "PyLucid_media_url": settings.PYLUCID_MEDIA_URL
     328            "PyLucid_media_url": media_url
    325329        } 
    326330 
  • trunk/pylucid/PyLucid/plugins_internal/main_menu/main_menu.py

    r1371 r1449  
    8585 
    8686            # Render one menu entry 
    87             html = self._get_rendered_template("main menu li", entry) 
     87            html = self._get_rendered_template("main_menu_li", entry) 
    8888            result.append(html) 
    8989 
     
    9393 
    9494        # render all menu entries into a <ul> tag 
    95         menu_html = self._get_rendered_template("main menu ul", context) 
     95        menu_html = self._get_rendered_template("main_menu_ul", context) 
    9696 
    9797        return mark_safe(menu_html) 
  • trunk/pylucid/PyLucid/plugins_internal/page_style/page_style.py

    r1425 r1449  
    4242from PyLucid.system.BasePlugin import PyLucidBasePlugin 
    4343from PyLucid.tools.content_processors import render_string_template 
    44 from PyLucid.db.internal_pages import get_internal_page 
    4544 
    4645class page_style(PyLucidBasePlugin): 
     
    103102        return response 
    104103 
    105  
     104from PyLucid.system.internal_page import get_internal_page, InternalPageNotFound 
    106105def replace_add_data(context, content): 
    107106    """ 
     
    110109    Note: The tag added in PyLucid.plugins_internal.page_style 
    111110    """ 
    112  
    113     internal_page = get_internal_page("page_style", "add_data") 
    114     internal_page_content = internal_page.content_html 
     111    internal_page_content = get_internal_page(context, "page_style", "add_data") 
    115112 
    116113    context = { 
  • trunk/pylucid/PyLucid/settings_example.py

    r1388 r1449  
    169169MEDIA_ROOT = "./media/" 
    170170 
    171  
    172171# URL that handles the media served from MEDIA_ROOT. 
    173172#     Example-1: "/media/" (default) 
     
    175174#     Example-3: "http://media.your_domain.net/" 
    176175MEDIA_URL = "/media/" 
    177  
    178  
    179 # URL for the PyLucid media files. 
    180 #     Example-1: "/media/PyLucid/" (default) 
    181 #     Examlpe-2: "http://other_domain.net/media/PyLucid/" 
    182 #     Example-3: "http://pylucid.media.your_domain.net/" 
    183 PYLUCID_MEDIA_URL = "/media/PyLucid/" 
    184  
    185176 
    186177# URL prefix for admin media -- CSS, JavaScript and images. 
     
    321312# PYLUCID BASE SETTINGS 
    322313# basic adjustments, witch don't have to be changed. 
     314 
     315# All PyLucid media files stored in a sub directory under the django media 
     316# path. Used for building filesystem path and URLs. 
     317# filesystem path: MEDIA_ROOT + PYLUCID_MEDIA_SUBDIR 
     318# URLs: MEDIA_URL + PYLUCID_MEDIA_SUBDIR 
     319PYLUCID_MEDIA_DIR = "PyLucid" 
     320 
     321# Sub directory name for all default internal pages. It would be used to build 
     322# the filesystem path and the URL! 
     323# filesystem path: MEDIA_ROOT + PYLUCID_MEDIA_SUBDIR + INTERNAL_PAGE_PATH 
     324# URLs: MEDIA_URL + PYLUCID_MEDIA_SUBDIR + INTERNAL_PAGE_PATH 
     325INTERNAL_PAGE_DIR = "internal_page" 
     326 
     327# If you will change a internal page, you must copy a file from 
     328# INTERNAL_PAGE_PATH into this directory. (Same subdirectory!) 
     329# (default: "custom") 
     330# filesystem path: MEDIA_ROOT + PYLUCID_MEDIA_SUBDIR + CUSTOM_INTERNAL_PAGE_PATH 
     331# URLs: MEDIA_URL + PYLUCID_MEDIA_SUBDIR + CUSTOM_INTERNAL_PAGE_PATH 
     332CUSTOM_INTERNAL_PAGE_DIR = "custom" 
     333 
    323334 
    324335# Path to the Plugins 
  • 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