瀏覽代碼

Call render_blocks automatically

version-14
Anand Doshi 11 年之前
父節點
當前提交
1d64cd32fb
共有 21 個檔案被更改,包括 50 行新增75 行删除
  1. +2
    -1
      webnotes/__init__.py
  2. +1
    -1
      webnotes/core/doctype/communication/communication.py
  3. +2
    -0
      webnotes/core/doctype/profile/profile.py
  4. +2
    -4
      webnotes/templates/generators/blog_post.py
  5. +2
    -3
      webnotes/templates/generators/web_page.py
  6. +1
    -8
      webnotes/templates/generators/website_group.html
  7. +2
    -2
      webnotes/templates/generators/website_group.py
  8. +8
    -0
      webnotes/templates/includes/breadcrumbs.html
  9. +2
    -2
      webnotes/templates/includes/sidebar.html
  10. +0
    -8
      webnotes/templates/pages/404.py
  11. +1
    -7
      webnotes/templates/pages/about.py
  12. +2
    -2
      webnotes/templates/pages/app.html
  13. +1
    -4
      webnotes/templates/pages/blog.py
  14. +1
    -5
      webnotes/templates/pages/contact.py
  15. +1
    -5
      webnotes/templates/pages/error.py
  16. +0
    -5
      webnotes/templates/pages/login.py
  17. +1
    -3
      webnotes/templates/pages/message.py
  18. +0
    -6
      webnotes/templates/pages/update_password.py
  19. +1
    -3
      webnotes/templates/pages/writers.py
  20. +2
    -1
      webnotes/translate.py
  21. +18
    -5
      webnotes/webutils.py

+ 2
- 1
webnotes/__init__.py 查看文件

@@ -563,7 +563,8 @@ def get_jenv():
jenv.globals.update({
"webnotes": sys.modules[__name__],
"webnotes.utils": webnotes.utils
"webnotes.utils": webnotes.utils,
"_": _
})
return jenv


+ 1
- 1
webnotes/core/doctype/communication/communication.py 查看文件

@@ -12,7 +12,7 @@ from webnotes.utils.email_lib.email_body import get_email
from webnotes.utils.email_lib.smtp import send

class DocType():
def __init__(self, doc, doclist=[]):
def __init__(self, doc, doclist=None):
self.doc = doc
self.doclist = doclist


+ 2
- 0
webnotes/core/doctype/profile/profile.py 查看文件

@@ -305,6 +305,8 @@ def update_password(new_password, key=None, old_password=None):
webnotes.conn.set_value("Profile", user, "reset_password_key", "")
webnotes.local.login_manager.logout()
return _("Password Updated")
@webnotes.whitelist(allow_guest=True)


+ 2
- 4
webnotes/templates/generators/blog_post.py 查看文件

@@ -6,13 +6,12 @@ from __future__ import unicode_literals
import markdown2
import webnotes
from webnotes.utils import global_date_format, get_fullname, cint
from webnotes.webutils import render_blocks

doctype = "Blog Post"
condition_field = "published"

def get_context(context):
blog_post = webnotes.doc(context.ref_doctype, context.docname)
blog_post = context.bean.doc
# this is for double precaution. usually it wont reach this code if not published
if not cint(blog_post.published):
@@ -35,9 +34,8 @@ def get_context(context):
from `tabComment` where comment_doctype="Blog Post"
and comment_docname=%s order by creation""", (blog_post.name,), as_dict=1) or []
blog_post.fields.update(context)
return render_blocks(blog_post.fields)
return blog_post.fields
@webnotes.whitelist(allow_guest=True)
def get_blog_list(start=0, by=None, category=None):


+ 2
- 3
webnotes/templates/generators/web_page.py 查看文件

@@ -3,14 +3,13 @@

from __future__ import unicode_literals
import webnotes
from webnotes.webutils import render_blocks
from webnotes.website.doctype.website_slideshow.website_slideshow import get_slideshow

doctype = "Web Page"
condition_field = "published"

def get_context(context):
web_page = webnotes.bean(context.ref_doctype, context.docname)
web_page = context.bean
if web_page.doc.slideshow:
web_page.doc.fields.update(get_slideshow(web_page))
@@ -36,7 +35,7 @@ def get_context(context):
web_page.doc.fields.update(context)
return render_blocks(web_page.doc.fields)
return web_page.doc.fields
def get_breadcrumbs(web_page):
breadcrumbs = []


+ 1
- 8
webnotes/templates/generators/website_group.html 查看文件

@@ -7,14 +7,7 @@
{%- endif -%}
{% endblock %}

{% block breadcrumbs %}
<ul class="breadcrumb">
{% for parent in parents %}
<li><a href="/{{ parent.name|lower }}">{{ parent.page_title }}</a></li>
{% endfor %}
<li class="active">{{ title }}</li>
</ul>
{% endblock %}
{% block breadcrumbs %}{% include "templates/includes/breadcrumbs.html" %}{% endblock %}

{% block content %}
<ul class="nav nav-tabs view-selector">


+ 2
- 2
webnotes/templates/generators/website_group.py 查看文件

@@ -2,7 +2,7 @@
# MIT License. See license.txt

import webnotes
from webnotes.webutils import get_access, render_blocks, can_cache
from webnotes.webutils import get_access, can_cache
from webnotes.templates.website_group.post import clear_post_cache

doctype = "Website Group"
@@ -20,7 +20,7 @@ def get_context(context):
group_context["access"] = get_access(group)
group_context.update(context)
return render_blocks(group_context)
return group_context
except webnotes.DoesNotExistError:
return {


+ 8
- 0
webnotes/templates/includes/breadcrumbs.html 查看文件

@@ -0,0 +1,8 @@
{% if parents -%}
<ul class="breadcrumb">
{% for parent in parents %}
<li><a href="/{{ parent.name|lower }}">{{ parent.page_title }}</a></li>
{% endfor %}
<li class="active">{{ title }}</li>
</ul>
{%- endif %}

+ 2
- 2
webnotes/templates/includes/sidebar.html 查看文件

@@ -1,4 +1,4 @@
{%- if children -%}
{% if children -%}
{%- for child in children -%}
<div class="sidebar-item">
<a href="/{{ child.name|lower }}" class="no-decoration">
@@ -9,4 +9,4 @@
</a>
</div>
{%- endfor -%}
{%- endif -%}
{%- endif %}

+ 0
- 8
webnotes/templates/pages/404.py 查看文件

@@ -1,12 +1,4 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals

import webnotes
from webnotes.webutils import render_blocks

no_sitemap = 1

def get_context(context):
return render_blocks(context)

+ 1
- 7
webnotes/templates/pages/about.py 查看文件

@@ -3,12 +3,6 @@

from __future__ import unicode_literals
import webnotes
from webnotes.webutils import render_blocks

def get_context(context):
about_context = {
"obj": webnotes.bean("About Us Settings", "About Us Settings").get_controller()
}
about_context.update(context)
return render_blocks(about_context)
return { "obj": webnotes.bean("About Us Settings", "About Us Settings").get_controller() }

+ 2
- 2
webnotes/templates/pages/app.html 查看文件

@@ -14,7 +14,7 @@
</div>
<footer></footer>
{% for include in include_css -%}
<link type="text/css" rel="stylesheet" href="{{ include }}">
<link type="text/css" rel="stylesheet" href="{{ include | scrub_relative_url }}">
{%- endfor -%}
<script type="text/javascript" src="/assets/webnotes/js/lib/jquery/jquery.min.js"></script>
<script type="text/javascript">
@@ -24,6 +24,6 @@
</script>

{% for include in include_js -%}
<script type="text/javascript" src="{{ include }}"></script>
<script type="text/javascript" src="{{ include | scrub_relative_url }}"></script>
{%- endfor -%}
</body>

+ 1
- 4
webnotes/templates/pages/blog.py 查看文件

@@ -3,9 +3,6 @@

from __future__ import unicode_literals
import webnotes
from webnotes.webutils import render_blocks

def get_context(context):
blog_context = webnotes.doc("Blog Settings", "Blog Settings").fields
blog_context.update(context)
return render_blocks(blog_context)
return webnotes.doc("Blog Settings", "Blog Settings").fields

+ 1
- 5
webnotes/templates/pages/contact.py 查看文件

@@ -5,7 +5,6 @@ from __future__ import unicode_literals

import webnotes
from webnotes.utils import now
from webnotes.webutils import render_blocks

def get_context(context):
bean = webnotes.bean("Contact Us Settings", "Contact Us Settings")
@@ -15,16 +14,13 @@ def get_context(context):
address = webnotes.bean("Address", bean.doc.address).doc if bean.doc.address else None
contact_context = {
return {
"query_options": query_options,
"address": address,
"heading": bean.doc.heading,
"introduction": bean.doc.introduction
}
contact_context.update(context)
return render_blocks(contact_context)

max_communications_per_hour = 300

@webnotes.whitelist(allow_guest=True)


+ 1
- 5
webnotes/templates/pages/error.py 查看文件

@@ -3,13 +3,9 @@

from __future__ import unicode_literals
import webnotes
from webnotes.webutils import render_blocks

no_cache = 1
no_sitemap = 1

def get_context(context):
error_context = {"error": webnotes.get_traceback()}
error_context.update(context)
return render_blocks(error_context)
return {"error": webnotes.get_traceback()}

+ 0
- 5
webnotes/templates/pages/login.py 查看文件

@@ -1,5 +0,0 @@
import webnotes
from webnotes.webutils import render_blocks

def get_context(context):
return render_blocks(context)

+ 1
- 3
webnotes/templates/pages/message.py 查看文件

@@ -3,7 +3,6 @@

from __future__ import unicode_literals
import webnotes
from webnotes.webutils import render_blocks

no_cache = 1
no_sitemap = 1
@@ -16,5 +15,4 @@ def get_context(context):
if hasattr(webnotes.local, "message_success"):
message_context["success"] = webnotes.local.message_success
message_context.update(context)
return render_blocks(message_context)
return message_context

+ 0
- 6
webnotes/templates/pages/update_password.py 查看文件

@@ -1,10 +1,4 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals
from webnotes.webutils import render_blocks

no_sitemap = 1

def get_context(context):
return render_blocks(context)

+ 1
- 3
webnotes/templates/pages/writers.py 查看文件

@@ -3,7 +3,6 @@

from __future__ import unicode_literals
import webnotes
from webnotes.webutils import render_blocks

def get_context(context):
bloggers = webnotes.conn.sql("""select * from `tabBlogger`
@@ -19,6 +18,5 @@ def get_context(context):
}
writers_context.update(webnotes.doc("Blog Settings", "Blog Settings").fields)
writers_context.update(context)
return render_blocks(writers_context)
return writers_context

+ 2
- 1
webnotes/translate.py 查看文件

@@ -21,7 +21,8 @@ import webnotes, os, re, codecs, json
def get_user_lang(user=None):
if not user:
user = webnotes.session.user
return get_lang_dict().get(webnotes.conn.get_value("Profile", user, "language") or "english")
user_lang = webnotes.conn.get_value("Profile", user, "language")
return get_lang_dict().get(user_lang!="Loading..." and user_lang or "english")

def get_all_languages():
return [a.split()[0] for a in get_lang_info()]


+ 18
- 5
webnotes/webutils.py 查看文件

@@ -128,6 +128,9 @@ def build_sitemap_options(page_name):
"page_name_field", "condition_field"):
sitemap_options[fieldname] = sitemap_config.get(fieldname)
sitemap_options.doctype = sitemap_options.ref_doctype
sitemap_options.title = sitemap_options.page_title
# establish hierarchy
sitemap_options.parents = webnotes.conn.sql("""select name, page_title from `tabWebsite Sitemap`
where lft < %s and rgt > %s order by lft asc""", (sitemap_options.lft, sitemap_options.rgt), as_dict=True)
@@ -143,14 +146,24 @@ def build_sitemap_options(page_name):
def build_context(sitemap_options):
"""get_context method of bean or module is supposed to render content templates and push it into context"""
context = webnotes._dict({ "_": webnotes._ })
context.update(sitemap_options)
context = webnotes._dict(sitemap_options)
context.update(get_website_settings())
if sitemap_options.get("controller"):
module = webnotes.get_module(sitemap_options.get("controller"))
# provide bean
if context.doctype and context.docname:
context.bean = webnotes.bean(context.doctype, context.docname)
if context.controller:
module = webnotes.get_module(context.controller)
if module and hasattr(module, "get_context"):
context.data = module.get_context(context) or {}
context.update(module.get_context(context) or {})
if context.get("base_template_path") != context.get("template_path") and not context.get("rendered"):
context.data = render_blocks(context)
# remove bean, as it is not pickle friendly and its purpose is over
if context.bean:
del context["bean"]
return context


Loading…
取消
儲存