RSS for blog
Comment addition into blog page's dom
This commit is contained in:
parent
1522f5d76b
commit
8c7e76ba44
@ -251,7 +251,7 @@ Total Available Qty: %s
|
|||||||
|
|
||||||
# no need to check for uniqueness, as name is unique
|
# no need to check for uniqueness, as name is unique
|
||||||
|
|
||||||
def get_html(self):
|
def prepare_template_args(self):
|
||||||
import markdown2
|
import markdown2
|
||||||
self.doc.web_description_html = markdown2.markdown(self.doc.description or '',
|
self.doc.web_description_html = markdown2.markdown(self.doc.description or '',
|
||||||
extras=["wiki-tables"])
|
extras=["wiki-tables"])
|
||||||
|
68
erpnext/website/blog.py
Normal file
68
erpnext/website/blog.py
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
import webnotes
|
||||||
|
|
||||||
|
@webnotes.whitelist(allow_guest=True)
|
||||||
|
def get_recent_blog_list(args=None):
|
||||||
|
"""
|
||||||
|
args = {
|
||||||
|
'limit_start': 0,
|
||||||
|
'limit_page_length': 5,
|
||||||
|
'name': '',
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
import webnotes
|
||||||
|
|
||||||
|
if not args: args = webnotes.form_dict
|
||||||
|
|
||||||
|
query = """\
|
||||||
|
select name, title, left(content, 100) as content
|
||||||
|
from tabBlog
|
||||||
|
where ifnull(published,0)=1 and
|
||||||
|
name!=%(name)s order by creation desc"""
|
||||||
|
|
||||||
|
from webnotes.widgets.query_builder import add_limit_to_query
|
||||||
|
query, args = add_limit_to_query(query, args)
|
||||||
|
|
||||||
|
result = webnotes.conn.sql(query, args, as_dict=1)
|
||||||
|
|
||||||
|
# strip html tags from content
|
||||||
|
import webnotes.utils
|
||||||
|
for res in result:
|
||||||
|
res['content'] = webnotes.utils.strip_html(res['content'])
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
@webnotes.whitelist(allow_guest=True)
|
||||||
|
def add_comment(args=None):
|
||||||
|
"""
|
||||||
|
args = {
|
||||||
|
'comment': '',
|
||||||
|
'comment_by': '',
|
||||||
|
'comment_by_fullname': '',
|
||||||
|
'comment_doctype': '',
|
||||||
|
'comment_docname': '',
|
||||||
|
'page_name': '',
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
import webnotes
|
||||||
|
|
||||||
|
if not args: args = webnotes.form_dict
|
||||||
|
|
||||||
|
import webnotes.widgets.form.comments
|
||||||
|
comment = webnotes.widgets.form.comments.add_comment(args)
|
||||||
|
|
||||||
|
# since comments are embedded in the page, clear the web cache
|
||||||
|
import website.web_cache
|
||||||
|
website.web_cache.clear_web_cache(
|
||||||
|
args.get('comment_doctype'), args.get('comment_docname'),
|
||||||
|
args.get('page_name'))
|
||||||
|
|
||||||
|
import webnotes.utils
|
||||||
|
|
||||||
|
comment['comment_date'] = webnotes.utils.pretty_date(comment['creation'])
|
||||||
|
template_args = { 'comment_list': [comment] }
|
||||||
|
|
||||||
|
# get html of comment row
|
||||||
|
comment_html = website.web_cache.build_html(template_args, 'blog/comment.html')
|
||||||
|
|
||||||
|
return comment_html
|
||||||
|
|
@ -34,7 +34,7 @@ class DocType(website.web_page.Page):
|
|||||||
if not webnotes.utils.cint(self.doc.published):
|
if not webnotes.utils.cint(self.doc.published):
|
||||||
self.delete_web_cache(self.doc.page_name)
|
self.delete_web_cache(self.doc.page_name)
|
||||||
|
|
||||||
def get_html(self):
|
def prepare_template_args(self):
|
||||||
import webnotes.utils
|
import webnotes.utils
|
||||||
|
|
||||||
# this is for double precaution. usually it wont reach this code if not published
|
# this is for double precaution. usually it wont reach this code if not published
|
||||||
|
@ -33,5 +33,5 @@ class DocType(website.web_page.Page):
|
|||||||
from webnotes.session_cache import clear_cache
|
from webnotes.session_cache import clear_cache
|
||||||
clear_cache('Guest')
|
clear_cache('Guest')
|
||||||
|
|
||||||
def get_html(self):
|
def prepare_template_args(self):
|
||||||
self.markdown_to_html(['head_section','main_section', 'side_section'])
|
self.markdown_to_html(['head_section','main_section', 'side_section'])
|
@ -15,12 +15,6 @@ def get_product_list(args=None):
|
|||||||
|
|
||||||
if not args: args = webnotes.form_dict
|
if not args: args = webnotes.form_dict
|
||||||
|
|
||||||
# dict to be passed to sql function
|
|
||||||
query_args = {
|
|
||||||
'limit_start': cint(args.get('limit_start')),
|
|
||||||
'limit_page_length': cint(args.get('limit_page_length'))
|
|
||||||
}
|
|
||||||
|
|
||||||
# base query
|
# base query
|
||||||
query = """\
|
query = """\
|
||||||
select name, item_name, page_name, website_image,
|
select name, item_name, page_name, website_image,
|
||||||
@ -40,36 +34,48 @@ def get_product_list(args=None):
|
|||||||
item_name like %(search)s or
|
item_name like %(search)s or
|
||||||
name like %(search)s
|
name like %(search)s
|
||||||
)"""
|
)"""
|
||||||
query_args['search'] = "%" + cstr(args.get('search')) + "%"
|
args['search'] = "%" + cstr(args.get('search')) + "%"
|
||||||
|
|
||||||
# product group condition
|
# product group condition
|
||||||
if args.get('product_group') and args.get('product_group') != 'All Products':
|
if args.get('product_group') and args.get('product_group') != 'All Products':
|
||||||
query += """
|
query += """
|
||||||
and item_group = %(product_group)s"""
|
and item_group = %(product_group)s"""
|
||||||
query_args['product_group'] = args.get('product_group')
|
|
||||||
|
|
||||||
# order by
|
# order by
|
||||||
query += """
|
query += """
|
||||||
order by item_name asc, name asc"""
|
order by item_name asc, name asc"""
|
||||||
|
|
||||||
if args.get('limit_page_length'):
|
from webnotes.widgets.query_builder import add_limit_to_query
|
||||||
query += """
|
query, args = add_limit_to_query(query, args)
|
||||||
limit %(limit_start)s, %(limit_page_length)s"""
|
|
||||||
|
return webnotes.conn.sql(query, args, as_dict=1)
|
||||||
return webnotes.conn.sql(query, query_args, as_dict=1)
|
|
||||||
|
|
||||||
@webnotes.whitelist(allow_guest=True)
|
@webnotes.whitelist(allow_guest=True)
|
||||||
def get_product_category_list():
|
def get_product_category_list(args=None):
|
||||||
|
"""
|
||||||
|
args = {
|
||||||
|
'limit_start': 0,
|
||||||
|
'limit_page_length': 5,
|
||||||
|
}
|
||||||
|
"""
|
||||||
import webnotes
|
import webnotes
|
||||||
|
|
||||||
result = webnotes.conn.sql("""\
|
if not args: args = webnotes.form_dict
|
||||||
|
|
||||||
|
query = """\
|
||||||
select count(name) as items, item_group
|
select count(name) as items, item_group
|
||||||
from `tabItem`
|
from `tabItem`
|
||||||
where is_sales_item = 'Yes'
|
where is_sales_item = 'Yes'
|
||||||
and docstatus = 0
|
and docstatus = 0
|
||||||
and show_in_website = 1
|
and show_in_website = 1
|
||||||
group by item_group
|
group by item_group
|
||||||
order by items desc""", as_dict=1)
|
order by items desc"""
|
||||||
|
|
||||||
|
from webnotes.widgets.query_builder import add_limit_to_query
|
||||||
|
query, args = add_limit_to_query(query, args)
|
||||||
|
|
||||||
|
|
||||||
|
result = webnotes.conn.sql(query, args, as_dict=1)
|
||||||
|
|
||||||
# add All Products link
|
# add All Products link
|
||||||
total_count = sum((r.get('items') or 0 for r in result))
|
total_count = sum((r.get('items') or 0 for r in result))
|
||||||
@ -79,11 +85,19 @@ def get_product_category_list():
|
|||||||
|
|
||||||
@webnotes.whitelist(allow_guest=True)
|
@webnotes.whitelist(allow_guest=True)
|
||||||
def get_similar_product_list(args=None):
|
def get_similar_product_list(args=None):
|
||||||
|
"""
|
||||||
|
args = {
|
||||||
|
'limit_start': 0,
|
||||||
|
'limit_page_length': 5,
|
||||||
|
'product_name': '',
|
||||||
|
'product_group': '',
|
||||||
|
}
|
||||||
|
"""
|
||||||
import webnotes
|
import webnotes
|
||||||
|
|
||||||
if not args: args = webnotes.form_dict
|
if not args: args = webnotes.form_dict
|
||||||
|
|
||||||
result = webnotes.conn.sql("""\
|
query = """\
|
||||||
select name, item_name, page_name, website_image,
|
select name, item_name, page_name, website_image,
|
||||||
description, web_short_description
|
description, web_short_description
|
||||||
from `tabItem`
|
from `tabItem`
|
||||||
@ -92,6 +106,11 @@ def get_similar_product_list(args=None):
|
|||||||
and show_in_website = 1
|
and show_in_website = 1
|
||||||
and name != %(product_name)s
|
and name != %(product_name)s
|
||||||
and item_group = %(product_group)s
|
and item_group = %(product_group)s
|
||||||
order by item_name""", args, as_dict=1)
|
order by item_name"""
|
||||||
|
|
||||||
|
from webnotes.widgets.query_builder import add_limit_to_query
|
||||||
|
query, args = add_limit_to_query(query, args)
|
||||||
|
|
||||||
|
result = webnotes.conn.sql(query, args, as_dict=1)
|
||||||
|
|
||||||
return result
|
return result
|
@ -9,19 +9,17 @@
|
|||||||
<div class="help">By {{ full_name }} on {{ updated }}</div>
|
<div class="help">By {{ full_name }} on {{ updated }}</div>
|
||||||
<br>
|
<br>
|
||||||
{{ content_html }}
|
{{ content_html }}
|
||||||
<hr><h3>Comments</h3>
|
<hr>
|
||||||
<br>
|
<h3>Comments</h3><br>
|
||||||
<div class="blog-comments">
|
<div class="blog-comments">
|
||||||
{% for comment in comment_list %}
|
<div class="no-result help hide">
|
||||||
<div class="comment-row">
|
<p>Be the first one to comment</p>
|
||||||
<div class="comment-title">
|
<br />
|
||||||
{{ comment.comment_by_fullname }} - {{ comment.comment_date }}:
|
|
||||||
{{ comment.comment_date_type }}
|
|
||||||
</div>
|
|
||||||
<p class="comment-content">{{ comment.comment }}</p>
|
|
||||||
<hr>
|
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
|
||||||
|
{% include 'blog/comment.html' %}
|
||||||
|
|
||||||
|
<button class="btn add-comment">Add Comment</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -23,24 +23,16 @@ wn.pages['{{ name }}'].onload = function(wrapper) {
|
|||||||
erpnext.blog.wrapper = wrapper;
|
erpnext.blog.wrapper = wrapper;
|
||||||
|
|
||||||
// sidebar
|
// sidebar
|
||||||
wrapper.recent_list = new wn.ui.Listing({
|
erpnext.blog.render_recent_list(wrapper);
|
||||||
parent: $(wrapper).find('.recent-posts'),
|
|
||||||
no_toolbar: true,
|
// unhide no-result if no comments found
|
||||||
query: 'select name, title, left(content, 100) as content from tabBlog\
|
erpnext.blog.toggle_no_result(wrapper);
|
||||||
where ifnull(published,0)=1 and name!="{{ name }}" order by creation desc',
|
|
||||||
hide_refresh: true,
|
// bind add comment button to comment dialog
|
||||||
render_row: function(parent, data) {
|
erpnext.blog.make_comment_dialog(wrapper);
|
||||||
//console.log(data);
|
|
||||||
if(data.content && data.content.length==100) data.content += '...';
|
// hide add comment button after 50 comments
|
||||||
parent.innerHTML = repl('<a href="%(name)s.html">%(title)s</a>\
|
erpnext.blog.toggle_add_comment_btn(wrapper);
|
||||||
<div class="comment">%(content)s</div><br>', data);
|
|
||||||
|
|
||||||
// adjust page height depending on sidebar height
|
|
||||||
erpnext.blog.adjust_page_height(wrapper);
|
|
||||||
},
|
|
||||||
page_length: 5,
|
|
||||||
});
|
|
||||||
wrapper.recent_list.run();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
erpnext.blog.adjust_page_height = function(wrapper) {
|
erpnext.blog.adjust_page_height = function(wrapper) {
|
||||||
@ -54,52 +46,131 @@ erpnext.blog.adjust_page_height = function(wrapper) {
|
|||||||
$main_page.height($sidebar.height());
|
$main_page.height($sidebar.height());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// wrapper.comment_list = new wn.ui.Listing({
|
|
||||||
// parent: $(wrapper).find('.blog-comments').get(0),
|
|
||||||
// no_toolbar: true,
|
|
||||||
// query: 'select comment, comment_by_fullname, creation\
|
|
||||||
// from `tabComment` where comment_doctype="Page"\
|
|
||||||
// and comment_docname="{{ name }}" order by creation desc',
|
|
||||||
// no_result_message: 'Be the first one to comment',
|
|
||||||
// render_row: function(parent, data) {
|
|
||||||
// data.comment_date = prettyDate(data.creation);
|
|
||||||
// $(parent).html(repl("<div style='color:#777'>\
|
|
||||||
// %(comment_by_fullname)s | %(comment_date)s:\
|
|
||||||
// </div>\
|
|
||||||
// <p style='margin-left: 20px;'>%(comment)s</p><br>", data))
|
|
||||||
// },
|
|
||||||
// hide_refresh: true,
|
|
||||||
// });
|
|
||||||
// wrapper.comment_list.run();
|
|
||||||
//
|
|
||||||
// // add comment
|
|
||||||
// $(wrapper).find('.layout-main-section').append('<br><button class="btn add-comment">\
|
|
||||||
// Add Comment</button>');
|
|
||||||
// $(wrapper).find('button.add-comment').click(function(){
|
|
||||||
// d = new wn.widgets.Dialog({
|
|
||||||
// title: 'Add Comment',
|
|
||||||
// fields: [
|
|
||||||
// {fieldname:'comment_by_fullname', label:'Your Name', reqd:1, fieldtype:'Data'},
|
|
||||||
// {fieldname:'comment_by', label:'Email Id', reqd:1, fieldtype:'Data'},
|
|
||||||
// {fieldname:'comment', label:'Comment', reqd:1, fieldtype:'Text'},
|
|
||||||
// {fieldname:'post', label:'Post', fieldtype:'Button'}
|
|
||||||
// ]
|
|
||||||
// });
|
|
||||||
// d.fields_dict.post.input.onclick = function() {
|
|
||||||
// var btn = this;
|
|
||||||
// var args = d.get_values();
|
|
||||||
// if(!args) return;
|
|
||||||
// args.comment_doctype = 'Page';
|
|
||||||
// args.comment_docname = '{{ name }}';
|
|
||||||
// $(btn).set_working();
|
|
||||||
// $c('webnotes.widgets.form.comments.add_comment', args, function(r) {
|
|
||||||
// $(btn).done_working();
|
|
||||||
// d.hide();
|
|
||||||
// wrapper.comment_list.refresh();
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
// d.show();
|
|
||||||
// })
|
|
||||||
|
|
||||||
|
erpnext.blog.render_recent_list = function(wrapper) {
|
||||||
|
if (!wrapper) { wrapper = erpnext.blog.wrapper; }
|
||||||
|
if (!wrapper) { return; }
|
||||||
|
|
||||||
|
wrapper.recent_list = new wn.ui.Listing({
|
||||||
|
parent: $(wrapper).find('.recent-posts'),
|
||||||
|
no_toolbar: true,
|
||||||
|
method: 'website.blog.get_recent_blog_list',
|
||||||
|
get_args: function() {
|
||||||
|
return { name: '{{ name }}' }
|
||||||
|
},
|
||||||
|
hide_refresh: true,
|
||||||
|
render_row: function(parent, data) {
|
||||||
|
if(data.content && data.content.length>=100) data.content += '...';
|
||||||
|
parent.innerHTML = repl('<a href="%(name)s.html">%(title)s</a>\
|
||||||
|
<div class="comment">%(content)s</div><br>', data);
|
||||||
|
|
||||||
|
// adjust page height depending on sidebar height
|
||||||
|
erpnext.blog.adjust_page_height(wrapper);
|
||||||
|
},
|
||||||
|
page_length: 5,
|
||||||
|
});
|
||||||
|
wrapper.recent_list.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
erpnext.blog.toggle_no_result = function(wrapper) {
|
||||||
|
if (!wrapper) { wrapper = erpnext.blog.wrapper; }
|
||||||
|
if (!wrapper) { return; }
|
||||||
|
|
||||||
|
var $blog_comments = $(wrapper).find('.blog-comments');
|
||||||
|
var $comment_rows = $blog_comments.find('.comment-row');
|
||||||
|
var $no_result = $blog_comments.find('.no-result');
|
||||||
|
if ($comment_rows.length == 0) {
|
||||||
|
$no_result.removeClass('hide');
|
||||||
|
} else {
|
||||||
|
$no_result.addClass('hide');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
erpnext.blog.make_comment_dialog = function(wrapper) {
|
||||||
|
if (!wrapper) { wrapper = erpnext.blog.wrapper; }
|
||||||
|
if (!wrapper) { return; }
|
||||||
|
|
||||||
|
var $comment_btn = $(wrapper).find('button.add-comment');
|
||||||
|
|
||||||
|
$comment_btn.click(function() {
|
||||||
|
if(!erpnext.blog.comment_dialog) {
|
||||||
|
var d = new wn.widgets.Dialog({
|
||||||
|
title: 'Add Comment',
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
fieldname: 'comment_by_fullname', label: 'Your Name',
|
||||||
|
reqd: 1, fieldtype: 'Data'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldname: 'comment_by', label: 'Email Id',
|
||||||
|
reqd: 1, fieldtype: 'Data'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldname: 'comment', label: 'Comment',
|
||||||
|
reqd: 1, fieldtype: 'Text'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldname: 'post_comment', label: 'Post Comment',
|
||||||
|
fieldtype: 'Button'
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
erpnext.blog.comment_dialog = d;
|
||||||
|
}
|
||||||
|
|
||||||
|
erpnext.blog.comment_dialog.fields_dict.post_comment
|
||||||
|
.input.onclick = function() {
|
||||||
|
erpnext.blog.add_comment(wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
erpnext.blog.comment_dialog.show();
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
erpnext.blog.add_comment = function(wrapper) {
|
||||||
|
var args = erpnext.blog.comment_dialog.get_values();
|
||||||
|
|
||||||
|
if(!args) return;
|
||||||
|
|
||||||
|
args.comment_doctype = 'Blog';
|
||||||
|
args.comment_docname = '{{ name }}';
|
||||||
|
args.page_name = '{{ page_name }}';
|
||||||
|
|
||||||
|
wn.call({
|
||||||
|
method: 'website.blog.add_comment',
|
||||||
|
args: args,
|
||||||
|
btn: this,
|
||||||
|
callback: function(r) {
|
||||||
|
if(!r.exc) {
|
||||||
|
erpnext.blog.add_comment_to_page(wrapper, r.message);
|
||||||
|
erpnext.blog.comment_dialog.hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
erpnext.blog.add_comment_to_page = function(wrapper, comment) {
|
||||||
|
$blog_comments = $(wrapper).find('.blog-comments');
|
||||||
|
$comment_rows = $blog_comments.find('.comment-row');
|
||||||
|
|
||||||
|
if ($comment_rows.length) {
|
||||||
|
$comment_rows.last().after(comment);
|
||||||
|
} else {
|
||||||
|
$blog_comments.find('.no-result').after(comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
erpnext.blog.toggle_no_result(wrapper);
|
||||||
|
erpnext.blog.toggle_add_comment_btn(wrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
erpnext.blog.toggle_add_comment_btn = function(wrapper) {
|
||||||
|
var $wrapper = $(wrapper);
|
||||||
|
if ($wrapper.find('.blog-comments .comment-row').length > 50) {
|
||||||
|
var $comment_btn = $wrapper.find('button.add-comment');
|
||||||
|
$comment_btn.addClass('hide');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
14
erpnext/website/templates/blog/comment.html
Normal file
14
erpnext/website/templates/blog/comment.html
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{#
|
||||||
|
this template generates comment rows for a blog
|
||||||
|
it is to be included in the blog/blog.html template
|
||||||
|
#}
|
||||||
|
|
||||||
|
{% for comment in comment_list %}
|
||||||
|
<div class="comment-row">
|
||||||
|
<div class="comment-title">
|
||||||
|
{{ comment.comment_by_fullname }} - {{ comment.comment_date }}:
|
||||||
|
</div>
|
||||||
|
<p class="comment-content">{{ comment.comment }}</p>
|
||||||
|
<hr>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
@ -15,7 +15,7 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
# used by web.py
|
# used by web.py
|
||||||
def load_from_web_cache(page_name, comments, template): #, script=None):
|
def load_from_web_cache(page_name, comments, template):
|
||||||
"""
|
"""
|
||||||
* search for page in cache
|
* search for page in cache
|
||||||
* if html exists, return
|
* if html exists, return
|
||||||
@ -47,30 +47,13 @@ def load_from_web_cache(page_name, comments, template): #, script=None):
|
|||||||
from webnotes.utils import cstr
|
from webnotes.utils import cstr
|
||||||
html += """\n<!-- %s -->""" % cstr(comments)
|
html += """\n<!-- %s -->""" % cstr(comments)
|
||||||
|
|
||||||
# show error in error console
|
|
||||||
# if script: html += """\n\n<script>\n%s\n</script>""" % cstr(script)
|
|
||||||
return html
|
return html
|
||||||
|
|
||||||
def load_into_web_cache(page_name, template, doc_type, doc_name):
|
def load_into_web_cache(page_name, template, doc_type, doc_name):
|
||||||
"""build html and store it in web cache"""
|
"""build html and store it in web cache"""
|
||||||
import webnotes
|
import webnotes
|
||||||
outer_env_dict = get_outer_env()
|
|
||||||
|
|
||||||
if page_name in ['404', 'blog', 'products', 'login-page']:
|
|
||||||
args = outer_env_dict
|
|
||||||
args.update({
|
|
||||||
'name': page_name,
|
|
||||||
})
|
|
||||||
else:
|
|
||||||
if page_name == 'index':
|
|
||||||
page_name, doc_type, doc_name = get_index_page()
|
|
||||||
|
|
||||||
from webnotes.model.code import get_obj
|
args = prepare_args(page_name, doc_type, doc_name)
|
||||||
obj = get_obj(doc_type, doc_name)
|
|
||||||
if hasattr(obj, 'get_html'):
|
|
||||||
obj.get_html()
|
|
||||||
args = obj.doc.fields
|
|
||||||
args.update(outer_env_dict)
|
|
||||||
|
|
||||||
# decide template and update args
|
# decide template and update args
|
||||||
if doc_type == 'Web Page':
|
if doc_type == 'Web Page':
|
||||||
@ -96,6 +79,26 @@ def load_into_web_cache(page_name, template, doc_type, doc_name):
|
|||||||
webnotes.conn.commit()
|
webnotes.conn.commit()
|
||||||
|
|
||||||
return html
|
return html
|
||||||
|
|
||||||
|
def prepare_args(page_name, doc_type, doc_name, with_outer_env=1):
|
||||||
|
if page_name in ['404', 'blog', 'products', 'login-page']:
|
||||||
|
args = {
|
||||||
|
'name': page_name,
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
if page_name == 'index':
|
||||||
|
page_name, doc_type, doc_name = get_index_page()
|
||||||
|
|
||||||
|
from webnotes.model.code import get_obj
|
||||||
|
obj = get_obj(doc_type, doc_name)
|
||||||
|
if hasattr(obj, 'prepare_template_args'):
|
||||||
|
obj.prepare_template_args()
|
||||||
|
args = obj.doc.fields
|
||||||
|
|
||||||
|
outer_env_dict = with_outer_env and get_outer_env() or {}
|
||||||
|
args.update(outer_env_dict)
|
||||||
|
|
||||||
|
return args
|
||||||
|
|
||||||
def build_html(args, template):
|
def build_html(args, template):
|
||||||
"""build html using jinja2 templates"""
|
"""build html using jinja2 templates"""
|
||||||
|
@ -55,12 +55,6 @@ def get_html(page_name):
|
|||||||
'comments': """error: %s""" % traceback,
|
'comments': """error: %s""" % traceback,
|
||||||
'template': '404.html',
|
'template': '404.html',
|
||||||
}
|
}
|
||||||
# 'script': """(function() {
|
|
||||||
# var error = "ERROR: %s";
|
|
||||||
# console.log(error);
|
|
||||||
# })();""" % traceback.replace('"', '\\"').replace('\n', ' \\\n'),
|
|
||||||
# }
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
args = {
|
args = {
|
||||||
'comments': """page: %s""" % page_name,
|
'comments': """page: %s""" % page_name,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user