Browse Source

[fixes] website

version-14
Rushabh Mehta 9 years ago
parent
commit
19ce3e7586
7 changed files with 42 additions and 28 deletions
  1. +13
    -0
      frappe/core/doctype/doctype/doctype.py
  2. +1
    -1
      frappe/public/js/legacy/form.js
  3. +1
    -1
      frappe/templates/generators/blog_post.html
  4. +1
    -1
      frappe/templates/includes/blog/blog_row.html
  5. +19
    -21
      frappe/templates/includes/search_box.html
  6. +1
    -1
      frappe/website/doctype/blog_category/blog_category.json
  7. +6
    -3
      frappe/website/doctype/blog_post/blog_post.py

+ 13
- 0
frappe/core/doctype/doctype/doctype.py View File

@@ -58,6 +58,7 @@ class DocType(Document):
validate_permissions(self) validate_permissions(self)


self.make_amendable() self.make_amendable()
self.validate_website()


def check_developer_mode(self): def check_developer_mode(self):
"""Throw exception if not developer mode or via patch""" """Throw exception if not developer mode or via patch"""
@@ -73,6 +74,18 @@ class DocType(Document):
if self.document_type=="Master": if self.document_type=="Master":
self.document_type = "Setup" self.document_type = "Setup"


def validate_website(self):
"""Ensure that website generator has field 'route'"""
from frappe.model.base_document import get_controller
try:
controller = get_controller(self.name)
except:
controller = None

if controller and controller.website:
if not 'route' in [d.fieldname for d in self.fields]:
frappe.throw('Field "route" is mandatory for Website Generator pages', title='Missing Field')

def change_modified_of_parent(self): def change_modified_of_parent(self):
"""Change the timestamp of parent DocType if the current one is a child to clear caches.""" """Change the timestamp of parent DocType if the current one is a child to clear caches."""
if frappe.flags.in_import: if frappe.flags.in_import:


+ 1
- 1
frappe/public/js/legacy/form.js View File

@@ -365,7 +365,7 @@ _f.Frm.prototype.show_web_link = function() {


_f.Frm.prototype.add_web_link = function(path) { _f.Frm.prototype.add_web_link = function(path) {
this.web_link = this.sidebar.add_user_action("See on Website", this.web_link = this.sidebar.add_user_action("See on Website",
function() {}).attr("href", path).attr("target", "_blank");
function() {}).attr("href", this.doc.route).attr("target", "_blank");
} }


_f.Frm.prototype.check_doc_perm = function() { _f.Frm.prototype.check_doc_perm = function() {


+ 1
- 1
frappe/templates/generators/blog_post.html View File

@@ -11,7 +11,7 @@
<p class="post-by text-muted"> <p class="post-by text-muted">
<a href="/blog?by={{ blogger }}&by_name={{ full_name }}" class="no-decoration">By {{ blogger_info and blogger_info.full_name or full_name }}</a> <a href="/blog?by={{ blogger }}&by_name={{ full_name }}" class="no-decoration">By {{ blogger_info and blogger_info.full_name or full_name }}</a>
<i class="blog-dot"></i> {{ frappe.format_date(published_on) }} <i class="blog-dot"></i> {{ frappe.format_date(published_on) }}
<i class="blog-dot"></i> <a href="/{{ category.route }}" class="no-decoration">{{ blog_category }}</a>
<i class="blog-dot"></i> <a href="/{{ category.route }}" class="no-decoration">{{ category.title }}</a>
<i class="blog-dot"></i> {{ comment_text }} <i class="blog-dot"></i> {{ comment_text }}
</p> </p>
</div> </div>


+ 1
- 1
frappe/templates/includes/blog/blog_row.html View File

@@ -8,7 +8,7 @@
<a href="/blog?by={{ post.blogger }}&by_name={{ post.full_name }}" class="no-decoration">By {{ post.full_name }}</a> <a href="/blog?by={{ post.blogger }}&by_name={{ post.full_name }}" class="no-decoration">By {{ post.full_name }}</a>
<i class="blog-dot"></i> {{ frappe.format_date(post.published_on) }} <i class="blog-dot"></i> {{ frappe.format_date(post.published_on) }}
<i class="blog-dot"></i> <i class="blog-dot"></i>
<a href="/{{ post.blog_category_route }}" class="no-decoration">{{ post.blog_category }}</a>
<a href="/{{ post.category.route }}" class="no-decoration">{{ post.category.title }}</a>
<i class="blog-dot"></i> {{ post.comment_text }} <i class="blog-dot"></i> {{ post.comment_text }}
</p> </p>
</div> </div>


+ 19
- 21
frappe/templates/includes/search_box.html View File

@@ -1,39 +1,37 @@
<div class="item-search text-muted pull-right"> <div class="item-search text-muted pull-right">
<input type="text" class="item-search-input" <input type="text" class="item-search-input"
placeholder="Search" autocomplete="off"> placeholder="Search" autocomplete="off">
<i class="octicon octicon-search"></i>
<i class="octicon octicon-search" style='cursor: pointer;'></i>
</div> </div>
<div class="clearfix pull-right" style="width:300px;"> <div class="clearfix pull-right" style="width:300px;">
<h4 class="item-search-results pull-left"></h4>
<p class="pull-right">
<a style="display: none; padding-left:5px;" href="javascript:history.back();" class="octicon octicon-x text-extra-muted clear" title="Clear Search" ></a>
<h5 class="item-search-results text-muted text-right" style="margin-right: 30px;"></h5>
<p class="pull-right" style="margin-top: -28px;">
<a style="display: none;" href="javascript:history.back();" class="octicon octicon-x text-extra-muted clear" title="Clear Search" ></a>
</p> </p>
</div> </div>


<script> <script>
frappe.ready(function() { frappe.ready(function() {
if(get_url_arg("search")){
var txt = get_url_arg("search");
$(".item-search-results").html("Search results for : " + txt);
$(".item-search").toggle(false);
$(".clear").toggle(true);
if(get_url_arg("search")) {
var txt = get_url_arg("search");
$(".item-search-results").html("{{ _('Search results for') }}: " + txt);
$(".item-search").toggle(false);
$(".clear").toggle(true);
} }
var thread = null; var thread = null;
function findResult(t) {
if (window.location.href.indexOf("?") > -1)
{
window.location.href=document.URL + "&search=" + t;
}
else
{
window.location.href=document.URL + "?search=" + t;
}
function find_result(t) {
var search_link = "{{ search_link or '' }}" || location.pathname;
window.location.href=search_link + "?search=" + t;
} }


$(".item-search-input").keyup(function() {
clearTimeout(thread);
var $this = $(this); thread = setTimeout(function(){findResult($this.val())}, 1000);
$(".item-search-input").keyup(function(e) {
if(e.which===13) {
find_result($(this).val());
}
}); });
$('.octicon-search').on('click', function() {
find_result($(".item-search-input").val());
})
$(".form-search").on("submit", function() { return false; }); $(".form-search").on("submit", function() { return false; });
}); });
</script> </script>

+ 1
- 1
frappe/website/doctype/blog_category/blog_category.json View File

@@ -120,7 +120,7 @@
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2016-06-23 14:45:10.682909",
"modified": "2016-06-27 12:25:12.502119",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Website", "module": "Website",
"name": "Blog Category", "name": "Blog Category",


+ 6
- 3
frappe/website/doctype/blog_post/blog_post.py View File

@@ -84,8 +84,10 @@ class BlogPost(WebsiteGenerator):
else: else:
context.comment_text = _('{0} comments').format(len(context.comment_list)) context.comment_text = _('{0} comments').format(len(context.comment_list))


context.category = frappe.db.get_value("Blog Category", context.doc.blog_category, ["title", "route"], as_dict=1)
context.parents = [{"title": context.category.title, "name": context.category.route}]
context.category = frappe.db.get_value("Blog Category",
context.doc.blog_category, ["title", "route"], as_dict=1)
context.parents = [{"title": context.category.title, "name":
context.category.route}]


def get_list_context(context=None): def get_list_context(context=None):
list_context = frappe._dict( list_context = frappe._dict(
@@ -178,7 +180,8 @@ def get_blog_list(doctype, txt=None, filters=None, limit_start=0, limit_page_len
post.comment_text = _('{0} comments').format(str(post.comments)) post.comment_text = _('{0} comments').format(str(post.comments))


post.avatar = post.avatar or "" post.avatar = post.avatar or ""
post.blog_category_route = frappe.db.get_value('Blog Post', post.blog_category, 'route')
post.category = frappe.db.get_value('Blog Category', post.blog_category,
['route', 'title'], as_dict=True)


if (not "http:" in post.avatar or "https:" in post.avatar) and not post.avatar.startswith("/"): if (not "http:" in post.avatar or "https:" in post.avatar) and not post.avatar.startswith("/"):
post.avatar = "/" + post.avatar post.avatar = "/" + post.avatar


Loading…
Cancel
Save