blob: 0c287ad1a1ca18c6d8bfb7d5a025a4e8a56329b8 [file] [log] [blame]
Anand Doshi8c7e76b2012-07-11 18:40:57 +05301import webnotes
2
3@webnotes.whitelist(allow_guest=True)
4def get_recent_blog_list(args=None):
5 """
6 args = {
7 'limit_start': 0,
8 'limit_page_length': 5,
9 'name': '',
10 }
11 """
12 import webnotes
13
14 if not args: args = webnotes.form_dict
15
16 query = """\
17 select name, title, left(content, 100) as content
18 from tabBlog
19 where ifnull(published,0)=1 and
20 name!=%(name)s order by creation desc"""
21
22 from webnotes.widgets.query_builder import add_limit_to_query
23 query, args = add_limit_to_query(query, args)
24
25 result = webnotes.conn.sql(query, args, as_dict=1)
26
27 # strip html tags from content
28 import webnotes.utils
29 for res in result:
30 res['content'] = webnotes.utils.strip_html(res['content'])
31
32 return result
33
34@webnotes.whitelist(allow_guest=True)
35def add_comment(args=None):
36 """
37 args = {
38 'comment': '',
39 'comment_by': '',
40 'comment_by_fullname': '',
41 'comment_doctype': '',
42 'comment_docname': '',
43 'page_name': '',
44 }
45 """
46 import webnotes
47
48 if not args: args = webnotes.form_dict
49
50 import webnotes.widgets.form.comments
51 comment = webnotes.widgets.form.comments.add_comment(args)
52
53 # since comments are embedded in the page, clear the web cache
54 import website.web_cache
Anand Doshi51146c02012-07-12 18:41:12 +053055 website.web_cache.clear_cache(args.get('page_name'),
56 args.get('comment_doctype'), args.get('comment_docname'))
Anand Doshi8c7e76b2012-07-11 18:40:57 +053057
58 import webnotes.utils
59
60 comment['comment_date'] = webnotes.utils.pretty_date(comment['creation'])
Anand Doshi3d53e862012-07-12 20:12:40 +053061 template_args = { 'comment_list': [comment], 'template': 'html/comment.html' }
Anand Doshi8c7e76b2012-07-11 18:40:57 +053062
63 # get html of comment row
Anand Doshi3d53e862012-07-12 20:12:40 +053064 comment_html = website.web_cache.build_html(template_args)
Anand Doshi8c7e76b2012-07-11 18:40:57 +053065
66 return comment_html
67