mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 16:34:46 +00:00
[website] [minor] moving website helper methods to doctypes
This commit is contained in:
@@ -90,7 +90,7 @@
|
|||||||
},
|
},
|
||||||
"blog": {
|
"blog": {
|
||||||
"template": "app/website/templates/pages/blog",
|
"template": "app/website/templates/pages/blog",
|
||||||
"args_method": "website.helpers.blog.get_blog_template_args"
|
"args_method": "website.doctype.blog_post.blog_post.get_blog_template_args"
|
||||||
},
|
},
|
||||||
"contact": {
|
"contact": {
|
||||||
"template": "app/website/templates/pages/contact",
|
"template": "app/website/templates/pages/contact",
|
||||||
@@ -185,7 +185,7 @@
|
|||||||
},
|
},
|
||||||
"partners": {
|
"partners": {
|
||||||
"template": "app/website/templates/pages/partners",
|
"template": "app/website/templates/pages/partners",
|
||||||
"args_method": "website.helpers.partner.get_partner_args"
|
"args_method": "setup.doctype.sales_partner.sales_partner.get_partner_args"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"generators": {
|
"generators": {
|
||||||
|
|||||||
@@ -60,6 +60,6 @@ class DocType(DocTypeNestedSet):
|
|||||||
self.doc.title = self.doc.name
|
self.doc.title = self.doc.name
|
||||||
|
|
||||||
if self.doc.slideshow:
|
if self.doc.slideshow:
|
||||||
from website.helpers.slideshow import get_slideshow
|
from website.doctype.website_slideshow.website_slideshow import get_slideshow
|
||||||
get_slideshow(self)
|
get_slideshow(self)
|
||||||
|
|
||||||
@@ -43,3 +43,9 @@ class DocType:
|
|||||||
"partner_address": filter_strip_join(address_rows, "\n<br>"),
|
"partner_address": filter_strip_join(address_rows, "\n<br>"),
|
||||||
"phone": filter_strip_join(cstr(address.phone).split(","), "\n<br>")
|
"phone": filter_strip_join(cstr(address.phone).split(","), "\n<br>")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def get_partner_args():
|
||||||
|
return {
|
||||||
|
"partners": webnotes.conn.sql("""select * from `tabSales Partner`
|
||||||
|
where show_in_website=1 order by name asc""", as_dict=True),
|
||||||
|
}
|
||||||
@@ -65,7 +65,7 @@ def check_if_expired():
|
|||||||
raise webnotes.AuthenticationError
|
raise webnotes.AuthenticationError
|
||||||
|
|
||||||
def on_build():
|
def on_build():
|
||||||
from website.helpers.make_web_include_files import make
|
from website.doctype.website_settings.make_web_include_files import make
|
||||||
make()
|
make()
|
||||||
|
|
||||||
from home.page.latest_updates import latest_updates
|
from home.page.latest_updates import latest_updates
|
||||||
|
|||||||
@@ -264,7 +264,7 @@ class DocType(DocListController):
|
|||||||
self.doc.title = self.doc.item_name
|
self.doc.title = self.doc.item_name
|
||||||
|
|
||||||
if self.doc.slideshow:
|
if self.doc.slideshow:
|
||||||
from website.helpers.slideshow import get_slideshow
|
from website.doctype.website_slideshow.website_slideshow import get_slideshow
|
||||||
get_slideshow(self)
|
get_slideshow(self)
|
||||||
|
|
||||||
def get_file_details(self, arg = ''):
|
def get_file_details(self, arg = ''):
|
||||||
|
|||||||
@@ -67,3 +67,110 @@ class DocType:
|
|||||||
for comment in self.doc.comment_list:
|
for comment in self.doc.comment_list:
|
||||||
comment['comment_date'] = webnotes.utils.global_date_format(comment['creation'])
|
comment['comment_date'] = webnotes.utils.global_date_format(comment['creation'])
|
||||||
comment['comment'] = markdown2.markdown(comment['comment'])
|
comment['comment'] = markdown2.markdown(comment['comment'])
|
||||||
|
|
||||||
|
def clear_blog_cache():
|
||||||
|
for blog in webnotes.conn.sql_list("""select page_name from
|
||||||
|
`tabBlog Post` where ifnull(published,0)=1"""):
|
||||||
|
webnotes.webutils.delete_page_cache(blog)
|
||||||
|
|
||||||
|
webnotes.webutils.delete_page_cache("writers")
|
||||||
|
|
||||||
|
@webnotes.whitelist(allow_guest=True)
|
||||||
|
def get_blog_list(start=0, by=None, category=None):
|
||||||
|
import webnotes
|
||||||
|
condition = ""
|
||||||
|
if by:
|
||||||
|
condition = " and t1.blogger='%s'" % by.replace("'", "\'")
|
||||||
|
if category:
|
||||||
|
condition += " and t1.blog_category='%s'" % category.replace("'", "\'")
|
||||||
|
query = """\
|
||||||
|
select
|
||||||
|
t1.title, t1.name, t1.page_name, t1.published_on as creation,
|
||||||
|
ifnull(t1.blog_intro, t1.content) as content,
|
||||||
|
t2.full_name, t2.avatar, t1.blogger,
|
||||||
|
(select count(name) from `tabComment` where
|
||||||
|
comment_doctype='Blog Post' and comment_docname=t1.name) as comments
|
||||||
|
from `tabBlog Post` t1, `tabBlogger` t2
|
||||||
|
where ifnull(t1.published,0)=1
|
||||||
|
and t1.blogger = t2.name
|
||||||
|
%(condition)s
|
||||||
|
order by published_on desc, name asc
|
||||||
|
limit %(start)s, 20""" % {"start": start, "condition": condition}
|
||||||
|
|
||||||
|
result = webnotes.conn.sql(query, as_dict=1)
|
||||||
|
|
||||||
|
# strip html tags from content
|
||||||
|
import webnotes.utils
|
||||||
|
|
||||||
|
for res in result:
|
||||||
|
from webnotes.utils import global_date_format
|
||||||
|
res['published'] = global_date_format(res['creation'])
|
||||||
|
if not res['content']:
|
||||||
|
res['content'] = webnotes.webutils.get_html(res['page_name'])
|
||||||
|
res['content'] = res['content'][:140]
|
||||||
|
|
||||||
|
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
|
||||||
|
import webnotes.utils, markdown2
|
||||||
|
|
||||||
|
if not args: args = webnotes.form_dict
|
||||||
|
args['comment'] = unicode(markdown2.markdown(args.get('comment') or ''))
|
||||||
|
args['doctype'] = "Comment"
|
||||||
|
|
||||||
|
page_name = args.get("page_name")
|
||||||
|
if "page_name" in args:
|
||||||
|
del args["page_name"]
|
||||||
|
if "cmd" in args:
|
||||||
|
del args["cmd"]
|
||||||
|
|
||||||
|
comment = webnotes.bean(args)
|
||||||
|
comment.ignore_permissions = True
|
||||||
|
comment.insert()
|
||||||
|
|
||||||
|
# since comments are embedded in the page, clear the web cache
|
||||||
|
webnotes.webutils.clear_cache(page_name)
|
||||||
|
|
||||||
|
args['comment_date'] = webnotes.utils.global_date_format(comment.doc.creation)
|
||||||
|
template_args = { 'comment_list': [args], 'template': 'app/website/templates/html/comment.html' }
|
||||||
|
|
||||||
|
# get html of comment row
|
||||||
|
comment_html = webnotes.webutils.build_html(template_args)
|
||||||
|
|
||||||
|
# notify commentors
|
||||||
|
commentors = [d[0] for d in webnotes.conn.sql("""select comment_by from tabComment where
|
||||||
|
comment_doctype='Blog Post' and comment_docname=%s and
|
||||||
|
ifnull(unsubscribed, 0)=0""", args.get('comment_docname'))]
|
||||||
|
|
||||||
|
blog = webnotes.doc("Blog Post", args.get("comment_docname"))
|
||||||
|
blogger_profile = webnotes.conn.get_value("Blogger", blog.blogger, "profile")
|
||||||
|
blogger_email = webnotes.conn.get_value("Profile", blogger_profile, "email")
|
||||||
|
|
||||||
|
from webnotes.utils.email_lib.bulk import send
|
||||||
|
send(recipients=list(set(commentors + [blogger_email])),
|
||||||
|
doctype='Comment',
|
||||||
|
email_field='comment_by',
|
||||||
|
subject='New Comment on Blog: ' + blog.title,
|
||||||
|
message='%(comment)s<p>By %(comment_by_fullname)s</p>' % args,
|
||||||
|
ref_doctype='Blog Post', ref_docname=blog.name)
|
||||||
|
|
||||||
|
return comment_html.replace("\n", "")
|
||||||
|
|
||||||
|
def get_blog_template_args():
|
||||||
|
args = {
|
||||||
|
"categories": webnotes.conn.sql_list("select name from `tabBlog Category` order by name")
|
||||||
|
}
|
||||||
|
args.update(webnotes.doc("Blog Settings", "Blog Settings").fields)
|
||||||
|
return args
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class DocType:
|
|||||||
def on_update(self):
|
def on_update(self):
|
||||||
"if profile is set, then update all older blogs"
|
"if profile is set, then update all older blogs"
|
||||||
|
|
||||||
from website.helpers.blog import clear_blog_cache
|
from website.doctype.blog_post.blog_post import clear_blog_cache
|
||||||
clear_blog_cache()
|
clear_blog_cache()
|
||||||
|
|
||||||
if self.doc.profile:
|
if self.doc.profile:
|
||||||
|
|||||||
@@ -94,5 +94,5 @@ class DocType:
|
|||||||
|
|
||||||
def on_update(self):
|
def on_update(self):
|
||||||
"""rebuild pages"""
|
"""rebuild pages"""
|
||||||
from website.helpers.make_web_include_files import make
|
from website.doctype.website_settings.make_web_include_files import make
|
||||||
make()
|
make()
|
||||||
@@ -29,7 +29,7 @@ class DocType():
|
|||||||
|
|
||||||
def prepare_template_args(self):
|
def prepare_template_args(self):
|
||||||
if self.doc.slideshow:
|
if self.doc.slideshow:
|
||||||
from website.helpers.slideshow import get_slideshow
|
from website.doctype.website_slideshow.website_slideshow import get_slideshow
|
||||||
get_slideshow(self)
|
get_slideshow(self)
|
||||||
|
|
||||||
self.doc.meta_description = self.doc.description
|
self.doc.meta_description = self.doc.description
|
||||||
|
|||||||
@@ -12,5 +12,5 @@ class DocType:
|
|||||||
|
|
||||||
def on_update(self):
|
def on_update(self):
|
||||||
# make js and css
|
# make js and css
|
||||||
from website.helpers.make_web_include_files import make
|
from website.doctype.website_settings.make_web_include_files import make
|
||||||
make()
|
make()
|
||||||
@@ -58,7 +58,7 @@ class DocType:
|
|||||||
|
|
||||||
def on_update(self):
|
def on_update(self):
|
||||||
# make js and css
|
# make js and css
|
||||||
from website.helpers.make_web_include_files import make
|
from website.doctype.website_settings.make_web_include_files import make
|
||||||
make()
|
make()
|
||||||
|
|
||||||
# clear web cache (for menus!)
|
# clear web cache (for menus!)
|
||||||
|
|||||||
@@ -14,3 +14,8 @@ class DocType:
|
|||||||
# a slide show can be in use and any change in it should get reflected
|
# a slide show can be in use and any change in it should get reflected
|
||||||
from webnotes.webutils import clear_cache
|
from webnotes.webutils import clear_cache
|
||||||
clear_cache()
|
clear_cache()
|
||||||
|
|
||||||
|
def get_slideshow(obj):
|
||||||
|
slideshow = webnotes.bean("Website Slideshow", obj.doc.slideshow)
|
||||||
|
obj.slides = slideshow.doclist.get({"doctype":"Website Slideshow Item"})
|
||||||
|
obj.doc.slideshow_header = slideshow.doc.header or ""
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
|
|
||||||
# License: GNU General Public License v3. See license.txt
|
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
import webnotes
|
|
||||||
import webnotes.webutils
|
|
||||||
from webnotes import _
|
|
||||||
|
|
||||||
def clear_blog_cache():
|
|
||||||
for blog in webnotes.conn.sql_list("""select page_name from
|
|
||||||
`tabBlog Post` where ifnull(published,0)=1"""):
|
|
||||||
webnotes.webutils.delete_page_cache(blog)
|
|
||||||
|
|
||||||
webnotes.webutils.delete_page_cache("writers")
|
|
||||||
|
|
||||||
@webnotes.whitelist(allow_guest=True)
|
|
||||||
def get_blog_list(start=0, by=None, category=None):
|
|
||||||
import webnotes
|
|
||||||
condition = ""
|
|
||||||
if by:
|
|
||||||
condition = " and t1.blogger='%s'" % by.replace("'", "\'")
|
|
||||||
if category:
|
|
||||||
condition += " and t1.blog_category='%s'" % category.replace("'", "\'")
|
|
||||||
query = """\
|
|
||||||
select
|
|
||||||
t1.title, t1.name, t1.page_name, t1.published_on as creation,
|
|
||||||
ifnull(t1.blog_intro, t1.content) as content,
|
|
||||||
t2.full_name, t2.avatar, t1.blogger,
|
|
||||||
(select count(name) from `tabComment` where
|
|
||||||
comment_doctype='Blog Post' and comment_docname=t1.name) as comments
|
|
||||||
from `tabBlog Post` t1, `tabBlogger` t2
|
|
||||||
where ifnull(t1.published,0)=1
|
|
||||||
and t1.blogger = t2.name
|
|
||||||
%(condition)s
|
|
||||||
order by published_on desc, name asc
|
|
||||||
limit %(start)s, 20""" % {"start": start, "condition": condition}
|
|
||||||
|
|
||||||
result = webnotes.conn.sql(query, as_dict=1)
|
|
||||||
|
|
||||||
# strip html tags from content
|
|
||||||
import webnotes.utils
|
|
||||||
|
|
||||||
for res in result:
|
|
||||||
from webnotes.utils import global_date_format
|
|
||||||
res['published'] = global_date_format(res['creation'])
|
|
||||||
if not res['content']:
|
|
||||||
res['content'] = webnotes.webutils.get_html(res['page_name'])
|
|
||||||
res['content'] = res['content'][:140]
|
|
||||||
|
|
||||||
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
|
|
||||||
import webnotes.utils, markdown2
|
|
||||||
|
|
||||||
if not args: args = webnotes.form_dict
|
|
||||||
args['comment'] = unicode(markdown2.markdown(args.get('comment') or ''))
|
|
||||||
args['doctype'] = "Comment"
|
|
||||||
|
|
||||||
page_name = args.get("page_name")
|
|
||||||
if "page_name" in args:
|
|
||||||
del args["page_name"]
|
|
||||||
if "cmd" in args:
|
|
||||||
del args["cmd"]
|
|
||||||
|
|
||||||
comment = webnotes.bean(args)
|
|
||||||
comment.ignore_permissions = True
|
|
||||||
comment.insert()
|
|
||||||
|
|
||||||
# since comments are embedded in the page, clear the web cache
|
|
||||||
webnotes.webutils.clear_cache(page_name)
|
|
||||||
|
|
||||||
args['comment_date'] = webnotes.utils.global_date_format(comment.doc.creation)
|
|
||||||
template_args = { 'comment_list': [args], 'template': 'app/website/templates/html/comment.html' }
|
|
||||||
|
|
||||||
# get html of comment row
|
|
||||||
comment_html = webnotes.webutils.build_html(template_args)
|
|
||||||
|
|
||||||
# notify commentors
|
|
||||||
commentors = [d[0] for d in webnotes.conn.sql("""select comment_by from tabComment where
|
|
||||||
comment_doctype='Blog Post' and comment_docname=%s and
|
|
||||||
ifnull(unsubscribed, 0)=0""", args.get('comment_docname'))]
|
|
||||||
|
|
||||||
blog = webnotes.doc("Blog Post", args.get("comment_docname"))
|
|
||||||
blogger_profile = webnotes.conn.get_value("Blogger", blog.blogger, "profile")
|
|
||||||
blogger_email = webnotes.conn.get_value("Profile", blogger_profile, "email")
|
|
||||||
|
|
||||||
from webnotes.utils.email_lib.bulk import send
|
|
||||||
send(recipients=list(set(commentors + [blogger_email])),
|
|
||||||
doctype='Comment',
|
|
||||||
email_field='comment_by',
|
|
||||||
subject='New Comment on Blog: ' + blog.title,
|
|
||||||
message='%(comment)s<p>By %(comment_by_fullname)s</p>' % args,
|
|
||||||
ref_doctype='Blog Post', ref_docname=blog.name)
|
|
||||||
|
|
||||||
return comment_html.replace("\n", "")
|
|
||||||
|
|
||||||
def get_blog_content(blog_page_name):
|
|
||||||
import webnotes.webutils
|
|
||||||
content = webnotes.webutils.get_html(blog_page_name)
|
|
||||||
import webnotes.utils
|
|
||||||
content = webnotes.utils.escape_html(content)
|
|
||||||
return content
|
|
||||||
|
|
||||||
def get_blog_template_args():
|
|
||||||
args = {
|
|
||||||
"categories": webnotes.conn.sql_list("select name from `tabBlog Category` order by name")
|
|
||||||
}
|
|
||||||
args.update(webnotes.doc("Blog Settings", "Blog Settings").fields)
|
|
||||||
return args
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
|
|
||||||
# License: GNU General Public License v3. See license.txt
|
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
import webnotes
|
|
||||||
|
|
||||||
def get_partner_args():
|
|
||||||
return {
|
|
||||||
"partners": webnotes.conn.sql("""select * from `tabSales Partner`
|
|
||||||
where show_in_website=1 order by name asc""", as_dict=True),
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
|
|
||||||
# License: GNU General Public License v3. See license.txt
|
|
||||||
|
|
||||||
import webnotes
|
|
||||||
|
|
||||||
def get_slideshow(obj):
|
|
||||||
slideshow = webnotes.bean("Website Slideshow", obj.doc.slideshow)
|
|
||||||
obj.slides = slideshow.doclist.get({"doctype":"Website Slideshow Item"})
|
|
||||||
obj.doc.slideshow_header = slideshow.doc.header or ""
|
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ var blog = {
|
|||||||
method: "GET",
|
method: "GET",
|
||||||
url: "server.py",
|
url: "server.py",
|
||||||
data: {
|
data: {
|
||||||
cmd: "website.helpers.blog.get_blog_list",
|
cmd: "website.doctype.blog_post.blog_post.get_blog_list",
|
||||||
start: blog.start,
|
start: blog.start,
|
||||||
by: get_url_arg("by"),
|
by: get_url_arg("by"),
|
||||||
category: get_url_arg("category")
|
category: get_url_arg("category")
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ $(document).ready(function() {
|
|||||||
comment_by_fullname: $("[name='comment_by_fullname']").val(),
|
comment_by_fullname: $("[name='comment_by_fullname']").val(),
|
||||||
comment_by: $("[name='comment_by']").val(),
|
comment_by: $("[name='comment_by']").val(),
|
||||||
comment: $("[name='comment']").val(),
|
comment: $("[name='comment']").val(),
|
||||||
cmd: "website.helpers.blog.add_comment",
|
cmd: "website.doctype.blog_post.blog_post.add_comment",
|
||||||
comment_doctype: "Blog Post",
|
comment_doctype: "Blog Post",
|
||||||
comment_docname: "{{ name }}",
|
comment_docname: "{{ name }}",
|
||||||
page_name: "{{ page_name }}",
|
page_name: "{{ page_name }}",
|
||||||
|
|||||||
Reference in New Issue
Block a user