[website] add full_index and list cleanups

This commit is contained in:
Rushabh Mehta 2015-03-23 18:39:48 +05:30
parent fe8273a594
commit acc314d0ab
11 changed files with 81 additions and 29 deletions

View file

@ -35,7 +35,7 @@
{%- for link in web_include_js %}
<script type="text/javascript" src="{{ link }}"></script>
{%- endfor -%}
{%- block head_include %}{% endblock -%}
{%- block head_include %}{{ head_include or "" }}{% endblock -%}
{%- endblock -%}
</head>
<body>
@ -97,5 +97,6 @@
{%- if script_lib is defined -%}{{ script_lib }}{%- endif -%}
</script>
{%- endblock -%}
{%- block body_include %}{{ body_include or "" }}{% endblock -%}
</body>
</html>

View file

@ -0,0 +1,12 @@
{% macro make_item_list(item_list) %}
<ol>
{% for item in item_list %}
<li>
<a href="{{ item.url }}">{{ item.title }}</a>
{% if item.children %}{{ make_item_list(item.children) }}{% endif %}
</li>
{% endfor %}
</ol>
{% endmacro %}
{{ make_item_list(full_index) }}

View file

@ -1,7 +1,8 @@
<div class="website-list" data-doctype="{{ doctype }}" data-txt="{{ txt or '[notxt]' }}">
{% if not hide_filters -%}
{% include "templates/includes/list/filters.html" %}
{%- endif %}
<!-- {% if not hide_filters -%}
{% include "templates/includes/list/filters.html" %}
{%- endif %} -->
<div class="result">
{% for item in result %}

View file

@ -1,21 +1,7 @@
{% set doc = frappe.get_doc(doc) %}
{% set subject = doc.get(meta.title_field or "name") %}
<a class="website-list-row" href="/{{ pathname or doc.doctype }}/{{ doc.name }}" no-pjax>
<div class="row">
<div class="{% if subject == doc.name -%} col-sm-10 {%- else %} col-sm-6 {%- endif %} col-xs-7">
<div class="row">
<div class="col-sm-9">{{ subject }}</div>
<div class="col-sm-3">
{{ doc.status or "" }}
</div>
</div>
</div>
{% if subject != doc.name %}
<div class="col-sm-2 text-muted text-right">
{{ doc.name }}
</div>
{% endif %}
<div class="col-sm-2 small text-muted text-right" title="{{ frappe.utils.format_datetime(doc.creation, "medium") }}">
{{ frappe.utils.pretty_date(doc.creation) }}</div>
<div class="web-list-item">
<a class="no-decoration" href="/{{ doc.get_route() }}" no-pjax>
<p>{{ subject }}</p>
</a>
</div>
</a>

View file

@ -1,6 +1,16 @@
{% block title %}{{ title or (_("{0} List").format(_(doctype))) }}{% endblock %}
{% block header %}<h2>{{ title or (_("{0} List").format(_(doctype))) }}</h2>{% endblock %}
{% block header %}
{% if default_subtitle %}
<div class="list-hero">
<h1>
{{ default_subtitle }}
</h1>
</div>
{% else %}
<h1>{{ title or (_("{0} List").format(_(doctype))) }}</h1>
{% endif %}
{% endblock %}
{% block content %}{% include "templates/includes/list/list.html" %}{% endblock %}

View file

@ -5,6 +5,7 @@ from __future__ import unicode_literals
import frappe
from frappe.utils import cint
from frappe.website.render import resolve_path
from frappe import _
no_cache = 1
no_sitemap = 1
@ -54,6 +55,9 @@ def get(doctype, txt=None, limit_start=0, **kwargs):
show_more = (_get_list(doctype=doctype, txt=txt, filters=filters,
limit_start=next_start, limit_page_length=1) and True or False)
if txt:
list_context.default_subtitle = _('Filtered by "{0}"').format(txt)
result = []
row_template = list_context.row_template or "templates/includes/list/row_template.html"
for doc in raw_result:
@ -95,7 +99,7 @@ def get_list(doctype, txt, filters, limit_start, limit_page_length=20, ignore_pe
else:
filters.append([doctype, "name", "like", "%" + txt + "%"])
return frappe.get_list(doctype, fields = ["*"],
return frappe.get_list(doctype, fields = "distinct *",
filters=filters, or_filters=or_filters, limit_start=limit_start,
limit_page_length = limit_page_length, ignore_permissions=ignore_permissions)

View file

@ -200,7 +200,7 @@
"icon": "icon-file-alt",
"idx": 1,
"max_attachments": 20,
"modified": "2015-02-20 08:30:53.345780",
"modified": "2015-03-23 17:57:49.375385",
"modified_by": "Administrator",
"module": "Website",
"name": "Web Page",
@ -221,5 +221,6 @@
"write": 1
}
],
"search_fields": "title,main_section",
"title_field": "title"
}

View file

@ -11,6 +11,7 @@ from frappe.website.utils import find_first_image, get_comment_list
from markdown2 import markdown
from frappe.utils.jinja import render_template
from jinja2.exceptions import TemplateSyntaxError
from frappe import _
class WebPage(WebsiteGenerator):
save_versions = True
@ -147,6 +148,22 @@ class WebPage(WebsiteGenerator):
if image:
context.metatags["image"] = image
# def get_list_context(context=None):
# list_context = frappe._dict(
# title = _("Website Search"),
# template = "templates/includes/kb_list.html",
# row_template = "templates/includes/kb_row.html",
# get_level_class = get_level_class,
# hide_filters = True,
# filters = {"published": 1}
# )
#
# if frappe.local.form_dict.txt:
# list_context.subtitle = _('Filtered by "{0}"').format(frappe.local.form_dict.txt)
# #
# # list_context.update(frappe.get_doc("Blog Settings", "Blog Settings").as_dict())
# return list_context
def check_broken_links():
cnt = 0
for p in frappe.db.sql("select name, main_section from `tabWeb Page`", as_dict=True):

View file

@ -440,12 +440,15 @@ $.extend(frappe, {
var val = $(this).val();
if(e.which===13 && val) {
$(this).val("").blur();
var path = (frappe.search_path && frappe.search_path[location.pathname] || location.pathname);
frappe.load_via_ajax(path + "?txt=" + encodeURIComponent(val));
frappe.do_search(val);
return false;
}
});
},
do_search: function(val) {
var path = (frappe.search_path && frappe.search_path[location.pathname] || location.pathname);
frappe.load_via_ajax(path + "?txt=" + encodeURIComponent(val));
},
set_search_path: function(path) {
frappe.search_path[location.pathname] = path;
},

View file

@ -122,7 +122,6 @@ def add_index(out, context):
html = ('<p><br><a href="{name}">'+_("Next")+': {title}</a></p>').format(**next_item)
out["content"] = out["content"].replace("{next}", html)
def add_hero(out, context):
"""Add a hero element if specified in content or hooks.
Hero elements get full page width."""

View file

@ -2,7 +2,7 @@
# MIT License. See license.txt
from __future__ import unicode_literals
import frappe, re
import frappe, re, os
def delete_page_cache(path):
if not path:
@ -162,3 +162,21 @@ def with_leading_slash(path):
path = "/" + path
return path
def get_full_index(doctype="Web Page"):
"""Returns full index of the website (on Web Page) upto the n-th level"""
all_routes = []
def get_children(parent):
children = frappe.db.get_all(doctype, ["parent_website_route", "page_name", "title"],
{"parent_website_route": parent}, order_by="idx asc")
for d in children:
d.url = with_leading_slash(os.path.join(d.parent_website_route or "", d.page_name))
if d.url not in all_routes:
d.children = get_children(d.url[1:])
all_routes.append(d.url)
return children
return get_children("")