2012-07-19 08:10:31 +00:00
|
|
|
from __future__ import unicode_literals
|
2012-07-11 13:10:57 +00:00
|
|
|
import webnotes
|
|
|
|
|
2012-07-12 19:16:59 +00:00
|
|
|
@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
|
2012-12-06 11:15:00 +00:00
|
|
|
name, content, owner, creation as creation,
|
|
|
|
title, (select count(name) from `tabComment` where
|
2012-12-06 14:43:57 +00:00
|
|
|
comment_doctype='Blog' and comment_docname=`tabBlog`.name) as comments
|
2012-12-06 11:15:00 +00:00
|
|
|
from `tabBlog`
|
|
|
|
where ifnull(published,0)=1
|
2012-12-06 14:19:00 +00:00
|
|
|
order by creation desc, name asc"""
|
2012-07-12 19:16:59 +00:00
|
|
|
|
|
|
|
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:
|
|
|
|
from webnotes.utils import global_date_format, get_fullname
|
|
|
|
res['full_name'] = get_fullname(res['owner'])
|
2012-12-06 11:15:00 +00:00
|
|
|
res['published'] = global_date_format(res['creation'])
|
2012-07-27 09:09:27 +00:00
|
|
|
if not res['content']:
|
2012-12-07 05:30:26 +00:00
|
|
|
res['content'] = website.utils.get_html(res['name'])
|
2012-07-12 19:16:59 +00:00
|
|
|
res['content'] = split_blog_content(res['content'])
|
|
|
|
res['content'] = res['content'][:1000]
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
2012-07-11 13:10:57 +00:00
|
|
|
@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 = """\
|
2012-07-31 13:45:01 +00:00
|
|
|
select name, page_name, title, left(content, 100) as content
|
2012-07-11 13:10:57 +00:00
|
|
|
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
|
2012-08-13 05:39:21 +00:00
|
|
|
import webnotes.utils, markdown2
|
|
|
|
import webnotes.widgets.form.comments
|
2012-07-11 13:10:57 +00:00
|
|
|
|
|
|
|
if not args: args = webnotes.form_dict
|
2012-08-17 18:06:11 +00:00
|
|
|
args['comment'] = unicode(markdown2.markdown(args.get('comment') or ''))
|
2012-07-11 13:10:57 +00:00
|
|
|
|
|
|
|
comment = webnotes.widgets.form.comments.add_comment(args)
|
|
|
|
|
|
|
|
# since comments are embedded in the page, clear the web cache
|
2012-12-07 05:30:26 +00:00
|
|
|
website.utils.clear_cache(args.get('page_name'))
|
2012-07-11 13:10:57 +00:00
|
|
|
|
2012-08-23 11:45:13 +00:00
|
|
|
comment['comment_date'] = webnotes.utils.global_date_format(comment['creation'])
|
2012-07-12 14:42:40 +00:00
|
|
|
template_args = { 'comment_list': [comment], 'template': 'html/comment.html' }
|
2012-07-11 13:10:57 +00:00
|
|
|
|
|
|
|
# get html of comment row
|
2012-12-07 05:30:26 +00:00
|
|
|
comment_html = website.utils.build_html(template_args)
|
2012-08-06 09:52:17 +00:00
|
|
|
|
|
|
|
# notify commentors
|
|
|
|
commentors = [d[0] for d in webnotes.conn.sql("""select comment_by from tabComment where
|
|
|
|
comment_doctype='Blog' and comment_docname=%s and
|
|
|
|
ifnull(unsubscribed, 0)=0""", args.get('comment_docname'))]
|
|
|
|
|
|
|
|
blog = webnotes.conn.sql("""select * from tabBlog where name=%s""",
|
|
|
|
args.get('comment_docname'), as_dict=1)[0]
|
|
|
|
|
|
|
|
from webnotes.utils.email_lib.bulk import send
|
2012-08-13 06:01:27 +00:00
|
|
|
send(recipients=list(set(commentors + [blog['owner']])),
|
2012-08-06 09:52:17 +00:00
|
|
|
doctype='Comment',
|
|
|
|
email_field='comment_by',
|
|
|
|
subject='New Comment on Blog: ' + blog['title'],
|
2012-08-13 05:39:21 +00:00
|
|
|
message='%(comment)s<p>By %(comment_by_fullname)s</p>' % args)
|
2012-08-06 09:52:17 +00:00
|
|
|
|
2012-07-11 13:10:57 +00:00
|
|
|
return comment_html
|
2012-07-12 19:16:59 +00:00
|
|
|
|
2012-08-03 08:40:59 +00:00
|
|
|
@webnotes.whitelist(allow_guest=True)
|
|
|
|
def add_subscriber():
|
|
|
|
"""add blog subscriber to lead"""
|
|
|
|
full_name = webnotes.form_dict.get('your_name')
|
|
|
|
email = webnotes.form_dict.get('your_email_address')
|
|
|
|
name = webnotes.conn.sql("""select name from tabLead where email_id=%s""", email)
|
|
|
|
|
|
|
|
from webnotes.model.doc import Document
|
|
|
|
if name:
|
|
|
|
lead = Document('Lead', name[0][0])
|
|
|
|
else:
|
|
|
|
lead = Document('Lead')
|
2012-08-06 09:52:17 +00:00
|
|
|
|
|
|
|
if not lead.source: lead.source = 'Blog'
|
2012-08-03 08:40:59 +00:00
|
|
|
lead.unsubscribed = 0
|
|
|
|
lead.blog_subscriber = 1
|
|
|
|
lead.lead_name = full_name
|
|
|
|
lead.email_id = email
|
|
|
|
lead.save()
|
|
|
|
|
2012-07-12 19:44:52 +00:00
|
|
|
def get_blog_content(blog_page_name):
|
2012-12-07 05:30:26 +00:00
|
|
|
import website.utils
|
|
|
|
content = website.utils.get_html(blog_page_name)
|
2012-07-12 19:16:59 +00:00
|
|
|
content = split_blog_content(content)
|
|
|
|
import webnotes.utils
|
|
|
|
content = webnotes.utils.escape_html(content)
|
|
|
|
return content
|
|
|
|
|
|
|
|
def split_blog_content(content):
|
|
|
|
content = content.split("<!-- begin blog content -->")
|
|
|
|
content = len(content) > 1 and content[1] or content[0]
|
|
|
|
content = content.split("<!-- end blog content -->")
|
|
|
|
content = content[0]
|
|
|
|
return content
|