Changeset 1127
- Timestamp:
- 06/29/07 16:05:08 (3 years ago)
- Location:
- branches/0.8(django)
- Files:
-
- 3 added
- 12 modified
- 1 moved
-
dev_scripts/local_dev_tests/newform_select_user.py (modified) (1 diff)
-
index.cgi (modified) (5 diffs)
-
PyLucid/defaulttags/lucidTag.py (modified) (2 diffs)
-
PyLucid/index.py (modified) (3 diffs)
-
PyLucid/middlewares/additional_content.py (moved) (moved from branches/0.8(django)/PyLucid/middlewares/pagestats.py) (5 diffs)
-
PyLucid/plugins_internal/admin_menu/admin_menu.py (modified) (3 diffs)
-
PyLucid/plugins_internal/page_style/internal_pages (added)
-
PyLucid/plugins_internal/page_style/internal_pages/add_data.html (added)
-
PyLucid/plugins_internal/page_style/internal_pages/write_styles.html (added)
-
PyLucid/plugins_internal/page_style/page_style.py (modified) (4 diffs)
-
PyLucid/plugins_internal/page_style/page_style_cfg.py (modified) (1 diff)
-
PyLucid/plugins_internal/page_update_list/page_update_list.py (modified) (1 diff)
-
PyLucid/settings_example.py (modified) (1 diff)
-
PyLucid/system/BaseModule.py (modified) (3 diffs)
-
PyLucid/system/plugin_manager.py (modified) (1 diff)
-
PyLucid/tools/content_processors.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/0.8(django)/dev_scripts/local_dev_tests/newform_select_user.py
r1104 r1127 51 51 users_form = UsersForm(users) 52 52 53 for field in users_form: 54 for i in dir(field): 55 print i 56 print field.auto_id 57 print field.html_name 58 53 59 html = users_form.as_p() 54 60 print html -
branches/0.8(django)/index.cgi
r1051 r1127 55 55 -global header_send variable 56 56 """ 57 oldFileinfo = "" 58 header_send = False 57 def __init__(self, out): 58 self.out = out 59 self.oldFileinfo = "" 60 self.header_send = False 59 61 60 62 def _get_fileinfo(self): … … 87 89 message comes from. 88 90 """ 89 stack = inspect.stack()[1]90 # fileinfo = (stack[1].split("/")[-1][-40:], stack[2])91 91 fileinfo = self._get_fileinfo() 92 92 … … 110 110 be send. 111 111 """ 112 def __init__(self, out):113 self.out = out114 115 112 def check(self, txt): 116 113 txt_lower = txt.lower() … … 135 132 136 133 def wrong_header_info(self): 137 # Angaben zur Datei, Zeilennummer, aus dem die Nachricht stammt138 134 self.out.write("Content-type: text/html; charset=utf-8\r\n\r\n") 139 135 self.out.write("Wrong Header!!!\n") … … 146 142 Sends a header, if the header were not already sent. 147 143 """ 148 def __init__(self, out):149 self.out = out150 self.header_send = False151 152 144 def write(self, *txt): 153 145 txt = " ".join([i for i in txt]) -
branches/0.8(django)/PyLucid/defaulttags/lucidTag.py
r1087 r1127 1 #!/usr/bin/python 2 # -*- coding: UTF-8 -*- 1 3 2 4 """ … … 80 82 raise AssertionError(msg) 81 83 82 # print content83 # print "---"84 85 84 return content 86 85 -
branches/0.8(django)/PyLucid/index.py
r1121 r1127 40 40 from PyLucid.system.URLs import URLs 41 41 42 from PyLucid.tools.content_processors import apply_markup, render_template 42 from PyLucid.tools.content_processors import apply_markup, \ 43 render_string_template 43 44 44 45 … … 63 64 ) 64 65 65 current_page.content = render_ template(current_page.content, context)66 current_page.content = render_string_template(current_page.content, context) 66 67 67 68 template = current_page.template 68 69 template_content = template.content 69 70 70 html = render_template(template_content, context) 71 72 # import cgi, pprint 73 # print context 74 # debug = "<hr/><pre>%s</pre></html>" % cgi.escape(pprint.pformat(context)) 75 # html = html.replace("</html>", debug) 76 71 html = render_string_template(template_content, context) 77 72 return HttpResponse(html) 78 73 … … 107 102 # For additional JavaScript and StyleSheet information. 108 103 # JS+CSS from internal_pages or CSS data for pygments 104 # Add into the context object. Would be integraged in the page with the 105 # additional_content middleware. 109 106 context["js_data"] = [] 110 107 context["css_data"] = [] 108 109 # Add the context to the reponse object. 110 # Used in PyLucid.middlewares.additional_content 111 request.CONTEXT = context 111 112 112 113 return context -
branches/0.8(django)/PyLucid/middlewares/additional_content.py
r1090 r1127 3 3 4 4 """ 5 PyLucid page statistics6 ~~~~~~~~~~~~~~~~~~~~~~~ 5 PyLucid additional page content 6 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 7 7 8 Replace some Tags after the cms page is completly created: 9 10 ADD_DATA_TAG 11 ~~~~~~~~~~~~ 12 The Stylesheet and JavaScript data from the internal pages are stored in 13 a list: context["js_data"] and context["css_data"] 14 The page_style Plugin insert the ADD_DATA_TAG into the response content. 15 Here we replace the tag with the collected CSS/JS contents. 16 17 18 PAGE_STAT_TAG 19 ~~~~~~~~~~~~~ 8 20 A small page statistic middleware. 9 -replace the > TAG< with some stats. But only in HTML pages.21 -replace the >PAGE_STAT_TAG< with some stats. But only in HTML pages. 10 22 11 23 Based on http://code.djangoproject.com/wiki/PageStatsMiddleware 24 12 25 13 26 Last commit info: … … 25 38 from django.db import connection 26 39 40 from PyLucid.db.internal_pages import get_internal_page 41 from PyLucid.tools.content_processors import render_string_template 42 27 43 start_overall = time() 28 44 29 TAG = "<!-- script_duration -->" 45 PAGE_STAT_TAG = "<!-- script_duration -->" 46 ADD_DATA_TAG = "<!-- additional_data -->" 30 47 31 48 FMT = ( … … 35 52 ) 36 53 37 class PageStatsMiddleware(object):54 class AdditionalContentMiddleware(object): 38 55 def process_view(self, request, view_func, view_args, view_kwargs): 39 56 start_time = time() … … 50 67 return response 51 68 69 content = response.content 70 71 content = self._add_data(content, request) 72 content = self._page_stat(content, start_time, old_queries) 73 74 response.content = content 75 76 return response 77 78 79 def _add_data(self, content, request): 80 """ 81 Replace the ADD_DATA_TAG 82 add CSS/JS data from the Plugins into the page. 83 Note: The ADD_DATA_TAG puts the page_style plugin into the content! 84 """ 85 try: 86 context = request.CONTEXT 87 except AttributeError: 88 # In the _install section, we need no add_data... There is no 89 # CONTEXT object in the request object. -> Do nothing 90 return content 91 92 try: 93 internal_page = get_internal_page("page_style", "add_data") 94 internal_page_content = internal_page.content_html 95 96 context = { 97 "js_data": context["js_data"], 98 "css_data": context["css_data"], 99 } 100 html = render_string_template(internal_page_content, context) 101 except Exception, msg: 102 html = "<!-- Replace the ADD_DATA_TAG error: %s -->" % msg 103 104 content = content.replace(ADD_DATA_TAG, html) 105 106 return content 107 108 109 def _page_stat(self, content, start_time, old_queries): 110 """ 111 Replace the PAGE_STAT_TAG 112 """ 52 113 # compute the db time for the queries just run 53 114 queries = len(connection.queries) - old_queries … … 60 121 } 61 122 62 response.content = response.content.replace(TAG, stat_info)123 content = content.replace(PAGE_STAT_TAG, stat_info) 63 124 64 return response125 return content -
branches/0.8(django)/PyLucid/plugins_internal/admin_menu/admin_menu.py
r1116 r1127 2 2 # -*- coding: UTF-8 -*- 3 3 4 __author__ = "Jens Diemer (www.jensdiemer.de)"5 __license__ = "GNU General Public License (GPL)" 6 __url__ = "http://www.PyLucid.org" 4 """ 5 PyLucid admin menu 6 ~~~~~~~~~~~~~~~~~~ 7 7 8 """ 9 the administration top menu 8 The administration top and sub menu. 10 9 11 TODO: edit_page_link should use pageadmin.edit_page - a inline editing 10 Last commit info: 11 ~~~~~~~~~~~~~~~~~ 12 $LastChangedDate: 2007-06-26 10:37:35 +0200 (Di, 26 Jun 2007) $ 13 $Rev: 1111 $ 14 $Author: JensDiemer $ 15 16 :copyright: 2007 by Jens Diemer 17 :license: GNU GPL v2 or above, see LICENSE for more details 12 18 """ 13 19 20 14 21 from PyLucid.system.BaseModule import PyLucidBaseModule 22 15 23 16 24 class admin_menu(PyLucidBaseModule): … … 18 26 def lucidTag(self): 19 27 """ 20 Front menu anzeigen28 Render the front menu 21 29 """ 22 30 current_page_id = self.current_page.id … … 24 32 25 33 context = { 34 "login_link" : self.context["login_link"], 26 35 "edit_page_link": self.URLs.commandLink("page_admin", "edit_page"), 27 # "edit_page_link": edit_link, 28 # "new_page_link": self.URLs.adminLink("PyLucid/page/add/"), 29 "new_page_link": self.URLs.commandLink("page_admin", "new_page"), 30 "sub_menu_link": self.URLs.commandLink("admin_menu", "sub_menu"), 36 "new_page_link" : self.URLs.commandLink("page_admin", "new_page"), 37 "sub_menu_link" : self.URLs.methodLink("sub_menu"), 31 38 } 32 self._render_template("top_menu", context) 39 self._render_template("top_menu", context)#, debug=True) 33 40 34 41 def sub_menu(self): 42 """ 43 render the sub menu 44 """ 35 45 context = { 36 46 "commandURLprefix": self.URLs.get_command_base(), 37 47 "adminURLprefix": self.URLs["adminBase"], 38 48 } 39 # self.page_msg(context) 40 41 self._render_template("sub_menu", context) 49 self._render_template("sub_menu", context)#, debug=True) 42 50 43 51 -
branches/0.8(django)/PyLucid/plugins_internal/page_style/page_style.py
r1087 r1127 8 8 - Put the css html tag into the cms page. 9 9 - Send the current stylesheet directly to the client. 10 11 Note: 12 The page_style.lucidTag() method adds the additional_content ADD_DATA_TAG 13 into the page. 14 The middleware PyLucid.middlewares.additional_content replace the tag and 15 puts the collected CSS/JS contents into the page. 10 16 11 17 Last commit info: … … 27 33 from django.http import HttpResponse 28 34 35 from PyLucid.middlewares.additional_content import ADD_DATA_TAG 29 36 from PyLucid.models import Style 30 31 37 from PyLucid.system.BaseModule import PyLucidBaseModule 32 38 33 39 class page_style(PyLucidBaseModule): 34 40 35 #~ def __init__(self, *args, **kwargs):36 #~ super(page_style, self).__init__(*args, **kwargs)37 38 41 def lucidTag(self): 39 # Schreibt den addCode-Tag, damit am Ende noch die CSS/JS Daten 40 # von Modulen eingefügt werden können 41 #~ self.response.write(self.response.addCode.tag) 42 """ 43 -Put a link to sendStyle into the page. 44 -Insert the ADD_DATA_TAG for the additional_content middleware 45 """ 46 self.response.write(ADD_DATA_TAG) 42 47 43 48 current_page = self.context["PAGE"] … … 49 54 ) 50 55 cssTag = '<link rel="stylesheet" type="text/css" href="%s" />\n' % url 56 self.response.write(cssTag) 51 57 52 self.response.write(cssTag)53 58 54 59 def print_current_style(self): 55 60 """ 56 CSS direkt in die Seite einfügen 61 -Write the stylesheet directly into the page. 62 -Insert the ADD_DATA_TAG for the additional_content middleware 63 Used with the tag: {% lucidTag page_style.print_current_style %} 57 64 """ 58 # Schreibt den addCode-Tag, damit am Ende noch die CSS/JS Daten 59 # von Modulen eingefügt werden können 60 self.response.write(self.response.addCode.tag) 65 self.response.write(ADD_DATA_TAG) 61 66 62 page_id = self.session["page_id"] 63 getItems = ["content"] 64 css = self.db.side_style_by_id(page_id, getItems) 65 css = css["content"] 67 current_page = self.context["PAGE"] 68 stylesheet = current_page.style 66 69 67 self.response.write('<style type="text/css">') 68 self.response.write(css) 69 self.response.write('</style>') 70 context = { 71 "content": stylesheet.content, 72 } 73 self._render_template("write_styles", context)#, debug=True) 74 70 75 71 76 def sendStyle(self, css_filename): 72 77 """ 73 Sendet das CSS als Datei, da in die Seite nur ein Link eingefügt, der74 jetzt "ausgeführt" wird.75 Dabei wird eine "Browsercache-Anfrage" berücksichtigt.78 send the stylesheet as a file to the client. 79 It's the request started with the link tag from self.lucidTag() ;) 80 TODO: Should insert some Headers for the browser cache. 76 81 """ 77 82 css_name = css_filename.split(".",1)[0] … … 90 95 return response 91 96 92 """93 timeFormat = "%a, %d %b %Y %H:%M:%S GMT"94 95 # Ein "wirklich" frisches response-Object nehmen:96 response = HttpResponse()97 response.headers['Content-Type'] = 'text/css; charset=utf-8'98 99 # Hop-by-hop Headers ist mit wsgiref nicht erlaubt:100 #~ response.headers['Connection'] = "Keep-Alive"101 102 page_id = self.session["page_id"]103 getItems = ["id", "content", "lastupdatetime"]104 cssData = self.db.side_style_by_id(page_id, getItems)105 106 lastupdatetime = cssData["lastupdatetime"] # datetime-Object!107 108 #~ raise str(repr(lastupdatetime))109 110 lastModified = lastupdatetime.strftime(timeFormat)111 #~ print "lastModified:", lastModified112 113 # 1Tag * 60Min * 60Sec = 3600Sec114 response.headers['Cache-Control'] = 'max-age=3600'115 delta = datetime.timedelta(days=1)116 expires = lastupdatetime + delta117 expires = expires.strftime(timeFormat)118 #~ print "expires:", expires119 response.headers['Expires'] = expires120 121 # ID damit der Browser das Style eindeutige Identifizieren kann:122 eTag = '"style-%s"' % cssData["id"]123 response.headers['Etag'] = eTag124 125 # Chaching im Browser überprüfen:126 if "HTTP_IF_MODIFIED_SINCE" in self.environ and \127 "HTTP_IF_NONE_MATCH" in self.environ:128 # Der Browser fragt nach, ob es die Daten aus seinem Chache nehmen129 # soll.130 send_modified = self.environ["HTTP_IF_MODIFIED_SINCE"]131 send_eTag = self.environ["HTTP_IF_NONE_MATCH"]132 if send_eTag == eTag and send_modified == lastModified:133 # CSS Daten haben sich nicht geändert!134 response.status = 304 # HTTP/1.x 304 Not Modified135 return response136 137 # Die CSS Daten werden zum ersten mal gesendet oder diese haben138 # sich seit dem letzten Aufruf geändert.139 140 cssContent = cssData["content"]141 142 # Content-Length kann nur in UTF8 und nicht richtig in Unicode143 # ermittelt werden!!!144 cssContent = cssContent.encode("utf8")145 contentLen = len(cssContent)146 response.headers['Content-Length'] = '%s' % contentLen147 148 response.headers['Last-Modified'] = lastModified149 response.headers['Content-Transfer-Encoding'] = '8bit' #'binary'150 response.headers['Content-Type'] = \151 'text/css; charset=utf-8'152 153 response.write(cssContent)154 155 # force Windows input/output to binary156 if sys.platform == "win32":157 try:158 import msvcrt159 msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)160 msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)161 except:162 pass163 164 return response165 166 """167 168 169 170 171 -
branches/0.8(django)/PyLucid/plugins_internal/page_style/page_style_cfg.py
r1103 r1127 18 18 "must_login" : False, 19 19 "must_admin" : False, 20 "internal_page_info" : { 21 # Note: This internal page is not used in page_style.lucidTag() 22 # The data used in PyLucid.middlewares.additional_content! 23 "name" : "add_data", 24 "description" : "Template for adding CSS/JS from plugins.", 25 "markup" : None 26 }, 20 27 }, 21 28 "print_current_style" : { 22 29 "must_login" : False, 23 30 "must_admin" : False, 31 "internal_page_info" : { 32 "name" : "write_styles", 33 "description" : "Insert the stylesheets directly.", 34 "markup" : None 35 }, 24 36 }, 25 37 "sendStyle" : { -
branches/0.8(django)/PyLucid/plugins_internal/page_update_list/page_update_list.py
r1123 r1127 41 41 self._render_template("PageUpdateTable", context)#, debug=True) 42 42 43 44 45 46 47 48 49 50 51 52 53 54 -
branches/0.8(django)/PyLucid/settings_example.py
r1116 r1127 221 221 'django.middleware.common.CommonMiddleware', 222 222 'django.middleware.doc.XViewMiddleware', 223 'PyLucid.middlewares.pagestats.PageStatsMiddleware', 223 224 'PyLucid.middlewares.additional_content.AdditionalContentMiddleware', 224 225 ) 225 226 -
branches/0.8(django)/PyLucid/system/BaseModule.py
r1111 r1127 3 3 4 4 """ 5 Basis Modul von den andere Module erben können 5 PyLucid BaseModule 6 ~~~~~~~~~~~~~~~~~~ 6 7 7 Bsp.: 8 The base Plugin object. Every Plugin can inherit. 8 9 9 from PyLucid.system.BaseModule import PyLucidBaseModule 10 e.g.: 10 11 11 class Bsp(PyLucidBaseModule): 12 def __init__(self, *args, **kwargs): 13 super(Bsp, self).__init__(*args, **kwargs) 12 from PyLucid.system.BaseModule import PyLucidBaseModule 13 14 class Bsp(PyLucidBaseModule): 15 def __init__(self, *args, **kwargs): 16 super(Bsp, self).__init__(*args, **kwargs) 17 18 19 Last commit info: 20 ~~~~~~~~~~~~~~~~~ 21 $LastChangedDate$ 22 $Rev$ 23 $Author$ 24 25 :copyright: 2007 by Jens Diemer 26 :license: GNU GPL, see LICENSE for more details 27 """ 14 28 15 29 16 30 17 Last commit info: 18 ---------------------------------- 19 $LastChangedDate$ 20 $Rev$ 21 $Author$ 22 23 Created by Jens Diemer 24 25 license: 26 GNU General Public License v2 or above 27 http://www.opensource.org/licenses/gpl-license.php 28 """ 29 30 from PyLucid.models import PagesInternal 31 from PyLucid.tools.content_processors import apply_markup, render_template 32 33 34 #______________________________________________________________________________ 31 from PyLucid.db.internal_pages import get_internal_page 32 from PyLucid.tools.content_processors import apply_markup, \ 33 render_string_template 35 34 36 35 … … 65 64 66 65 def _get_template(self, internal_page_name): 67 plugin_name = self.__class__.__name__ # Get the superior class name 68 69 internal_page_name = ".".join([plugin_name, internal_page_name]) 70 71 # django bug work-a-round 72 # http://groups.google.com/group/django-developers/browse_thread/thread/e1ed7f81e54e724a 73 internal_page_name = internal_page_name.replace("_", " ") 74 75 try: 76 return PagesInternal.objects.get(name = internal_page_name) 77 except PagesInternal.DoesNotExist, err: 78 msg = "internal page '%s' not found! (%s)" % (internal_page_name, err) 79 raise PagesInternal.DoesNotExist(msg) 80 66 """ 67 retuned the internal page object 68 Get the plugin name throu the superior class name 69 """ 70 plugin_name = self.__class__.__name__ 71 internal_page = get_internal_page(plugin_name, internal_page_name) 72 return internal_page 81 73 82 74 def _add_js_css_data(self, internal_page): … … 134 126 """ 135 127 html = self.__render(template, context, debug) 136 137 128 self.response.write(html) 138 129 139 130 def __render(self, content, context, debug=False): 140 131 """ 141 render the string with the given context132 render the content string with the given context and returned it. 142 133 -debug the context, if debug is on. 143 -prepare the context144 -retunted the rendered page145 134 """ 146 135 if debug: 147 136 self._debug_context(context, content) 148 137 149 html = render_ template(content, self.context, context)138 html = render_string_template(content, context) 150 139 return html 151 140 -
branches/0.8(django)/PyLucid/system/plugin_manager.py
r1110 r1127 146 146 147 147 output = unbound_method(*url_args, **method_kwargs) 148 148 149 return output 149 150 -
branches/0.8(django)/PyLucid/tools/content_processors.py
r1101 r1127 1 #!/usr/bin/python 2 # -*- coding: UTF-8 -*- 1 3 2 4 """ … … 93 95 94 96 95 def render_string_template(template, context): 96 """ 97 Render a string-template with the given context 98 """ 99 context = Context(context) 100 template = Template(template) 101 html = template.render(context) 102 return html 103 104 def render_template(content, global_context, local_context={}): 97 def render_string_template(content, context): 105 98 """ 106 99 Render a template. 107 1. put all local context items in the global context108 2. render with the merged context109 Note:110 - The local_context are content for a internal page.111 - We merged the local- and global-context together, so every internal112 page can display something from the global context, like page name...113 100 """ 114 global_context.update(local_context) 115 116 html = render_string_template(content, global_context) 117 101 context2 = Context(context) 102 template = Template(content) 103 html = template.render(context2) 118 104 return html