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 website.utils
from webnotes import _
class DocType:
def __init__(self, d, dl):
@ -73,6 +74,16 @@ class DocType:
self.doc.blogger_info = webnotes.doc("blogger", self.doc.blogger).fields
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.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

View File

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

@ -32,6 +32,11 @@ div.outer {
{% if doc.google_web_font_for_heading or doc.heading_font %}
h1, h2, h3, h4, h5 {
font-family: '{{ doc.google_web_font_for_heading or doc.heading_font }}', Arial, 'Helvetica Neue' !important;
}
{% endif %}
{% if doc.heading_text_as %}
h1, h2, h3, h4, h5 {
text-transform: {{ doc.heading_text_as }};
}
{% endif %}

View File

@ -57,10 +57,16 @@ class DocType:
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 = ""
for f in fonts:
self.doc.at_import += "\n@import url(http://fonts.googleapis.com/css?family=%s);" % f.replace(" ", "+")
def on_update(self):

View File

@ -2,7 +2,7 @@
{
"creation": "2013-01-25 11:35:10",
"docstatus": 0,
"modified": "2013-03-07 16:06:22",
"modified": "2013-03-08 09:58:49",
"modified_by": "Administrator",
"owner": "Administrator"
},
@ -119,6 +119,13 @@
"label": "Font Size (Text)",
"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",
"fieldname": "column_break_13",

View File

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

View File

@ -6,11 +6,13 @@ import webnotes
import website.utils
@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
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.creation as creation,
@ -115,4 +117,8 @@ def get_blog_content(blog_page_name):
import webnotes.utils
content = webnotes.utils.escape_html(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."),
doctype:"Web Page"
},
{
label: wn._("Blog"),
description: wn._("Blog entry."),
doctype:"Blog"
},
{
label: wn._("Website Slideshow"),
description: wn._("Embed image slideshows in website pages."),
doctype:"Website Slideshow"
},
]
},
{
title: wn._("Blog"),
icon: "icon-edit",
items: [
{
label: wn._("Blog"),
description: wn._("Blog post."),
doctype:"Blog"
},
{
label: wn._("Blogger"),
description: wn._("Profile of a blog writer."),
doctype:"Blogger"
},
{
label: wn._("Blog Category"),
description: wn._("Categorize blog posts."),
doctype:"Blogger"
},
]
},
{
title: wn._("Website Overall Settings"),
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 -->
<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>
{{ content_html }}
<!-- end blog content -->
@ -30,23 +30,23 @@
<h4>{{ blogger_info.full_name }}</h4>
<p>{{ blogger_info.bio }}</p>
<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>
{% endif %}
<hr>
<h3>Comments</h3><br>
<h3>{{ texts.comments }}</h3><br>
<div class="blog-comments">
{% if not comment_list %}
<div class="no-comment">
<p>Be the first one to comment</p>
<p>{{ texts.first_comment }}</p>
</div>
{% endif %}
{% include 'html/comment.html' %}
</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;"
id="comment-form">
<div class="alert" style="display:none;"></div>
@ -56,11 +56,10 @@
<input name="comment_by" placeholder="Your Email Id" type="text"/><br>
<textarea name="comment" placeholder="Comment" style="width: 300px; height: 120px;"/>
</textarea><br>
<button class="btn btn-info" id="submit-comment">Submit</button>
<button class="btn btn-info" id="submit-comment">{{ texts.submit }}</button>
</fieldset>
</form>
</div>
<hr>
<a href="blog">Show posts by everyone</p>
</div>
{% include 'html/blog_footer.html' %}
{% endblock %}

View File

@ -26,8 +26,12 @@ $(document).ready(function() {
if(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 = {
@ -39,7 +43,8 @@ var blog = {
data: {
cmd: "website.helpers.blog.get_blog_list",
start: blog.start,
by: get_url_arg("by")
by: get_url_arg("by"),
category: get_url_arg("category")
},
dataType: "json",
success: function(data) {

View File

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

View File

@ -41,7 +41,8 @@ page_map = {
page_settings_map = {
"about": "About Us Settings",
"contact": "Contact Us Settings"
"contact": "Contact Us Settings",
"blog": "website.helpers.blog.get_blog_template_args"
}
def render(page_name):
@ -155,7 +156,11 @@ def prepare_args(page_name):
'name': page_name,
})
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:
args = get_doc_fields(page_name)