updates to website: removed webnotes.cms

This commit is contained in:
Rushabh Mehta
2012-12-07 12:44:45 +05:30
parent 571377a313
commit a494b88ad8
18 changed files with 196 additions and 35 deletions

View File

158
website/helpers/blog.py Normal file
View File

@@ -0,0 +1,158 @@
# Copyright (c) 2012 Web Notes Technologies Pvt Ltd.
# License: GNU General Public License (v3). For more information see license.txt
from __future__ import unicode_literals
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
name, content, owner, creation as creation,
title, (select count(name) from `tabComment` where
comment_doctype='Blog' and comment_docname=`tabBlog`.name) as comments
from `tabBlog`
where ifnull(published,0)=1
order by creation 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
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['creation'])
if not res['content']:
res['content'] = website.utils.get_html(res['name'])
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):
"""
args = {
'limit_start': 0,
'limit_page_length': 5,
'name': '',
}
"""
import webnotes
if not args: args = webnotes.form_dict
query = """\
select name, page_name, title, left(content, 100) as content
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
import webnotes.utils, markdown2
import webnotes.widgets.form.comments
if not args: args = webnotes.form_dict
args['comment'] = unicode(markdown2.markdown(args.get('comment') or ''))
comment = webnotes.widgets.form.comments.add_comment(args)
# since comments are embedded in the page, clear the web cache
website.utils.clear_cache(args.get('page_name'))
comment['comment_date'] = webnotes.utils.global_date_format(comment['creation'])
template_args = { 'comment_list': [comment], 'template': 'html/comment.html' }
# get html of comment row
comment_html = website.utils.build_html(template_args)
# 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
send(recipients=list(set(commentors + [blog['owner']])),
doctype='Comment',
email_field='comment_by',
subject='New Comment on Blog: ' + blog['title'],
message='%(comment)s<p>By %(comment_by_fullname)s</p>' % args)
return comment_html
@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')
if not lead.source: lead.source = 'Blog'
lead.unsubscribed = 0
lead.blog_subscriber = 1
lead.lead_name = full_name
lead.email_id = email
lead.save()
def get_blog_content(blog_page_name):
import website.utils
content = website.utils.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("<!-- begin blog content -->")
content = len(content) > 1 and content[1] or content[0]
content = content.split("<!-- end blog content -->")
content = content[0]
return content

View File

@@ -0,0 +1,79 @@
# Copyright (c) 2012 Web Notes Technologies Pvt Ltd (http://erpnext.com)
#
# MIT License (MIT)
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
from __future__ import unicode_literals
"""
Generate RSS feed for blog
"""
rss = u"""<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title>%(title)s</title>
<description>%(description)s</description>
<link>%(link)s</link>
<lastBuildDate>%(modified)s</lastBuildDate>
<pubDate>%(modified)s</pubDate>
<ttl>1800</ttl>
%(items)s
</channel>
</rss>"""
rss_item = u"""
<item>
<title>%(title)s</title>
<description>%(content)s</description>
<link>%(link)s</link>
<guid>%(name)s</guid>
<pubDate>%(creation)s</pubDate>
</item>"""
def generate():
"""generate rss feed"""
import webnotes, os
from webnotes.model.doc import Document
from website.helpers.blog import get_blog_content
host = (os.environ.get('HTTPS') and 'https://' or 'http://') + os.environ.get('HTTP_HOST')
items = ''
blog_list = webnotes.conn.sql("""\
select page_name as name, modified, creation, title from tabBlog
where ifnull(published,0)=1
order by creation desc, modified desc, name asc limit 100""", as_dict=1)
for blog in blog_list:
blog.link = host + '/' + blog.name + '.html'
blog.content = get_blog_content(blog.name)
items += rss_item % blog
modified = max((blog['modified'] for blog in blog_list))
ws = Document('Website Settings', 'Website Settings')
return (rss % {
'title': ws.title_prefix,
'description': ws.description or (ws.title_prefix + ' Blog'),
'modified': modified,
'items': items,
'link': host + '/blog.html'
}).encode('utf-8', 'ignore')

View File

@@ -0,0 +1,32 @@
# Copyright (c) 2012 Web Notes Technologies Pvt Ltd.
# License: GNU General Public License (v3). For more information see license.txt
def make():
import os
import webnotes
import website.utils
import startup.event_handlers
if not webnotes.conn:
webnotes.connect()
home_page = website.utils.get_home_page('Guest')
fname = 'js/wn-web.js'
if os.path.basename(os.path.abspath('.'))!='public':
fname = os.path.join('public', fname)
if hasattr(startup.event_handlers, 'get_web_script'):
with open(fname, 'w') as f:
script = 'window.home_page = "%s";\n' % home_page
script += startup.event_handlers.get_web_script()
f.write(script)
fname = 'css/wn-web.css'
if os.path.basename(os.path.abspath('.'))!='public':
fname = os.path.join('public', fname)
# style - wn.css
if hasattr(startup.event_handlers, 'get_web_style'):
with open(fname, 'w') as f:
f.write(startup.event_handlers.get_web_style())

120
website/helpers/product.py Normal file
View File

@@ -0,0 +1,120 @@
# Copyright (c) 2012 Web Notes Technologies Pvt Ltd.
# License: GNU General Public License (v3). For more information see license.txt
from __future__ import unicode_literals
import webnotes
@webnotes.whitelist(allow_guest=True)
def get_product_list(args=None):
"""
args = {
'limit_start': 0,
'limit_page_length': 20,
'search': '',
'product_group': '',
}
"""
import webnotes
from webnotes.utils import cstr
if not args: args = webnotes.form_dict
# base query
query = """\
select name, item_name, page_name, website_image,
description, web_short_description
from `tabItem`
where is_sales_item = 'Yes'
and docstatus = 0
and show_in_website = 1"""
# search term condition
if args.get('search'):
query += """
and (
web_short_description like %(search)s or
web_long_description like %(search)s or
description like %(search)s or
item_name like %(search)s or
name like %(search)s
)"""
args['search'] = "%" + cstr(args.get('search')) + "%"
# product group condition
if args.get('product_group') and args.get('product_group') != 'All Products':
query += """
and item_group = %(product_group)s"""
# order by
query += """
order by item_name asc, name asc"""
from webnotes.widgets.query_builder import add_limit_to_query
query, args = add_limit_to_query(query, args)
return webnotes.conn.sql(query, args, as_dict=1)
@webnotes.whitelist(allow_guest=True)
def get_product_category_list(args=None):
"""
args = {
'limit_start': 0,
'limit_page_length': 5,
}
"""
import webnotes
if not args: args = webnotes.form_dict
query = """\
select count(name) as items, item_group
from `tabItem`
where is_sales_item = 'Yes'
and docstatus = 0
and show_in_website = 1
group by item_group
order by items 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)
# add All Products link
total_count = sum((r.get('items') or 0 for r in result))
result = [{'items': total_count, 'item_group': 'All Products'}] + (result or [])
return result
@webnotes.whitelist(allow_guest=True)
def get_similar_product_list(args=None):
"""
args = {
'limit_start': 0,
'limit_page_length': 5,
'product_name': '',
'product_group': '',
}
"""
import webnotes
if not args: args = webnotes.form_dict
query = """\
select name, item_name, page_name, website_image,
description, web_short_description
from `tabItem`
where is_sales_item = 'Yes'
and docstatus = 0
and show_in_website = 1
and name != %(product_name)s
and item_group = %(product_group)s
order by item_name"""
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)
return result

View File

@@ -0,0 +1,38 @@
# Copyright (c) 2012 Web Notes Technologies Pvt Ltd.
# License: GNU General Public License (v3). For more information see license.txt
from __future__ import unicode_literals
frame_xml = """<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">%s
</urlset>"""
link_xml = """\n<url><loc>%s</loc><lastmod>%s</lastmod></url>"""
# generate the sitemap XML
def generate(domain):
global frame_xml, link_xml
import urllib, os
import webnotes
import website.utils
# settings
max_doctypes = 10
max_items = 1000
site_map = ''
page_list = []
if domain:
# list of all pages in web cache
for doctype in website.utils.page_map:
d = website.utils.page_map[doctype];
pages = webnotes.conn.sql("""select page_name, `modified`
from `tab%s` where ifnull(%s,0)=1
order by modified desc""" % (doctype, d.condition_field))
for p in pages:
page_url = os.path.join(domain, urllib.quote(p[0]) + '.html')
modified = p[1].strftime('%Y-%m-%d')
site_map += link_xml % (page_url, modified)
return frame_xml % site_map