From f01059fd3e039778cc6d611c948a519d6af40959 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Fri, 13 Jul 2012 00:46:59 +0530 Subject: [PATCH] fixes in blog list --- erpnext/website/blog.py | 60 +++++++++++++++++++++++++++- erpnext/website/doctype/blog/blog.py | 2 +- erpnext/website/templates/js/blog.js | 13 +----- 3 files changed, 62 insertions(+), 13 deletions(-) diff --git a/erpnext/website/blog.py b/erpnext/website/blog.py index 0c287ad1a1..8c367fefd0 100644 --- a/erpnext/website/blog.py +++ b/erpnext/website/blog.py @@ -1,5 +1,44 @@ import webnotes +@webnotes.whitelist(allow_guest=True) +def get_blog_list(args=None): + """ + args = { + 'limit_start': 0, + 'limit_page_length': 10, + } + """ + import webnotes + + if not args: args = webnotes.form_dict + + query = """\ + select + cache.name as name, cache.html as content, + blog.owner as owner, blog.creation as published, + blog.title as title + from `tabWeb Cache` cache, `tabBlog` blog + where cache.doc_type = 'Blog' and blog.page_name = cache.name + order by published desc, name asc""" + + 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 + import website.web_cache + + for res in result: + from webnotes.utils import global_date_format, get_fullname + res['full_name'] = get_fullname(res['owner']) + res['published'] = global_date_format(res['published']) + res['content'] = split_blog_content(res['content']) + res['content'] = res['content'][:1000] + + return result + @webnotes.whitelist(allow_guest=True) def get_recent_blog_list(args=None): """ @@ -64,4 +103,23 @@ def add_comment(args=None): comment_html = website.web_cache.build_html(template_args) return comment_html - \ No newline at end of file + +def get_content(blog_page_name): + import website.web_cache + content = website.web_cache.get_html(blog_page_name) + + content = split_blog_content(content) + + import webnotes.utils + content = webnotes.utils.escape_html(content) + + return content + +def split_blog_content(content): + content = content.split("") + content = len(content) > 1 and content[1] or content[0] + + content = content.split("") + content = content[0] + + return content \ No newline at end of file diff --git a/erpnext/website/doctype/blog/blog.py b/erpnext/website/doctype/blog/blog.py index bb7b66071f..8847596fc6 100644 --- a/erpnext/website/doctype/blog/blog.py +++ b/erpnext/website/doctype/blog/blog.py @@ -44,7 +44,7 @@ class DocType(website.web_page.Page): # temp fields from webnotes.utils import global_date_format, get_fullname self.doc.full_name = get_fullname(self.doc.owner) - self.doc.updated = global_date_format(self.doc.modified) + self.doc.updated = global_date_format(self.doc.creation) self.markdown_to_html(['content']) diff --git a/erpnext/website/templates/js/blog.js b/erpnext/website/templates/js/blog.js index 1212a84c8e..3ccc7d4eb1 100644 --- a/erpnext/website/templates/js/blog.js +++ b/erpnext/website/templates/js/blog.js @@ -18,24 +18,15 @@ wn.pages['{{ name }}'].onload = function(wrapper) { erpnext.blog_list = new wn.ui.Listing({ parent: $(wrapper).find('#blog-list').get(0), - query: 'select tabBlog.name, title, left(content, 1000) as content, tabBlog.creation, \ - ifnull(first_name, "") as first_name, ifnull(last_name, "") as last_name \ - from tabProfile, tabBlog\ - where ifnull(published,0)=1 and tabBlog.owner = tabProfile.name \ - order by tabBlog.creation desc', + method: 'website.blog.get_blog_list', hide_refresh: true, no_toolbar: true, render_row: function(parent, data) { if(data.content && data.content.length==1000) { data.content += repl('... (read on)', data); } - data.content = wn.markdown(data.content); - if(data.last_name) data.last_name = ' ' + data.last_name; - data.date = prettyDate(data.creation); parent.innerHTML = repl('

%(title)s

\ -

By %(first_name)s%(last_name)s, %(date)s

\ -

%(content)s


', data) - //Read Full Text
', data); +

%(content)s


', data); }, page_length: 10 });