Changeset 2037
- Timestamp:
- 06/17/09 09:19:14 (9 months ago)
- Location:
- branches/0.9/pylucid_project
- Files:
-
- 2 added
- 12 modified
-
apps/pylucid/defaulttags/extraheadBlock.py (modified) (2 diffs)
-
apps/pylucid/shortcuts.py (added)
-
apps/pylucid/system/extrahead.py (added)
-
apps/pylucid/system/pylucid_objects.py (modified) (2 diffs)
-
media/PyLucid/pylucid_js_tools.js (modified) (1 diff)
-
pylucid_plugins/admin_menu/templates/admin_menu/admin_top_menu.html (modified) (2 diffs)
-
pylucid_plugins/admin_menu/views.py (modified) (1 diff)
-
pylucid_plugins/auth/templates/auth/input_username.html (modified) (1 diff)
-
pylucid_plugins/auth/templates/auth/login_link.html (modified) (1 diff)
-
pylucid_plugins/auth/templates/auth/logout_link.html (modified) (1 diff)
-
pylucid_plugins/auth/views.py (modified) (9 diffs)
-
pylucid_plugins/extrahead/context_middleware.py (modified) (3 diffs)
-
pylucid_plugins/page_admin/templates/page_admin/edit_page_form.html (modified) (2 diffs)
-
pylucid_plugins/page_admin/views.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/0.9/pylucid_project/apps/pylucid/defaulttags/extraheadBlock.py
r2022 r2037 6 6 7 7 Simple django template block tag. "Redirect" extra head content 8 into pylucid_plugin.head_files.context_middleware 8 into request.PYLUCID.extrahead 9 This data would be inserted with pylucid_plugin.extrahead.context_middleware 9 10 10 11 PyLucid plugins should use {% extrahead %} block tag in plugin template for … … 40 41 raise RuntimeError("Plugin must use RequestContext() or request.PYLUCID.context !") 41 42 42 head_files = request.PYLUCID.context["context_middlewares"]["extrahead"]43 head_files.add_content(output)43 extrahead = request.PYLUCID.extrahead 44 extrahead.append(output) 44 45 return u"" -
branches/0.9/pylucid_project/apps/pylucid/system/pylucid_objects.py
r2027 r2037 1 1 # coding:utf-8 2 2 3 """ 4 PyLucid objects 5 ~~~~~~~~~~~~~~~ 6 7 Some need full objects attached to the current request object in pylucid.views. 8 9 see also: http://www.pylucid.org/_goto/187/PyLucid-objects/ 10 11 Last commit info: 12 ~~~~~~~~~~~~~~~~~ 13 $LastChangedDate: $ 14 $Rev: $ 15 $Author: $ 16 17 :copyleft: 2009 by the PyLucid team, see AUTHORS for more details. 18 :license: GNU GPL v3 or above, see LICENSE for more details. 19 """ 20 3 21 from pylucid.models import Language 22 from pylucid.system import extrahead 4 23 from pylucid.preference_forms import SystemPreferencesForm 5 24 6 25 class PyLucidRequestObjects(object): 7 """ 8 PyLucid request objects 9 see also: http://www.pylucid.org/_goto/187/PyLucid-objects/ 10 """ 26 """ PyLucid request objects """ 11 27 def __init__(self): 12 28 self.system_preferences = SystemPreferencesForm().get_preferences() … … 14 30 self.default_lang_code = default_lang_code 15 31 self.default_lang_entry = Language.objects.get(code=default_lang_code) 32 33 # Storing extra html head code from plugins, used in: 34 # pylucid.defaulttags.extraheadBlock - redirect {% extrahead %} block tag content 35 # pylucid_plugin.extrahead.context_middleware - insert the data into the global page 36 self.extrahead = extrahead.ExtraHead() 37 16 38 # objects witch will be set later: 17 39 #self.pagetree - The current PageTree model instance -
branches/0.9/pylucid_project/media/PyLucid/pylucid_js_tools.js
r2034 r2037 16 16 17 17 18 function pylucid_ajax_form_view(form_id) { 19 /************************************************************************* 20 PyLucid ajax form view. 21 22 Don't send the form and get a complete new rendered page. Send the form 23 via ajax post and replace the #page_content with the html response. 24 25 usage e.g.: 26 ---------------------------------------------------------------------- 27 $(document).ready(function(){ 28 // simply bind the form with the id: 29 pylucid_ajax_form_view('#form_id'); 30 }); 31 ---------------------------------------------------------------------- 32 *************************************************************************/ 33 $(form_id).bind('submit', function() { 34 35 $("#page_content").html('<h2>loading...</h2>'); 36 $("#page_content").animate({opacity: 0.3}, 500 ); 37 38 var form = $(this); 39 var form_data = form.serialize(); 40 log("form data:" + form_data); 41 42 var url = encodeURI(form.attr('action')); 43 log("send form to url:" + url); 44 45 var load_normal_link = true; 46 47 $.ajax({ 48 async: false, 49 type: "POST", 50 url: url, 51 data: form_data, 52 dataType: "html", 53 54 success: function(form_html){ 55 log("ajax post response success."); 56 $("#page_content").html(form_html); 57 $("#page_content").animate({opacity: 1}, 500 ); 58 load_normal_link = false; 59 }, 60 error: function(XMLHttpRequest){ 61 log("ajax get response error!"); 62 // Display the complete Traceback html page 63 log(XMLHttpRequest); 64 var response_text = XMLHttpRequest.responseText; 65 log("response_text: '" + response_text + "'"); 66 if (!response_text) { 67 document.write("<h1>ajax response error</h1>"); 68 } else { 69 document.write(response_text); 70 } 71 load_normal_link = true; 72 } 73 }); 74 return load_normal_link; // <-- important: Don't send the form in normal way. 75 }); 76 } 77 78 18 79 19 80 function get_pylucid_ajax_view(url) { 20 81 /************************************************************************* 21 PyLucid ajax replace function 22 23 usage e.g.: 24 ---------------------------------------------------------------------- 25 $(document).ready(function(){ 26 $("#link_id").click(function(){ 27 return get_pylucid_ajax_view("{{ ajax_get_view_url }}"); 28 }); 82 PyLucid ajax get view replace. 83 84 Don't render the complete page again. Simply get the new content via ajax 85 and replace #page_content with it. 86 87 usage e.g.: 88 ---------------------------------------------------------------------- 89 $(document).ready(function(){ 90 $("#link_id").click(function(){ 91 return get_pylucid_ajax_view("{{ ajax_get_view_url }}"); 29 92 }); 30 ---------------------------------------------------------------------- 31 or: 32 ---------------------------------------------------------------------- 33 <a href="{{ url }}" onclick="return get_pylucid_ajax_view('{{ ajax_url }}');">foo</a> 34 ---------------------------------------------------------------------- 93 }); 94 ---------------------------------------------------------------------- 95 or: 96 ---------------------------------------------------------------------- 97 <a href="{{ url }}" onclick="return get_pylucid_ajax_view('{{ ajax_url }}');">foo</a> 98 ---------------------------------------------------------------------- 35 99 *************************************************************************/ 36 100 $("#page_content").html('<h2>loading...</h2>'); -
branches/0.9/pylucid_project/pylucid_plugins/admin_menu/templates/admin_menu/admin_top_menu.html
r2034 r2037 9 9 <script type="text/javascript" src="{{ PyLucid_media_url }}superfish/superfish.js" onerror="JavaScript:alert('{{ PyLucid_media_url }}superfish/superfish.js');" ></script> 10 10 <script type="text/javascript" src="{{ PyLucid_media_url }}superfish/pylucid_superfish_init.js" onerror="JavaScript:alert('{{ PyLucid_media_url }}superfish/pylucid_superfish_init.js');" ></script> 11 <script type="text/javascript" src="{{ PyLucid_media_url }}pylucid_js_tools.js" onerror="JavaScript:alert('{{ PyLucid_media_url }}pylucid_js_tools.js');" ></script>12 11 <style type="text/css"> 13 12 <!-- … … 26 25 <li class="current">{% lucidTag auth %}</li> 27 26 <li> 28 <li><a href="{{ edit_page_link }}" title="edit inline" id="edit_page" onclick="return get_pylucid_ajax_view('{{ edit_page_ ajax}}');">{% trans 'edit page' %}</a></li>27 <li><a href="{{ edit_page_link }}" title="edit inline" id="edit_page" onclick="return get_pylucid_ajax_view('{{ edit_page_link }}');">{% trans 'edit page' %}</a></li> 29 28 <ul> 30 29 <li><a href="{{ edit_admin_panel_link }}">edit in admin panel</a></li> -
branches/0.9/pylucid_project/pylucid_plugins/admin_menu/views.py
r2029 r2037 31 31 32 32 "edit_page_link": "?page_admin=inline_edit", 33 "edit_page_ajax": "?page_admin=get_ajax_form",34 33 35 34 "edit_admin_panel_link": edit_admin_panel_link, -
branches/0.9/pylucid_project/pylucid_plugins/auth/templates/auth/input_username.html
r2034 r2037 2 2 3 3 {% block plugin_content %} 4 {# We can't use extrahead block here, because it's used in ajax view, too. #} 4 5 {% extrahead %} 5 6 <script type="text/javascript"> 6 7 7 $(document).ready(function(){ 8 8 log("input username ready"); 9 9 $("#id_username").focus(); 10 10 11 $('#username_form').bind('submit', function() { 12 // get the input password form via ajax 13 $("#page_content").html('<h2>loading...</h2>'); 14 $("#page_content").animate({opacity: 0.3}, 500 ); 15 16 log("continue login..."); 17 18 var form = $(this); 19 var form_data = form.serialize(); 20 log("form data:" + form_data); 21 22 var url = encodeURI(form.attr('action')); 23 log("form url:" + url); 24 25 $.post(url, form_data, 26 function(form_html){ 27 log("ajax get success."); 28 $("#page_content").html(form_html); 29 $("#page_content").animate({opacity: 1}, 500 ); 30 } 31 ); 32 33 return false; // <-- important! 34 }); 11 pylucid_ajax_form_view('#username_form'); // send username form and get the input password form via ajax 35 12 }); 36 13 </script> 14 {% endextrahead %} 37 15 38 16 <fieldset><legend>PyLucid <a href="http://www.pylucid.org/_goto/8/JS-SHA-Login/" title="What is the PyLucid JS-SHA-LogIn?">JS-SHA-LogIn</a> - step 1</legend> -
branches/0.9/pylucid_project/pylucid_plugins/auth/templates/auth/login_link.html
r2034 r2037 2 2 3 3 {% block plugin_content %} 4 <a href="{{ login_url }}" id="login_link" onclick="return get_pylucid_ajax_view('{{ login_url_ajax}}');">{% trans 'Log in' %}</a>4 <a href="{{ url }}" id="login_link" onclick="return get_pylucid_ajax_view('{{ url }}');">{% trans 'Log in' %}</a> 5 5 {% endblock %} -
branches/0.9/pylucid_project/pylucid_plugins/auth/templates/auth/logout_link.html
r2034 r2037 1 <a href="{{ logout_url }}">{% trans 'Log out' %} [{{ request.user.username }}]</a>1 <a href="{{ url }}">{% trans 'Log out' %} [{{ request.user.username }}]</a> -
branches/0.9/pylucid_project/pylucid_plugins/auth/views.py
r2034 r2037 5 5 from django.template import RequestContext 6 6 from django.http import HttpResponseRedirect 7 from django.shortcuts import render_to_response8 7 from django.utils.translation import ugettext as _ 9 8 from django.template.loader import render_to_string 9 10 from pylucid.shortcuts import render_pylucid_response 10 11 11 12 from pylucid_project.utils import crypt … … 25 26 26 27 28 29 30 27 31 def lucidTag(request): 28 # TODO: Use internal SHA-Login plugin views, if implemented:32 """ Create login/logout link """ 29 33 if request.user.is_authenticated(): 30 34 # admin_logout reverse is still broken in django, see: … … 34 38 #url = reverse("admin_index") + "logout/" # TODO: Update this if django is bugfixed 35 39 template_name = "auth/logout_link.html" 36 context = {"logout_url": "?auth=logout"}40 url = "?auth=logout" 37 41 else: 38 42 template_name = "auth/login_link.html" 39 #url = reverse("admin_index") # django admin panel index page 40 context = { 41 "login_url": "?auth=login", 42 "login_url_ajax": "?auth=get_login_form", 43 } 44 45 return render_to_string(template_name, context, context_instance=RequestContext(request)) 43 url = "?auth=login" 44 45 return render_to_string(template_name, {"url": url}, context_instance=RequestContext(request)) 46 46 47 47 … … 66 66 67 67 68 def _plaintext_login(request, context, username, next_url , render_function):68 def _plaintext_login(request, context, username, next_url): 69 69 """ input the password and login if auth ok """ 70 70 if "password" in request.POST: … … 79 79 80 80 # return a string for replacing the normal cms page content 81 return render_ function('auth/plaintext_login.html', context)82 83 84 85 def _sha_login(request, context, user, next_url , render_function):81 return render_pylucid_response(request, 'auth/plaintext_login.html', context) 82 83 84 85 def _sha_login(request, context, user, next_url): 86 86 """ 87 87 Login via JS-SHA-Login. … … 145 145 146 146 # return a string for replacing the normal cms page content 147 return render_function('auth/input_password.html', context, context_instance=RequestContext(request)) 148 149 150 def _login_view(request, form_url, next_url, render_function): 147 return render_pylucid_response(request, 'auth/input_password.html', context, 148 context_instance=RequestContext(request) 149 ) 150 151 152 def _login_view(request, form_url, next_url): 151 153 if DEBUG: 152 154 request.page_msg( … … 168 170 169 171 if "plaintext_login" in request.POST: 170 return _plaintext_login(request, context, user.username, next_url , render_function)172 return _plaintext_login(request, context, user.username, next_url) 171 173 else: 172 return _sha_login(request, context, user, next_url , render_function)174 return _sha_login(request, context, user, next_url) 173 175 else: 174 176 username_form = UsernameForm() … … 177 179 178 180 # return a string for replacing the normal cms page content 179 return render_ function('auth/input_username.html', context)181 return render_pylucid_response(request, 'auth/input_username.html', context) 180 182 181 183 … … 185 187 """ 186 188 next_url = request.path 187 # import time188 # time.sleep(0.5)189 189 action = request.GET["auth"] 190 190 if action=="login": 191 191 form_url = request.path + "?auth=login" # FIXME: How can we add the GET Parameter? 192 return _login_view(request, form_url, next_url, render_function=render_to_string) 193 elif action=="get_login_form": 194 form_url = request.path + "?auth=get_login_form" # FIXME: How can we add the GET Parameter? 195 return _login_view(request, form_url, next_url, render_function=render_to_response) 192 return _login_view(request, form_url, next_url) 196 193 elif action=="logout": 197 194 return _logout_view(request, next_url) -
branches/0.9/pylucid_project/pylucid_plugins/extrahead/context_middleware.py
r2034 r2037 5 5 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 6 6 7 Stores extra html head content via PyLucid context middleware.8 It's used by pylucid.defaulttags.extraheadBlock.7 replace <!-- ContextMiddleware extrahead --> in the global page template with 8 all extra head html code, stored in request.PYLUCID.extrahead (pylucid.system.extrahead) 9 9 10 PyLucid plugins should use {% extrahead %} block tag in plugin template for 11 insert e.g. CSS/JS file links into html head. 10 Add all headfile links from pagetree.design.headfiles m2m. 11 12 PyLucid plugins should use {% extrahead %} block tag (pylucid.defaulttags.extraheadBlock) 13 in plugin template for insert e.g. CSS/JS file links into html head. 12 14 13 15 Last commit info: … … 29 31 30 32 31 FILEPATH_SPLIT = "pylucid_project"32 33 SKIP_MODULES = [34 os.path.join("django", "template"),35 os.path.join("django", "shortcuts"),36 os.path.join("extrahead", "context_middleware")37 ]38 39 DEBUG_INFO = """\40 <!-- extrahead from %(fileinfo)s - START -->41 %(content)s42 <!-- extrahead from %(fileinfo)s - END -->"""43 44 45 33 class ContextMiddleware(object): 46 """ 47 Simple store extra html head content from plugins. 48 """ 34 """ replace <!-- ContextMiddleware extrahead --> in the global page template """ 49 35 def __init__(self, request, context): 50 36 self.request = request 51 if settings.DEBUG: 52 # Turn debug mode in JavaScript on 53 self.data = DEBUG_INFO % { 54 "fileinfo": os.path.basename(__file__), 55 "content": '<script type="text/javascript">var debug=true;log("debug is on");</script>' 56 } 57 self.data += "\n" 58 else: 59 self.data = "" 60 61 def add_content(self, content): 62 content = content.strip() 63 if settings.DEBUG: 64 # Add debug info around content. 65 fileinfo = self._get_fileinfo() 66 content = DEBUG_INFO % {"fileinfo": fileinfo, "content": content} 67 68 self.data += content + "\n" 69 37 self.extrahead = request.PYLUCID.extrahead # pylucid.system.extrahead 38 70 39 def _add_pagetree_headfiles(self): 40 """ add all headfile links used in the current design. """ 71 41 pagetree = self.request.PYLUCID.pagetree 72 42 design = pagetree.design … … 74 44 headfiles = design.headfiles.all() 75 45 76 headfilelinks = []77 46 for headfile in headfiles: 78 47 # Get a instance from pylucid.system.headfile.HeadfileLink(): 79 48 headfilelink = headfile.get_headfilelink() 80 49 head_tag = headfilelink.get_head_tag() 81 headfilelinks.append(head_tag) 82 83 self.add_content("\n".join(headfilelinks)) 50 self.extrahead.append(head_tag) 84 51 85 52 def render(self): 53 """ return all extra head content with all headfiles from current used design """ 86 54 self._add_pagetree_headfiles() 87 return self.data 88 89 def _get_fileinfo(self): 90 """ 91 return fileinfo: Where from the announcement comes? 92 """ 93 def skip(filepath): 94 for ignore_path in SKIP_MODULES: 95 if ignore_path in filepath: 96 return True 97 return False 98 99 try: 100 fileinfo = [] 101 step = 0 102 for stack_frame in inspect.stack(): 103 filepath = stack_frame[1] 104 lineno = stack_frame[2] 55 return "\n".join(self.extrahead) 105 56 106 if skip(filepath) or FILEPATH_SPLIT not in filepath:107 continue108 109 filepath = "..." + filepath.split(FILEPATH_SPLIT,1)[1]110 111 fileinfo.append("%s line %s" % (filepath, lineno))112 if step>=1:113 break114 step += 1115 return " | ".join(fileinfo)116 except Exception, e:117 return "(inspect Error: %s)" % e -
branches/0.9/pylucid_project/pylucid_plugins/page_admin/templates/page_admin/edit_page_form.html
r2034 r2037 1 1 {% extends "pylucid/css_anchor_div.html" %} 2 2 3 3 4 {% block plugin_content %} 4 5 5 { # We can't use extrahead block here, because it's used in ajax view, too. #}6 {% extrahead %} 6 7 <script type="text/javascript"> 7 8 $(document).ready(function(){ 8 9 $("#preview_fieldset").hide(); 9 10 11 pylucid_ajax_form_view('#edit_page_form'); 12 10 13 $("#preview").click(function() { 11 14 $("#edit_page_preview").html("<h2>loading...</h2>"); … … 22 25 23 26 }); 24 return false; // The browser submit the form, if true27 return false; // <-- important: Don't send the form in normal way. 25 28 }); 26 29 }); 27 30 </script> 31 {% endextrahead %} 28 32 29 33 <fieldset id="preview_fieldset"> -
branches/0.9/pylucid_project/pylucid_plugins/page_admin/views.py
r2034 r2037 5 5 from django.conf import settings 6 6 from django.template import RequestContext 7 from django.shortcuts import render_to_response8 7 from django.utils.translation import ugettext as _ 9 8 from django.core.exceptions import PermissionDenied 10 from django.template.loader import render_to_string11 9 from django.http import HttpResponse, HttpResponseRedirect 12 10 13 11 from pylucid.markup.converter import apply_markup 12 from pylucid.shortcuts import render_pylucid_response 14 13 15 14 from page_admin.forms import EditPageForm … … 35 34 36 35 37 def _edit_page(request, render_function):36 def _edit_page(request, form_url): 38 37 check_permissions(request, EDIT_PERMISSIONS) 39 38 … … 53 52 54 53 context = { 55 "form_url": "%s?page_admin=inline_edit" % request.path,54 "form_url": form_url, 56 55 "abort_url": request.path, 57 56 "preview_url": "%s?page_admin=preview" % request.path, … … 64 63 "pagemeta_instance": pagemeta_instance, 65 64 } 66 return render_ function('page_admin/edit_page_form.html', context,65 return render_pylucid_response(request, 'page_admin/edit_page_form.html', context, 67 66 context_instance=RequestContext(request) 68 67 ) … … 89 88 if action=="inline_edit": 90 89 # replace the page content with the edit page form 91 return _edit_page(request, render_function=render_to_string) 92 elif action=="get_ajax_form": 93 # return the edit page form only, for inserting it via jQuery 94 return _edit_page(request, render_function=render_to_response) 90 form_url = "%s?page_admin=inline_edit" % request.path 91 return _edit_page(request, form_url) 95 92 elif action=="preview": 96 93 # preview via jQuery