Esempio n. 1
0
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
Esempio n. 2
0
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
Esempio n. 3
0
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
Esempio n. 4
0
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
Esempio n. 5
0
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
Esempio n. 6
0
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
Esempio n. 7
0
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)
Esempio n. 8
0
def get_product_list(args=None):
    """
		args = {
			'limit_start': 0,
			'limit_page_length': 20,
			'search': '',
			'product_group': '',
		}
	"""
    import webnotes
    from webnotes.utils import cstr, cint

    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)
Esempio n. 9
0
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
			cache.name as name, cache.html as content,
			blog.owner as owner, blog.creation as published,
			blog.title as title, (select count(name) from `tabComment` where
				comment_doctype='Blog' and comment_docname=blog.name) as comments
		from `tabWeb Cache` cache, `tabBlog` blog
		where cache.doc_type = 'Blog' and blog.page_name = cache.name
		order by published 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
    import website.web_cache

    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['published'])
        if not res['content']:
            res['content'] = website.web_cache.get_html(res['name'])
        res['content'] = split_blog_content(res['content'])
        res['content'] = res['content'][:1000]

    return result
Esempio n. 10
0
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
			cache.name as name, cache.html as content,
			blog.owner as owner, blog.creation as published,
			blog.title as title, (select count(name) from `tabComment` where
				comment_doctype='Blog' and comment_docname=blog.name) as comments
		from `tabWeb Cache` cache, `tabBlog` blog
		where cache.doc_type = 'Blog' and blog.page_name = cache.name
		order by published 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
	import website.web_cache
	
	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['published'])
		if not res['content']:
			res['content'] = website.web_cache.get_html(res['name'])
		res['content'] = split_blog_content(res['content'])
		res['content'] = res['content'][:1000]

	return result
Esempio n. 11
0
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, page_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['page_name'])
		res['content'] = split_blog_content(res['content'])
		res['content'] = res['content'][:1000]

	return result