Anand Doshi | 8c7e76b | 2012-07-11 18:40:57 +0530 | [diff] [blame] | 1 | import webnotes |
| 2 | |
| 3 | @webnotes.whitelist(allow_guest=True) |
| 4 | def 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) |
| 35 | def 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 Doshi | 51146c0 | 2012-07-12 18:41:12 +0530 | [diff] [blame] | 55 | website.web_cache.clear_cache(args.get('page_name'), |
| 56 | args.get('comment_doctype'), args.get('comment_docname')) |
Anand Doshi | 8c7e76b | 2012-07-11 18:40:57 +0530 | [diff] [blame] | 57 | |
| 58 | import webnotes.utils |
| 59 | |
| 60 | comment['comment_date'] = webnotes.utils.pretty_date(comment['creation']) |
Anand Doshi | 3d53e86 | 2012-07-12 20:12:40 +0530 | [diff] [blame] | 61 | template_args = { 'comment_list': [comment], 'template': 'html/comment.html' } |
Anand Doshi | 8c7e76b | 2012-07-11 18:40:57 +0530 | [diff] [blame] | 62 | |
| 63 | # get html of comment row |
Anand Doshi | 3d53e86 | 2012-07-12 20:12:40 +0530 | [diff] [blame] | 64 | comment_html = website.web_cache.build_html(template_args) |
Anand Doshi | 8c7e76b | 2012-07-11 18:40:57 +0530 | [diff] [blame] | 65 | |
| 66 | return comment_html |
| 67 | |