コード例 #1
0
ファイル: blog_post.py プロジェクト: BillTheBest/erpnext
	def prepare_template_args(self):
		import webnotes.utils
		
		# this is for double precaution. usually it wont reach this code if not published
		if not webnotes.utils.cint(self.doc.published):
			raise Exception, "This blog has not been published yet!"
		
		# temp fields
		from webnotes.utils import global_date_format, get_fullname
		self.doc.full_name = get_fullname(self.doc.owner)
		self.doc.updated = global_date_format(self.doc.published_on)
		self.doc.content_html = self.doc.content
		if self.doc.blogger:
			self.doc.blogger_info = webnotes.doc("Blogger", self.doc.blogger).fields
		
		self.doc.description = self.doc.blog_intro or self.doc.content[:140]
		
		self.doc.categories = webnotes.conn.sql_list("select name from `tabBlog Category` order by name")
		
		self.doc.texts = {
			"comments": _("Comments"),
			"first_comment": _("Be the first one to comment"),
			"add_comment": _("Add Comment"),
			"submit": _("Submit"),
			"all_posts_by": _("All posts by"),
		}

		comment_list = webnotes.conn.sql("""\
			select comment, comment_by_fullname, creation
			from `tabComment` where comment_doctype="Blog Post"
			and comment_docname=%s order by creation""", self.doc.name, as_dict=1)
		
		self.doc.comment_list = comment_list or []
		for comment in self.doc.comment_list:
			comment['comment_date'] = webnotes.utils.global_date_format(comment['creation'])
コード例 #2
0
ファイル: blog.py プロジェクト: eric20201688/erpnext
    def prepare_template_args(self):
        import webnotes.utils

        # this is for double precaution. usually it wont reach this code if not published
        if not webnotes.utils.cint(self.doc.published):
            raise Exception, "This blog has not been published yet!"

        # temp fields
        from webnotes.utils import global_date_format, get_fullname
        self.doc.full_name = get_fullname(self.doc.owner)
        self.doc.updated = global_date_format(self.doc.creation)

        self.markdown_to_html(['content'])

        comment_list = webnotes.conn.sql("""\
			select comment, comment_by_fullname, creation
			from `tabComment` where comment_doctype="Blog"
			and comment_docname=%s order by creation""",
                                         self.doc.name,
                                         as_dict=1)

        self.doc.comment_list = comment_list or []
        for comment in self.doc.comment_list:
            comment['comment_date'] = webnotes.utils.global_date_format(
                comment['creation'])
コード例 #3
0
    def get_context(self):
        import webnotes.utils
        import markdown2

        # this is for double precaution. usually it wont reach this code if not published
        if not webnotes.utils.cint(self.doc.published):
            raise Exception, "This blog has not been published yet!"

        # temp fields
        from webnotes.utils import global_date_format, get_fullname
        self.doc.full_name = get_fullname(self.doc.owner)
        self.doc.updated = global_date_format(self.doc.published_on)

        if self.doc.blogger:
            self.doc.blogger_info = webnotes.doc("Blogger",
                                                 self.doc.blogger).fields

        self.doc.description = self.doc.blog_intro or self.doc.content[:140]
        self.doc.meta_description = self.doc.description

        self.doc.categories = webnotes.conn.sql_list(
            "select name from `tabBlog Category` order by name")

        self.doc.comment_list = webnotes.conn.sql("""\
			select comment, comment_by_fullname, creation
			from `tabComment` where comment_doctype="Blog Post"
			and comment_docname=%s order by creation""",
                                                  self.doc.name,
                                                  as_dict=1) or []
コード例 #4
0
ファイル: blog.py プロジェクト: MiteshC/erpnext
def get_blog_list(args=None):
    """
		args = {
			'start': 0,
		}
	"""
    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
		limit %s, 5""" % args.start

    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'])

    return result
コード例 #5
0
ファイル: blog_post.py プロジェクト: Halfnhav/wnframework
	def get_context(self):
		import webnotes.utils
		import markdown2
		
		# this is for double precaution. usually it wont reach this code if not published
		if not webnotes.utils.cint(self.doc.published):
			raise Exception, "This blog has not been published yet!"
		
		# temp fields
		from webnotes.utils import global_date_format, get_fullname
		self.doc.full_name = get_fullname(self.doc.owner)
		self.doc.updated = global_date_format(self.doc.published_on)
		
		if self.doc.blogger:
			self.doc.blogger_info = webnotes.doc("Blogger", self.doc.blogger).fields
		
		self.doc.description = self.doc.blog_intro or self.doc.content[:140]
		self.doc.meta_description = self.doc.description
		
		self.doc.categories = webnotes.conn.sql_list("select name from `tabBlog Category` order by name")
		
		self.doc.comment_list = webnotes.conn.sql("""\
			select comment, comment_by_fullname, creation
			from `tabComment` where comment_doctype="Blog Post"
			and comment_docname=%s order by creation""", self.doc.name, as_dict=1) or []
コード例 #6
0
ファイル: blog_post.py プロジェクト: Halfnhav/wnframework
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
コード例 #7
0
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, get_fullname
		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
コード例 #8
0
	def validate(self):
		"""write/update 'Page' with the blog"""		
		p = website.utils.add_page(self.doc.title)
		self.doc.name = p.name
		
		from jinja2 import Template
		import markdown2
		import os
		from webnotes.utils import global_date_format, get_fullname
		
		self.doc.content_html = markdown2.markdown(self.doc.content or '')
		self.doc.full_name = get_fullname(self.doc.owner)
		self.doc.updated = global_date_format(self.doc.modified)
		
		with open(os.path.join(os.path.dirname(__file__), 'template.html'), 'r') as f:
			p.content = Template(f.read()).render(doc=self.doc)
		
		with open(os.path.join(os.path.dirname(__file__), 'blog_page.js'), 'r') as f:
			p.script = Template(f.read()).render(doc=self.doc)
				
		p.save()
		
		website.utils.add_guest_access_to_page(p.name)
		
		# cleanup
		for f in ['content_html', 'full_name', 'updated']:
			if f in self.doc.fields:
				del self.doc.fields[f]
コード例 #9
0
    def prepare_template_args(self):
        import webnotes.utils

        # this is for double precaution. usually it wont reach this code if not published
        if not webnotes.utils.cint(self.doc.published):
            raise Exception, "This blog has not been published yet!"

            # temp fields
        from webnotes.utils import global_date_format, get_fullname

        self.doc.full_name = get_fullname(self.doc.owner)
        self.doc.updated = global_date_format(self.doc.creation)

        self.markdown_to_html(["content"])

        comment_list = webnotes.conn.sql(
            """\
			select comment, comment_by_fullname, creation
			from `tabComment` where comment_doctype="Blog"
			and comment_docname=%s order by creation""",
            self.doc.name,
            as_dict=1,
        )

        self.doc.comment_list = comment_list or []
        for comment in self.doc.comment_list:
            comment["comment_date"] = webnotes.utils.global_date_format(comment["creation"])
コード例 #10
0
ファイル: blog.py プロジェクト: MiteshC/erpnext
def get_blog_list(args=None):
	"""
		args = {
			'start': 0,
		}
	"""
	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
		limit %s, 5""" % args.start
		
	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'])

	return result
コード例 #11
0
def write_docs(data, build_sitemap=None, domain=None):
    from webnotes.utils import global_date_format
    if webnotes.session.user != "Administrator":
        raise webnotes.PermissionError

    with open(os.path.join(os.path.dirname(__file__), "docs.html"),
              "r") as docshtml:
        docs_template = docshtml.read()

    if isinstance(data, basestring):
        data = json.loads(data)

    template = Template(docs_template)
    data["index"] = data["docs"]
    data["docs"] = None
    for name, d in data.items():
        if d:
            if not d.get("title"):
                d["title"] = d["_label"]
            if d.get("_parent_page") == "docs.html":
                d["_parent_page"] = "index.html"
            if not d.get("_icon"):
                d["_icon"] = "icon-file-alt"
            if not d["_icon"].startswith("icon-"):
                d["_icon"] = "icon-" + d["_icon"]
            if d.get("_modified"):
                d["_modified"] = global_date_format(d["_modified"])

            with open(get_path("public", "docs", name + ".html"),
                      "w") as docfile:
                if not d.get("description"):
                    d["description"] = "Help pages for " + d["title"]
                html = template.render(d)
                docfile.write(html.encode("utf-8", errors="ignore"))

    if build_sitemap and domain:
        if not domain.endswith("/"):
            domain = domain + "/"
        content = ""
        for fname in os.listdir(get_path("public", "docs")):
            if fname.endswith(".html"):
                content += sitemap_link_xml % (
                    domain + fname,
                    get_timestamp(get_path("public", "docs", fname)))

        with open(get_path("public", "docs", "sitemap.xml"), "w") as sitemap:
            sitemap.write(sitemap_frame_xml % content)
コード例 #12
0
def write_docs(data, build_sitemap=None, domain=None):
	from webnotes.utils import global_date_format
	if webnotes.session.user != "Administrator":
		raise webnotes.PermissionError
		
	if isinstance(data, basestring):
		data = json.loads(data)

	jenv = Environment(loader = FileSystemLoader(webnotes.utils.get_base_path()))

	template = jenv.get_template("app/docs/templates/docs.html")

	data["index"] = data["docs"]
	data["docs"] = None
	for name, d in data.items():
		if d:
			if not d.get("title"):
				d["title"] = d["_label"]
			if d.get("_parent_page")=="docs.html":
				d["_parent_page"] = "index.html"
			if not d.get("_icon"):
				d["_icon"] = "icon-file-alt"
			if not d["_icon"].startswith("icon-"):
				d["_icon"] = "icon-" + d["_icon"]
			if d.get("_modified"):
				d["_modified"] = global_date_format(d["_modified"])

			with open(get_path("public", "docs", name + ".html"), "w") as docfile:
				if not d.get("description"):
					d["description"] = "Help pages for " + d["title"]
				html = template.render(d)
				docfile.write(html.encode("utf-8", errors="ignore"))
				
	if build_sitemap and domain:
		if not domain.endswith("/"):
			domain = domain + "/"
		content = ""
		for fname in os.listdir(get_path("public", "docs")):
			fname = cstr(fname)
			if fname.endswith(".html"):
				content += sitemap_link_xml % (domain + fname, 
					get_timestamp(get_path("public", "docs", fname)))
					
		with open(get_path("public", "docs", "sitemap.xml"), "w") as sitemap:
			sitemap.write(sitemap_frame_xml % content)
コード例 #13
0
    def prepare_template_args(self):
        import webnotes.utils
        import markdown2

        # this is for double precaution. usually it wont reach this code if not published
        if not webnotes.utils.cint(self.doc.published):
            raise Exception, "This blog has not been published yet!"

        # temp fields
        from webnotes.utils import global_date_format, get_fullname
        self.doc.full_name = get_fullname(self.doc.owner)
        self.doc.updated = global_date_format(self.doc.published_on)
        self.doc.content_html = self.doc.content

        if self.doc.blogger:
            self.doc.blogger_info = webnotes.doc("Blogger",
                                                 self.doc.blogger).fields

        self.doc.description = self.doc.blog_intro or self.doc.content[:140]
        self.doc.meta_description = self.doc.description

        self.doc.categories = webnotes.conn.sql_list(
            "select name from `tabBlog Category` order by name")

        self.doc.texts = {
            "comments": _("Comments"),
            "first_comment": _("Be the first one to comment"),
            "add_comment": _("Add Comment"),
            "submit": _("Submit"),
            "all_posts_by": _("All posts by"),
        }

        comment_list = webnotes.conn.sql("""\
			select comment, comment_by_fullname, creation
			from `tabComment` where comment_doctype="Blog Post"
			and comment_docname=%s order by creation""",
                                         self.doc.name,
                                         as_dict=1)

        self.doc.comment_list = comment_list or []
        for comment in self.doc.comment_list:
            comment['comment_date'] = webnotes.utils.global_date_format(
                comment['creation'])
            comment['comment'] = markdown2.markdown(comment['comment'])
コード例 #14
0
    def validate(self):
        """write/update 'Page' with the blog"""
        # we need the name for the templates
        if not self.doc.name:
            self.autoname()

        if self.doc.page_name:
            webnotes.conn.sql("""delete from tabPage where name=%s""",
                              self.doc.page_name)

        p = website.utils.add_page(self.doc.title)

        from jinja2 import Template
        import markdown2
        import os
        from webnotes.utils import global_date_format, get_fullname
        from webnotes.model.code import get_obj

        self.doc.content_html = unicode(
            markdown2.markdown(self.doc.content or ''))
        self.doc.full_name = get_fullname(self.doc.owner)
        self.doc.updated = global_date_format(self.doc.modified)

        with open(os.path.join(os.path.dirname(__file__), 'template.html'),
                  'r') as f:
            p.content = Template(f.read()).render(doc=self.doc)

        with open(os.path.join(os.path.dirname(__file__), 'blog_page.js'),
                  'r') as f:
            p.script = Template(f.read()).render(doc=self.doc)

        p.web_page = 'Yes'
        p.save()
        get_obj(doc=p).write_cms_page()

        website.utils.add_guest_access_to_page(p.name)
        self.doc.page_name = p.name

        # cleanup
        for f in ['full_name', 'updated', 'content_html']:
            if f in self.doc.fields:
                del self.doc.fields[f]
コード例 #15
0
ファイル: web_page.py プロジェクト: aarohan/erpnext
	def on_update(self):
		"""make page for this product"""
		from jinja2 import Template
		from webnotes.utils import global_date_format
		from webnotes.model.code import get_obj
		import os

		# we need the name for the templates
		if self.doc.name.startswith('New Web Page'):
			self.autoname()

		if self.doc.page_name:
			webnotes.conn.sql("""delete from tabPage where name=%s""", self.doc.page_name)

		p = website.utils.add_page(self.doc.name)
		self.doc.page_name = p.name
		
		self.doc.updated = global_date_format(self.doc.modified)
		website.utils.markdown(self.doc, ['head_section','main_section', 'side_section'])
				
		with open(os.path.join(os.path.dirname(__file__), 'template.html'), 'r') as f:
			p.content = Template(f.read()).render(doc=self.doc)

		p.title = self.doc.title
		p.web_page = 'Yes'
		
		if self.doc.insert_code:
			p.script = self.doc.javascript

		if self.doc.insert_style:
			p.style = self.doc.css

		p.save()
		get_obj(doc=p).write_cms_page()
		
		website.utils.add_guest_access_to_page(p.name)
		self.cleanup_temp()

		self.doc.save()

		self.if_home_clear_cache()
コード例 #16
0
ファイル: web_page.py プロジェクト: salmandaw/erpnext
    def validate(self):
        """make page for this product"""
        from jinja2 import Template
        from webnotes.utils import global_date_format
        from webnotes.model.code import get_obj
        import os

        # we need the name for the templates
        if not self.doc.name:
            self.autoname()

        if self.doc.page_name:
            webnotes.conn.sql("""delete from tabPage where name=%s""",
                              self.doc.page_name)

        p = website.utils.add_page(self.doc.name)
        self.doc.page_name = p.name

        self.doc.updated = global_date_format(self.doc.modified)
        website.utils.markdown(
            self.doc, ['head_section', 'main_section', 'side_section'])

        with open(os.path.join(os.path.dirname(__file__), 'template.html'),
                  'r') as f:
            p.content = Template(f.read()).render(doc=self.doc)

        p.title = self.doc.title
        p.web_page = 'Yes'

        if self.doc.insert_code:
            p.script = self.doc.javascript

        if self.doc.insert_style:
            p.style = self.doc.css

        p.save()
        get_obj(doc=p).write_cms_page()

        website.utils.add_guest_access_to_page(p.name)
        self.cleanup_temp()
        self.if_home_clear_cache()
コード例 #17
0
ファイル: blog.py プロジェクト: eric20201688/erpnext
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
コード例 #18
0
ファイル: blog.py プロジェクト: hbkfabio/erpnext
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
コード例 #19
0
ファイル: blog.py プロジェクト: NorrWing/erpnext
	def validate(self):
		"""write/update 'Page' with the blog"""
		# we need the name for the templates
		if not self.doc.name:
			self.autoname()
		
		if self.doc.page_name:
			webnotes.conn.sql("""delete from tabPage where name=%s""", self.doc.page_name)
		
		p = website.utils.add_page(self.doc.title)
		
		from jinja2 import Template
		import markdown2
		import os
		from webnotes.utils import global_date_format, get_fullname
		from webnotes.model.code import get_obj
		
		self.doc.content_html = unicode(markdown2.markdown(self.doc.content or ''))
		self.doc.full_name = get_fullname(self.doc.owner)
		self.doc.updated = global_date_format(self.doc.modified)
		
		with open(os.path.join(os.path.dirname(__file__), 'template.html'), 'r') as f:
			p.content = Template(f.read()).render(doc=self.doc)
		
		with open(os.path.join(os.path.dirname(__file__), 'blog_page.js'), 'r') as f:
			p.script = Template(f.read()).render(doc=self.doc)
			
		p.web_page = 'Yes'
		p.save()
		get_obj(doc=p).write_cms_page()
		
		website.utils.add_guest_access_to_page(p.name)
		self.doc.page_name = p.name
		
		# cleanup
		for f in ['full_name', 'updated', 'content_html']:
			if f in self.doc.fields:
				del self.doc.fields[f]				
コード例 #20
0
ファイル: web_page.py プロジェクト: antoxin/erpnext
	def validate(self):
		"""make page for this product"""
		if not self.doc.name:				
			self.doc.name = website.utils.page_name(self.doc.title)

		p = website.utils.add_page(self.doc.name)
		
		from jinja2 import Template
		from webnotes.utils import global_date_format
		import os
	
		self.doc.updated = global_date_format(self.doc.modified)
		website.utils.markdown(self.doc, ['head_section','main_section', 'side_section'])
		
		self.add_page_links()
		
		with open(os.path.join(os.path.dirname(__file__), 'template.html'), 'r') as f:
			p.content = Template(f.read()).render(doc=self.doc)

		p.save()
		
		website.utils.add_guest_access_to_page(p.name)
		self.cleanup_temp()
		self.if_home_clear_cache()