Преглед изворни кода

fixes to website

version-14
Rushabh Mehta пре 11 година
родитељ
комит
c9b02586fc
16 измењених фајлова са 143 додато и 78 уклоњено
  1. +2
    -2
      webnotes/__init__.py
  2. +1
    -1
      webnotes/public/js/wn/views/formview.js
  3. +1
    -1
      webnotes/templates/generators/web_page.html
  4. +5
    -5
      webnotes/templates/generators/website_group.py
  5. +2
    -4
      webnotes/templates/includes/breadcrumbs.html
  6. +2
    -2
      webnotes/templates/includes/inline_post.html
  7. +1
    -1
      webnotes/templates/includes/navbar.html
  8. +7
    -7
      webnotes/templates/website_group/forum.py
  9. +2
    -2
      webnotes/templates/website_group/post.py
  10. +10
    -10
      webnotes/website/doctype/web_page/web_page.txt
  11. +29
    -7
      webnotes/website/doctype/website_group/website_group.txt
  12. +39
    -5
      webnotes/website/doctype/website_sitemap/website_sitemap.py
  13. +1
    -1
      webnotes/website/js/website.js
  14. +1
    -1
      webnotes/website/js/website_group.js
  15. +5
    -0
      webnotes/website/page/website_home/website_home.js
  16. +35
    -29
      webnotes/webutils.py

+ 2
- 2
webnotes/__init__.py Прегледај датотеку

@@ -364,9 +364,9 @@ def reload_doc(module, dt=None, dn=None, force=False):
import webnotes.modules
return webnotes.modules.reload_doc(module, dt, dn, force=force)

def rename_doc(doctype, old, new, debug=0, force=False, merge=False):
def rename_doc(doctype, old, new, debug=0, force=False, merge=False, ignore_permissions=False):
from webnotes.model.rename_doc import rename_doc
return rename_doc(doctype, old, new, force=force, merge=merge)
return rename_doc(doctype, old, new, force=force, merge=merge, ignore_permissions=ignore_permissions)

def insert(doclist):
import webnotes.model


+ 1
- 1
webnotes/public/js/wn/views/formview.js Прегледај датотеку

@@ -37,7 +37,7 @@ wn.views.FormFactory = wn.views.Factory.extend({
// doc not found, but starts with New,
// make a new doc and set it
var new_str = wn._("New") + " ";
if(dn && dn.substr(0, new_str.length)==new_star) {
if(dn && dn.substr(0, new_str.length)==new_str) {
var new_name = wn.model.make_new_doc_and_get_name(dt);
if(new_name===dn) {
me.load(dt, dn);


+ 1
- 1
webnotes/templates/generators/web_page.html Прегледај датотеку

@@ -1,6 +1,6 @@
{% block title %} {{ title }} {% endblock %}

{% block header %}{% if show_title %}<h2>{{ title }}</h2>{% endif %}{% endblock %}
{% block header %}<h2>{{ title }}</h2>{% endblock %}

{% block breadcrumbs %}{% include "templates/includes/breadcrumbs.html" %}{% endblock %}



+ 5
- 5
webnotes/templates/generators/website_group.py Прегледај датотеку

@@ -16,7 +16,7 @@ def get_context(context):
if not has_access(group, view):
raise webnotes.PermissionError
group_context = get_group_context(group, view, bean)
group_context = get_group_context(group, view, bean, context)
group_context["access"] = get_access(group)
group_context.update(context)
@@ -33,7 +33,7 @@ def get_context(context):
'You are not permitted to view this page.</div>'
}
def get_group_context(group, view, bean):
def get_group_context(group, view, bean, context):
cache_key = "website_group_context:{}:{}".format(group, view)
views = get_views(bean.doc.group_type)
view = webnotes._dict(views.get(view))
@@ -43,18 +43,18 @@ def get_group_context(group, view, bean):
if group_context:
return group_context
group_context = build_group_context(group, view, bean, views)
group_context = build_group_context(group, view, bean, views, context)
if can_cache(view.get("no_cache")):
webnotes.cache().set_value(cache_key, group_context)
return group_context
def build_group_context(group, view, bean, views):
def build_group_context(group, view, bean, views, context):
title = "{} - {}".format(bean.doc.group_title, view.get("label"))
for name, opts in views.iteritems():
opts["url"] = opts["url"].format(group=group, post="")
opts["url"] = opts["url"].format(pathname=context.pathname, post="")
group_context = webnotes._dict({
"group": bean.doc.fields,


+ 2
- 4
webnotes/templates/includes/breadcrumbs.html Прегледај датотеку

@@ -1,8 +1,6 @@
{% if parents -%}
<ul class="breadcrumb">
{% for parent in parents %}
{% for parent in parents or [] %}
<li><a href="/{{ parent.name|lower }}">{{ parent.page_title or parent.title }}</a></li>
{% endfor %}
<li class="active">{{ title }}</li>
</ul>
{%- endif %}
</ul>

+ 2
- 2
webnotes/templates/includes/inline_post.html Прегледај датотеку

@@ -1,5 +1,5 @@
{% set post_url = "/" + post.website_group + "?view=post&name=" + post.name %}
{% set edit_url = "/" + post.website_group + "?view=edit&name=" + post.name %}
{% set post_url = webnotes.local.request.path + "?view=post&name=" + post.name %}
{% set edit_url = webnotes.local.request.path + "?view=edit&name=" + post.name %}

<div class="media post {% if post.parent_post -%} child-post {%- endif %}"
data-name="{{ post.name }}"


+ 1
- 1
webnotes/templates/includes/navbar.html Прегледај датотеку

@@ -10,7 +10,7 @@
<span class="icon-bar"></span>
</button>
<a class="navbar-brand ellipsis" href="/">
<span>{{ brand_html or "<i class='icon-home'></i>"}}</span>
<span>{{ brand_html or "Home"}}</span>
</a>
</div>
<div class="collapse navbar-collapse navbar-responsive-collapse">


+ 7
- 7
webnotes/templates/website_group/forum.py Прегледај датотеку

@@ -56,7 +56,7 @@ def get_post_list_html(group, view, limit_start=0, limit_length=20):
where p.website_group = %s and pr.name = p.owner and ifnull(p.parent_post, '')=''
order by {order_by} limit %s, %s""".format(order_by=order_by),
(group, int(limit_start), int(limit_length)), as_dict=True)
context = {"posts": posts, "limit_start": limit_start, "view": view}
return webnotes.get_template("templates/includes/post_list.html").render(context)
@@ -65,7 +65,7 @@ views = {
"popular": {
"name": "popular",
"template_path": "templates/website_group/forum.html",
"url": "/{group}",
"url": "{pathname}",
"label": "Popular",
"icon": "icon-heart",
"default": True,
@@ -75,7 +75,7 @@ views = {
"feed": {
"name": "feed",
"template_path": "templates/website_group/forum.html",
"url": "/{group}?view=feed",
"url": "/{pathname}?view=feed",
"label": "Feed",
"icon": "icon-rss",
"upvote": True,
@@ -84,7 +84,7 @@ views = {
"post": {
"name": "post",
"template_path": "templates/website_group/post.html",
"url": "/{group}?view=post&name={post}",
"url": "/{pathname}?view=post&name={post}",
"label": "Post",
"icon": "icon-comments",
"upvote": True,
@@ -95,7 +95,7 @@ views = {
"edit": {
"name": "edit",
"template_path": "templates/website_group/edit_post.html",
"url": "/{group}?view=edit&name={post}",
"url": "/{pathname}?view=edit&name={post}",
"label": "Edit Post",
"icon": "icon-pencil",
"hidden": True,
@@ -105,7 +105,7 @@ views = {
"add": {
"name": "add",
"template_path": "templates/website_group/edit_post.html",
"url": "/{group}?view=add",
"url": "/{pathname}?view=add",
"label": "Add Post",
"icon": "icon-plus",
"hidden": True,
@@ -114,7 +114,7 @@ views = {
"settings": {
"name": "settings",
"template_path": "templates/website_group/settings.html",
"url": "/{group}?view=settings",
"url": "/{pathname}?view=settings",
"label": "Settings",
"icon": "icon-cog",
"hidden": True,


+ 2
- 2
webnotes/templates/website_group/post.py Прегледај датотеку

@@ -20,12 +20,12 @@ def get_post_context(group_context):
"parent_post": post.name
}
cache_key = "website_group_post:".format(post.name)
cache_key = "website_group_post:{}".format(post.name)
return webnotes.cache().get_value(cache_key, lambda: _get_post_context())
def get_parent_post_html(post, view):
profile = webnotes.bean("Profile", post.owner).doc
for fieldname in ("first_name", "last_name", "user_image", "fb_hometown", "fb_location"):
for fieldname in ("first_name", "last_name", "user_image", "location"):
post.fields[fieldname] = profile.fields[fieldname]
return webnotes.get_template("templates/includes/inline_post.html")\


+ 10
- 10
webnotes/website/doctype/web_page/web_page.txt Прегледај датотеку

@@ -2,7 +2,7 @@
{
"creation": "2013-03-28 10:35:30",
"docstatus": 0,
"modified": "2014-02-05 17:02:09",
"modified": "2014-02-10 16:17:48",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -61,13 +61,20 @@
"reqd": 1
},
{
"description": "Page url name (auto-generated) (add \".html\")",
"description": "Page url name (auto-generated)",
"doctype": "DocField",
"fieldname": "page_name",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Page Name",
"read_only": 1
"read_only": 0
},
{
"doctype": "DocField",
"fieldname": "parent_website_sitemap",
"fieldtype": "Link",
"label": "Parent Website Page",
"options": "Website Sitemap"
},
{
"doctype": "DocField",
@@ -185,13 +192,6 @@
"label": "Table of Contents",
"options": "Table of Contents"
},
{
"doctype": "DocField",
"fieldname": "parent_website_sitemap",
"fieldtype": "Link",
"label": "Parent Website Page",
"options": "Website Sitemap"
},
{
"doctype": "DocPerm"
}

+ 29
- 7
webnotes/website/doctype/website_group/website_group.txt Прегледај датотеку

@@ -2,7 +2,7 @@
{
"creation": "2014-01-29 15:57:42",
"docstatus": 0,
"modified": "2014-02-05 17:00:33",
"modified": "2014-02-10 14:38:12",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -39,6 +39,12 @@
"doctype": "DocType",
"name": "Website Group"
},
{
"doctype": "DocField",
"fieldname": "name_and_description",
"fieldtype": "Section Break",
"label": "Name and Description"
},
{
"doctype": "DocField",
"fieldname": "group_name",
@@ -62,6 +68,20 @@
"options": "Forum\nTasks\nEvents",
"reqd": 1
},
{
"description": "Display in the sidebar of this Website Sitemap node",
"doctype": "DocField",
"fieldname": "parent_website_sitemap",
"fieldtype": "Link",
"in_list_view": 0,
"label": "Parent Website Page",
"options": "Website Sitemap"
},
{
"doctype": "DocField",
"fieldname": "column_break_6",
"fieldtype": "Column Break"
},
{
"doctype": "DocField",
"fieldname": "group_description",
@@ -77,6 +97,12 @@
"no_copy": 1,
"reqd": 0
},
{
"doctype": "DocField",
"fieldname": "details",
"fieldtype": "Section Break",
"label": "Details"
},
{
"doctype": "DocField",
"fieldname": "public_read",
@@ -90,13 +116,9 @@
"label": "Anyone Can Write"
},
{
"description": "Display in the sidebar of this Website Sitemap node",
"doctype": "DocField",
"fieldname": "parent_website_sitemap",
"fieldtype": "Link",
"in_list_view": 0,
"label": "Parent Website Page",
"options": "Website Sitemap"
"fieldname": "column_break_12",
"fieldtype": "Column Break"
},
{
"doctype": "DocField",


+ 39
- 5
webnotes/website/doctype/website_sitemap/website_sitemap.py Прегледај датотеку

@@ -17,12 +17,46 @@ class DocType(DocTypeNestedSet):
self.nsm_parent_field = "parent_website_sitemap"
def autoname(self):
self.doc.name = self.doc.page_name
self.doc.name = self.get_url()

def get_url(self):
url = self.doc.page_name
if self.doc.parent_website_sitemap:
url = self.doc.parent_website_sitemap + "/" + url
return url
def validate(self):
if self.get_url() != self.doc.name:
self.rename()
self.check_if_page_name_is_unique()
self.make_private_if_parent_is_private()
def rename(self):
from webnotes.webutils import clear_cache
self.old_name = self.doc.name
self.doc.name = self.get_url()
webnotes.conn.sql("""update `tabWebsite Sitemap` set name=%s where name=%s""",
(self.doc.name, self.old_name))
self.rename_links()
self.rename_descendants()
clear_cache(self.old_name)

def rename_links(self):
for doctype in webnotes.conn.sql_list("""select parent from tabDocField where fieldtype='Link' and
fieldname='parent_website_sitemap' and options='Website Sitemap'"""):
for name in webnotes.conn.sql_list("""select name from `tab{}`
where parent_website_sitemap=%s""".format(doctype), self.old_name):
webnotes.conn.set_value(doctype, name, "parent_website_sitemap", self.doc.name)
def rename_descendants(self):
# rename children
for name in webnotes.conn.sql_list("""select name from `tabWebsite Sitemap`
where parent_website_sitemap=%s""", self.doc.name):
child = webnotes.bean("Website Sitemap", name)
child.doc.parent_website_sitemap = self.doc.name
child.save()
def on_update(self):
if not webnotes.flags.in_rebuild_config:
DocTypeNestedSet.on_update(self)
@@ -50,10 +84,9 @@ class DocType(DocTypeNestedSet):
if not parent_pubic_read:
self.doc.public_read = self.doc.public_write = 0
def on_trash(self):
def on_trash(self):
from webnotes.webutils import clear_cache
# remove website sitemap permissions
to_remove = webnotes.conn.sql_list("""select name from `tabWebsite Sitemap Permission`
where website_sitemap=%s""", (self.doc.name,))
@@ -78,6 +111,7 @@ def update_sitemap(website_sitemap, options):
for key in sitemap_fields:
bean.doc.fields[key] = options.get(key)
if not bean.doc.page_name:
# for pages
bean.doc.page_name = options.link_name
bean.doc.website_sitemap_config = options.link_name


+ 1
- 1
webnotes/website/js/website.js Прегледај датотеку

@@ -424,7 +424,7 @@ $(document).ready(function() {
$(document).on("page_change", function() {
$(".page-header").toggleClass("hidden", !!!$(".page-header").text().trim());
$(".page-footer").toggleClass("hidden", !!!$(".page-footer").text().trim());
$(".page-breadcrumbs").toggleClass("hidden", !!!$(".page-breadcrumbs").text().trim());
//$(".page-breadcrumbs").toggleClass("hidden", !!!$(".page-breadcrumbs").text().trim());

// add prive pages to sidebar
if(website.private_pages && $(".page-sidebar").length) {


+ 1
- 1
webnotes/website/js/website_group.js Прегледај датотеку

@@ -77,7 +77,7 @@ $.extend(website, {
post: website.post || undefined
}, values),
callback: function(data) {
var url = "/" + website.group + "?view=post&name=" + data.message;
var url = window.location.pathname + "?view=post&name=" + data.message;
window.location.href = url;
// if(history.pushState) {


+ 5
- 0
webnotes/website/page/website_home/website_home.js Прегледај датотеку

@@ -12,6 +12,11 @@ wn.module_page["Website"] = [
description: wn._("Content web page."),
doctype:"Web Page"
},
{
label: wn._("Website Group"),
description: wn._("Web Site Forum Page."),
doctype:"Web Page"
},
{
label: wn._("Blog Post"),
description: wn._("Single Post (article)."),


+ 35
- 29
webnotes/webutils.py Прегледај датотеку

@@ -77,7 +77,7 @@ def build_page(page_name):
html = webnotes.get_template(context.base_template_path).render(context)
html = scrub_relative_urls(html)
if can_cache(context.no_cache):
webnotes.cache().set_value("page:" + page_name, html)
@@ -115,12 +115,7 @@ def get_sitemap_options(page_name):
def build_sitemap_options(page_name):
sitemap_options = webnotes.doc("Website Sitemap", page_name).fields
# only non default fields
for fieldname in default_fields:
if fieldname in sitemap_options:
del sitemap_options[fieldname]
sitemap_config = webnotes.doc("Website Sitemap Config",
sitemap_options.get("website_sitemap_config")).fields
@@ -131,6 +126,7 @@ def build_sitemap_options(page_name):
sitemap_options.doctype = sitemap_options.ref_doctype
sitemap_options.title = sitemap_options.page_title
sitemap_options.pathname = sitemap_options.name
# establish hierarchy
sitemap_options.parents = webnotes.conn.sql("""select name, page_title from `tabWebsite Sitemap`
@@ -243,10 +239,7 @@ def is_ajax():
def scrub_page_name(page_name):
if not page_name:
page_name = "index"
if "/" in page_name:
page_name = page_name.split("/")[0]
if page_name.endswith('.html'):
page_name = page_name[:-5]
@@ -305,6 +298,16 @@ def call_website_generator(bean, method):
getattr(WebsiteGenerator(bean.doc, bean.doclist), method)()
class WebsiteGenerator(DocListController):
def set_page_name(self):
"""set page name based on parent page_name and title"""
page_name = cleanup_page_name(self.get_page_title)
if self.doc.parent_website_sitemap:
page_name = self.doc.parent_website_sitemap + "/" + page_name

webnotes.conn.set(self.doc, self._website_config.page_name_field, page_name)

return page_name
def setup_generator(self):
if webnotes.flags.in_install_app:
return
@@ -343,7 +346,7 @@ class WebsiteGenerator(DocListController):
def add_or_update_sitemap(self):
page_name = self.get_page_name()
existing_page_name = webnotes.conn.get_value("Website Sitemap", {"ref_doctype": self.doc.doctype,
existing_site_map = webnotes.conn.get_value("Website Sitemap", {"ref_doctype": self.doc.doctype,
"docname": self.doc.name})
opts = webnotes._dict({
@@ -354,32 +357,35 @@ class WebsiteGenerator(DocListController):
"link_name": self._website_config.name,
"lastmod": webnotes.utils.get_datetime(self.doc.modified).strftime("%Y-%m-%d"),
"parent_website_sitemap": self.doc.parent_website_sitemap,
"page_title": self.get_page_title() \
if hasattr(self, "get_page_title") else (self.doc.title or self.doc.name)
"page_title": self.get_page_title()
})

self.update_permissions(opts)

if existing_site_map:
update_sitemap(existing_site_map, opts)
else:
add_to_sitemap(opts)
def update_permissions(self, opts):
if self.meta.get_field("public_read"):
opts.public_read = self.doc.public_read
opts.public_write = self.doc.public_write
else:
opts.public_read = 1
if existing_page_name:
if existing_page_name != page_name:
webnotes.rename_doc("Website Sitemap", existing_page_name, page_name, ignore_permissions=True)
update_sitemap(page_name, opts)
else:
add_to_sitemap(opts)
def get_page_name(self):
if not self.doc.fields.get(self._website_config.page_name_field):
new_page_name = cleanup_page_name(self.get_page_title() \
if hasattr(self, "get_page_title") else (self.doc.title or self.doc.name))
webnotes.conn.set(self.doc, self._website_config.page_name_field, new_page_name)
def get_page_name(self):
if not self._get_page_name():
self.set_page_name()
return self._get_page_name()
def _get_page_name(self):
return self.doc.fields.get(self._website_config.page_name_field)
def get_page_title(self):
return self.doc.title or (self.doc.name.replace("-", " ").replace("_", " ").title())
def cleanup_page_name(title):
"""make page name from title"""
import re
@@ -425,7 +431,7 @@ def render_blocks(context):
out = {}
template = webnotes.get_template(context["template_path"])
# required as per low level API
context = template.new_context(context)


Loading…
Откажи
Сачувај