added blog category and other updates to website module

This commit is contained in:
Rushabh Mehta 2013-03-08 10:44:25 +05:30
parent e73b5e23b9
commit a2deb68776
16 changed files with 157 additions and 26 deletions

View File

@ -18,6 +18,7 @@ from __future__ import unicode_literals
import webnotes import webnotes
import website.utils import website.utils
from webnotes import _
class DocType: class DocType:
def __init__(self, d, dl): def __init__(self, d, dl):
@ -74,6 +75,16 @@ class DocType:
if self.doc.blogger_info.avatar and not "/" in self.doc.blogger_info.avatar: if self.doc.blogger_info.avatar and not "/" in self.doc.blogger_info.avatar:
self.doc.blogger_info.avatar = "files/" + self.doc.blogger_info.avatar self.doc.blogger_info.avatar = "files/" + self.doc.blogger_info.avatar
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("""\ comment_list = webnotes.conn.sql("""\
select comment, comment_by_fullname, creation select comment, comment_by_fullname, creation
from `tabComment` where comment_doctype="Blog" from `tabComment` where comment_doctype="Blog"

View File

@ -2,7 +2,7 @@
{ {
"creation": "2013-01-25 11:35:09", "creation": "2013-01-25 11:35:09",
"docstatus": 0, "docstatus": 0,
"modified": "2013-03-07 16:32:13", "modified": "2013-03-08 09:41:37",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -62,6 +62,13 @@
"options": "Blogger", "options": "Blogger",
"reqd": 1 "reqd": 1
}, },
{
"doctype": "DocField",
"fieldname": "blog_category",
"fieldtype": "Link",
"label": "Blog Category",
"options": "Blog Category"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "section_break_5", "fieldname": "section_break_5",

View File

@ -0,0 +1,8 @@
# For license information, please see license.txt
from __future__ import unicode_literals
import webnotes
class DocType:
def __init__(self, d, dl):
self.doc, self.doclist = d, dl

View File

@ -0,0 +1,51 @@
[
{
"creation": "2013-03-08 09:41:11",
"docstatus": 0,
"modified": "2013-03-08 09:41:11",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"autoname": "field:category_name",
"doctype": "DocType",
"document_type": "Master",
"module": "Website",
"name": "__common__"
},
{
"doctype": "DocField",
"fieldname": "category_name",
"fieldtype": "Data",
"label": "Category Name",
"name": "__common__",
"parent": "Blog Category",
"parentfield": "fields",
"parenttype": "DocType",
"permlevel": 0,
"reqd": 1
},
{
"cancel": 1,
"create": 1,
"doctype": "DocPerm",
"name": "__common__",
"parent": "Blog Category",
"parentfield": "permissions",
"parenttype": "DocType",
"permlevel": 0,
"read": 1,
"role": "Website Manager",
"write": 1
},
{
"doctype": "DocType",
"name": "Blog Category"
},
{
"doctype": "DocField"
},
{
"doctype": "DocPerm"
}
]

View File

@ -34,6 +34,11 @@ h1, h2, h3, h4, h5 {
font-family: '{{ doc.google_web_font_for_heading or doc.heading_font }}', Arial, 'Helvetica Neue' !important; font-family: '{{ doc.google_web_font_for_heading or doc.heading_font }}', Arial, 'Helvetica Neue' !important;
} }
{% endif %} {% endif %}
{% if doc.heading_text_as %}
h1, h2, h3, h4, h5 {
text-transform: {{ doc.heading_text_as }};
}
{% endif %}
{% if doc.page_border %} {% if doc.page_border %}
/* Page Border*/ /* Page Border*/

View File

@ -57,12 +57,18 @@ class DocType:
fonts = list(set(fonts)) fonts = list(set(fonts))
if self.doc.heading_text_as:
self.doc.heading_text_as = {
"UPPERCASE": "uppercase",
"Title Case":"capitalize",
"lowercase": "lowercase"
}[self.doc.heading_text_as]
self.doc.at_import = "" self.doc.at_import = ""
for f in fonts: for f in fonts:
self.doc.at_import += "\n@import url(http://fonts.googleapis.com/css?family=%s);" % f.replace(" ", "+") self.doc.at_import += "\n@import url(http://fonts.googleapis.com/css?family=%s);" % f.replace(" ", "+")
def on_update(self): def on_update(self):
"""rebuild pages""" """rebuild pages"""
from website.helpers.make_web_include_files import make from website.helpers.make_web_include_files import make

View File

@ -2,7 +2,7 @@
{ {
"creation": "2013-01-25 11:35:10", "creation": "2013-01-25 11:35:10",
"docstatus": 0, "docstatus": 0,
"modified": "2013-03-07 16:06:22", "modified": "2013-03-08 09:58:49",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -119,6 +119,13 @@
"label": "Font Size (Text)", "label": "Font Size (Text)",
"options": "\n12px\n13px\n14px\n15px\n16px" "options": "\n12px\n13px\n14px\n15px\n16px"
}, },
{
"doctype": "DocField",
"fieldname": "heading_text_as",
"fieldtype": "Select",
"label": "Heading Text As",
"options": "\nUPPERCASE\nTitle Case\nlowercase"
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "column_break_13", "fieldname": "column_break_13",

View File

@ -31,9 +31,6 @@ class DocType:
from website.utils import clear_cache from website.utils import clear_cache
clear_cache() clear_cache()
from webnotes.sessions import clear_cache
clear_cache('Guest')
def set_home_page(self): def set_home_page(self):
import webnotes import webnotes

View File

@ -6,11 +6,13 @@ import webnotes
import website.utils import website.utils
@webnotes.whitelist(allow_guest=True) @webnotes.whitelist(allow_guest=True)
def get_blog_list(start=0, by=None): def get_blog_list(start=0, by=None, category=None):
import webnotes import webnotes
condition = "" condition = ""
if by: if by:
condition = " and t1.blogger='%s'" % by.replace("'", "\'") condition = " and t1.blogger='%s'" % by.replace("'", "\'")
if category:
condition += " and t1.blog_category='%s'" % category.replace("'", "\'")
query = """\ query = """\
select select
t1.title, t1.name, t1.page_name, t1.creation as creation, t1.title, t1.name, t1.page_name, t1.creation as creation,
@ -116,3 +118,7 @@ def get_blog_content(blog_page_name):
content = webnotes.utils.escape_html(content) content = webnotes.utils.escape_html(content)
return content return content
def get_blog_template_args():
return {
"categories": webnotes.conn.sql_list("select name from `tabBlog Category` order by name")
}

View File

@ -11,23 +11,35 @@ wn.module_page["Website"] = [
description: wn._("Content web page."), description: wn._("Content web page."),
doctype:"Web Page" doctype:"Web Page"
}, },
{
label: wn._("Blog"),
description: wn._("Blog entry."),
doctype:"Blog"
},
{ {
label: wn._("Website Slideshow"), label: wn._("Website Slideshow"),
description: wn._("Embed image slideshows in website pages."), description: wn._("Embed image slideshows in website pages."),
doctype:"Website Slideshow" doctype:"Website Slideshow"
}, },
]
},
{
title: wn._("Blog"),
icon: "icon-edit",
items: [
{
label: wn._("Blog"),
description: wn._("Blog post."),
doctype:"Blog"
},
{ {
label: wn._("Blogger"), label: wn._("Blogger"),
description: wn._("Profile of a blog writer."), description: wn._("Profile of a blog writer."),
doctype:"Blogger" doctype:"Blogger"
}, },
{
label: wn._("Blog Category"),
description: wn._("Categorize blog posts."),
doctype:"Blogger"
},
] ]
}, },
{ {
title: wn._("Website Overall Settings"), title: wn._("Website Overall Settings"),
icon: "icon-wrench", icon: "icon-wrench",

View File

@ -0,0 +1,12 @@
<div class="span12">
<hr />
<p><a href="blog">Show posts by everyone</a></p>
{% if categories %}
<h5>Explore posts by categories</h5>
<ul class="breadcrumb" style="background-color: transparent; padding-left: 0px;">
{% for category in categories %}
<li><a href="blog?category={{ category }}">{{ category }}</a>
{% if not loop.last %}<span class="divider">/</span>{% endif %}</li>
{% endfor %}
{% endif %}
</div>

View File

@ -14,7 +14,7 @@
<!-- begin blog content --> <!-- begin blog content -->
<div class="help" style="color: #aaa"> <div class="help" style="color: #aaa">
{{ blogger_info and blogger_info.full_name or full_name }} wrote this on {{ updated }}</div> {{ blogger_info and blogger_info.full_name or full_name }} / {{ updated }}</div>
<br> <br>
{{ content_html }} {{ content_html }}
<!-- end blog content --> <!-- end blog content -->
@ -30,23 +30,23 @@
<h4>{{ blogger_info.full_name }}</h4> <h4>{{ blogger_info.full_name }}</h4>
<p>{{ blogger_info.bio }}</p> <p>{{ blogger_info.bio }}</p>
<p><a href="blog?by={{ blogger_info.name }}&by_name={{ blogger_info.full_name }}"> <p><a href="blog?by={{ blogger_info.name }}&by_name={{ blogger_info.full_name }}">
All posts by {{ blogger_info.full_name }}</a></p> {{ texts.all_posts_by }} {{ blogger_info.full_name }}</a></p>
</div> </div>
</div> </div>
{% endif %} {% endif %}
<hr> <hr>
<h3>Comments</h3><br> <h3>{{ texts.comments }}</h3><br>
<div class="blog-comments"> <div class="blog-comments">
{% if not comment_list %} {% if not comment_list %}
<div class="no-comment"> <div class="no-comment">
<p>Be the first one to comment</p> <p>{{ texts.first_comment }}</p>
</div> </div>
{% endif %} {% endif %}
{% include 'html/comment.html' %} {% include 'html/comment.html' %}
</div> </div>
<div><button class="btn add-comment">Add Comment</button></div> <div><button class="btn add-comment">{{ texts.add_comment }}</button></div>
<div style="display: none; margin-top: 10px;" <div style="display: none; margin-top: 10px;"
id="comment-form"> id="comment-form">
<div class="alert" style="display:none;"></div> <div class="alert" style="display:none;"></div>
@ -56,11 +56,10 @@
<input name="comment_by" placeholder="Your Email Id" type="text"/><br> <input name="comment_by" placeholder="Your Email Id" type="text"/><br>
<textarea name="comment" placeholder="Comment" style="width: 300px; height: 120px;"/> <textarea name="comment" placeholder="Comment" style="width: 300px; height: 120px;"/>
</textarea><br> </textarea><br>
<button class="btn btn-info" id="submit-comment">Submit</button> <button class="btn btn-info" id="submit-comment">{{ texts.submit }}</button>
</fieldset> </fieldset>
</form> </form>
</div> </div>
<hr>
<a href="blog">Show posts by everyone</p>
</div> </div>
{% include 'html/blog_footer.html' %}
{% endblock %} {% endblock %}

View File

@ -26,8 +26,12 @@ $(document).ready(function() {
if(get_url_arg("by_name")) { if(get_url_arg("by_name")) {
$("#blog-title").html("Posts by " + get_url_arg("by_name")); $("#blog-title").html("Posts by " + get_url_arg("by_name"));
$("#blog-link").toggle(true);
} }
if(get_url_arg("category")) {
$("#blog-title").html("Posts filed under " + get_url_arg("category"));
}
}); });
var blog = { var blog = {
@ -39,7 +43,8 @@ var blog = {
data: { data: {
cmd: "website.helpers.blog.get_blog_list", cmd: "website.helpers.blog.get_blog_list",
start: blog.start, start: blog.start,
by: get_url_arg("by") by: get_url_arg("by"),
category: get_url_arg("category")
}, },
dataType: "json", dataType: "json",
success: function(data) { success: function(data) {

View File

@ -13,7 +13,6 @@
{% block content %} {% block content %}
<div class="span12"> <div class="span12">
<h2 id="blog-title">Blog</h2> <h2 id="blog-title">Blog</h2>
<p id="blog-link" style="display:none"><a href="blog">Show posts by everyone.</a></p>
<br> <br>
<div id="blog-list"> <div id="blog-list">
<!-- blog list will be generated dynamically --> <!-- blog list will be generated dynamically -->
@ -23,4 +22,5 @@
style="display:none;">More...</button> style="display:none;">More...</button>
</div> </div>
</div> </div>
{% include 'html/blog_footer.html' %}
{% endblock %} {% endblock %}

View File

@ -41,7 +41,8 @@ page_map = {
page_settings_map = { page_settings_map = {
"about": "About Us Settings", "about": "About Us Settings",
"contact": "Contact Us Settings" "contact": "Contact Us Settings",
"blog": "website.helpers.blog.get_blog_template_args"
} }
def render(page_name): def render(page_name):
@ -155,7 +156,11 @@ def prepare_args(page_name):
'name': page_name, 'name': page_name,
}) })
if page_name in page_settings_map: if page_name in page_settings_map:
args.obj = webnotes.bean(page_settings_map[page_name]).obj target = page_settings_map[page_name]
if "." in target:
args.update(webnotes.get_method(target)())
else:
args.obj = webnotes.bean(page_settings_map[page_name]).obj
else: else:
args = get_doc_fields(page_name) args = get_doc_fields(page_name)