web-form-fixes
This commit is contained in:
parent
6e15d97ee1
commit
8917d41f89
8 changed files with 68 additions and 53 deletions
|
|
@ -152,7 +152,7 @@
|
|||
</div>
|
||||
</form>
|
||||
{% if allow_comments -%}
|
||||
<div class="row">
|
||||
<div class="row comments">
|
||||
<div class="col-sm-offset-3 col-sm-9">
|
||||
<hr>
|
||||
<h3>{{ _("Comments") }}</h3>
|
||||
|
|
@ -243,6 +243,7 @@ frappe.ready(function() {
|
|||
callback: function(data) {
|
||||
if(!data.exc) {
|
||||
$form.addClass("hide");
|
||||
$(".comments").addClass("hide");
|
||||
scroll(0, 0);
|
||||
$(".form-message")
|
||||
.html("{{ success_message or 'Thank You!' }}")
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
<div class="sidebar-items">
|
||||
{%- for child in children -%}
|
||||
<div class="sidebar-item">
|
||||
<a href="{{ child.name }}" class="no-decoration {% if (pathname or "").startswith(child.name or "") %}active{% endif %}">
|
||||
<a href="{{ child.name }}" class="no-decoration {% if (pathname or "")==(child.name or "") %}active{% endif %}">
|
||||
{{ child.title or child.page_title or (child.name or "").replace("_", " ").title() }}
|
||||
</a>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,18 +1,17 @@
|
|||
{% block title %}{{ type }} {{ _("List") }}{% endblock %}
|
||||
{% block title %}{{ doctype }} {{ _("List") }}{% endblock %}
|
||||
|
||||
{% block header %}
|
||||
<h2>{{ type }} {{ _("List") }}</h2>
|
||||
<h2>{{ doctype }} {{ _("List") }}</h2>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<!-- no-sidebar -->
|
||||
<div class="row">
|
||||
<div class=" col-sm-offset-8 col-sm-4">
|
||||
<form class="form-inline form-search" action="/list">
|
||||
<div class="input-group">
|
||||
<input class="form-control" type="text" name="txt"
|
||||
<input class="form-control" doctype="text" name="txt"
|
||||
placeholder="Search..." value="{{ txt or '' }}">
|
||||
<input type="hidden" name="type" value="{{ type }}">
|
||||
<input type="hidden" name="doctype" value="{{ doctype }}">
|
||||
<span class="input-group-btn">
|
||||
<button class="btn btn-default" type="submit">
|
||||
<i class="icon-search"></i></button>
|
||||
|
|
@ -23,13 +22,14 @@
|
|||
</div>
|
||||
<br>
|
||||
{% if txt %}
|
||||
<div class="alert alert-warning">Results filtered by <b>{{ txt }}</b>. <a href="/list?type={{ type }}" class="close">×</a></div>
|
||||
<div class="alert alert-warning">Results filtered by <b>{{ txt }}</b>. <a href="/list?doctype={{ doctype }}" class="close">×</a></div>
|
||||
{% endif %}
|
||||
<div class="list-group" data-type="{{ type }}" data-txt="{{ txt or '[notxt]' }}">
|
||||
<div data-doctype="{{ doctype }}" data-txt="{{ txt or '[notxt]' }}">
|
||||
{% for item in items %}
|
||||
<div class="list-group-item">
|
||||
<div>
|
||||
{{ item }}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="more-block text-center hide">
|
||||
|
|
@ -41,7 +41,7 @@
|
|||
<script>
|
||||
frappe.ready(function() {
|
||||
// show more button if len is 20
|
||||
$list_group = $(".list-group[data-type='{{ type }}'][data-txt='{{ txt or "[notxt]" }}']");
|
||||
$list_group = $(".list-group[data-doctype='{{ doctype }}'][data-txt='{{ txt or "[notxt]" }}']");
|
||||
|
||||
// more ajax
|
||||
frappe.start = 20;
|
||||
|
|
@ -49,7 +49,7 @@ frappe.ready(function() {
|
|||
$.ajax({
|
||||
url:"/api/method/frappe.templates.pages.list.get_items",
|
||||
data: {
|
||||
type: "{{ type }}",
|
||||
doctype: "{{ doctype }}",
|
||||
txt: "{{ txt or '' }}",
|
||||
limit_start: frappe.start
|
||||
},
|
||||
|
|
|
|||
|
|
@ -3,47 +3,48 @@
|
|||
|
||||
from __future__ import unicode_literals
|
||||
import frappe, os
|
||||
from frappe.modules import get_doc_path
|
||||
from jinja2 import Environment, Template, FileSystemLoader
|
||||
from frappe.modules import get_doc_path, load_doctype_module
|
||||
|
||||
no_cache = 1
|
||||
no_sitemap = 1
|
||||
|
||||
def get_context(context):
|
||||
context.type = frappe.local.form_dict.type
|
||||
context.doctype = frappe.local.form_dict.doctype
|
||||
context.txt = frappe.local.form_dict.txt
|
||||
context.update(get_items(context.type, context.txt))
|
||||
module = load_doctype_module(context.doctype)
|
||||
context.update(get_items(context.doctype, context.txt))
|
||||
return context
|
||||
|
||||
@frappe.whitelist(allow_guest=True)
|
||||
def get_items(type, txt, limit_start=0):
|
||||
meta = frappe.get_meta(type)
|
||||
def get_items(doctype, txt, limit_start=0):
|
||||
meta = frappe.get_meta(doctype)
|
||||
filters, or_filters = [], []
|
||||
out = frappe._dict()
|
||||
module = load_doctype_module(doctype)
|
||||
|
||||
if txt:
|
||||
if meta.search_fields:
|
||||
for f in meta.get_search_fields():
|
||||
or_filters.append([type, f.strip(), "like", "%" + txt + "%"])
|
||||
or_filters.append([doctype, f.strip(), "like", "%" + txt + "%"])
|
||||
else:
|
||||
filters.append([type, "name", "like", "%" + txt + "%"])
|
||||
filters.append([doctype, "name", "like", "%" + txt + "%"])
|
||||
|
||||
|
||||
out.raw_items = frappe.get_list(type, fields = ["*"],
|
||||
out.raw_items = frappe.get_list(doctype, fields = ["*"],
|
||||
filters=filters, or_filters = or_filters, limit_start=limit_start,
|
||||
limit_page_length = 20)
|
||||
template_path = os.path.join(get_doc_path(meta.module, "DocType", meta.name), "list_item.html")
|
||||
|
||||
if os.path.exists(template_path):
|
||||
env = Environment(loader = FileSystemLoader("/"))
|
||||
#template_path = os.path.relpath(template_path)
|
||||
template = env.get_template(template_path)
|
||||
if hasattr(module, "get_list_item"):
|
||||
out["items"] = []
|
||||
for i in out.raw_items:
|
||||
i.doc = i
|
||||
out["items"].append(module.get_list_item(i))
|
||||
else:
|
||||
template = Template("""<div><a href="/{{ doctype }}/{{ doc.name }}" no-pjax>
|
||||
{{ doc[title_field] }}</a></div>""")
|
||||
|
||||
out.items = [template.render(doc=i, doctype=type,
|
||||
title_field = meta.title_field or "name") for i in out.raw_items]
|
||||
out.items = [template.render(doc=i, doctype=doctype,
|
||||
title_field = meta.title_field or "name") for i in out.raw_items]
|
||||
|
||||
out.meta = meta
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
||||
# MIT License. See license.txt
|
||||
from __future__ import unicode_literals
|
||||
from jinja2 import Template
|
||||
|
||||
def get_jenv():
|
||||
import frappe
|
||||
|
|
@ -24,10 +23,7 @@ def get_template(path):
|
|||
return get_jenv().get_template(path)
|
||||
|
||||
def render_template(template, context):
|
||||
if not "frappe" in context:
|
||||
context.update(get_allowed_functions_for_jenv())
|
||||
template = Template(template)
|
||||
return template.render(**context)
|
||||
return get_jenv().from_string(template).render(context)
|
||||
|
||||
def get_allowed_functions_for_jenv():
|
||||
import frappe
|
||||
|
|
|
|||
|
|
@ -32,8 +32,11 @@ class WebPage(WebsiteGenerator):
|
|||
context.comment_list = get_comment_list(self.doctype, self.name)
|
||||
|
||||
if self.template_path:
|
||||
# render dynamic context (if .py file exists)
|
||||
context = self.get_dynamic_context(frappe._dict(context))
|
||||
|
||||
# load content from template
|
||||
context.update(get_static_content(self, context))
|
||||
get_static_content(self, context)
|
||||
else:
|
||||
context.update({
|
||||
"style": self.css or "",
|
||||
|
|
@ -52,11 +55,27 @@ class WebPage(WebsiteGenerator):
|
|||
|
||||
def render_dynamic(self, context):
|
||||
# dynamic
|
||||
if context.main_section and "<!-- render-jinja -->" in context.main_section:
|
||||
if context.main_section and ("<!-- render-jinja -->" in context.main_section) \
|
||||
or ("{{" in context.main_section):
|
||||
context["main_section"] = render_template(context.main_section,
|
||||
{"doc": self, "frappe": frappe})
|
||||
context)
|
||||
context["no_cache"] = 1
|
||||
|
||||
def get_dynamic_context(self, context):
|
||||
template_path_base = self.template_path.rsplit(".", 1)[0]
|
||||
template_module = os.path.dirname(os.path.relpath(self.template_path,
|
||||
os.path.join(frappe.get_app_path("frappe"),"..", "..")))\
|
||||
.replace(os.path.sep, ".") + "." + frappe.scrub(template_path_base.rsplit(os.path.sep, 1)[1])
|
||||
|
||||
try:
|
||||
method = template_module.split(".", 1)[1] + ".get_context"
|
||||
get_context = frappe.get_attr(method)
|
||||
ret = get_context(context)
|
||||
if ret:
|
||||
context = ret
|
||||
except ImportError: pass
|
||||
return context
|
||||
|
||||
def set_metatags(self, context):
|
||||
context.metatags = {
|
||||
"name": context.title,
|
||||
|
|
@ -69,7 +88,6 @@ class WebPage(WebsiteGenerator):
|
|||
|
||||
|
||||
def get_static_content(doc, context):
|
||||
d = frappe._dict({})
|
||||
with open(doc.template_path, "r") as contentfile:
|
||||
content = unicode(contentfile.read(), 'utf-8')
|
||||
|
||||
|
|
@ -79,24 +97,24 @@ def get_static_content(doc, context):
|
|||
first_line = lines[0].strip()
|
||||
|
||||
if first_line.startswith("# "):
|
||||
d.title = first_line[2:]
|
||||
context.title = first_line[2:]
|
||||
content = "\n".join(lines[1:])
|
||||
|
||||
content = markdown(content)
|
||||
|
||||
d.main_section = unicode(content.encode("utf-8"), 'utf-8')
|
||||
if not d.title:
|
||||
d.title = doc.name.replace("-", " ").replace("_", " ").title()
|
||||
context.main_section = unicode(content.encode("utf-8"), 'utf-8')
|
||||
if not context.title:
|
||||
context.title = doc.name.replace("-", " ").replace("_", " ").title()
|
||||
|
||||
doc.render_dynamic(d)
|
||||
doc.render_dynamic(context)
|
||||
|
||||
for extn in ("js", "css"):
|
||||
fpath = doc.template_path.rsplit(".", 1)[0] + "." + extn
|
||||
if os.path.exists(fpath):
|
||||
with open(fpath, "r") as f:
|
||||
d["css" if extn=="css" else "javascript"] = f.read()
|
||||
context["css" if extn=="css" else "javascript"] = f.read()
|
||||
|
||||
return d
|
||||
return context
|
||||
|
||||
def check_broken_links():
|
||||
cnt = 0
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ def render(path, http_status_code=None):
|
|||
frappe.local.form_dict.name = name
|
||||
elif doctype:
|
||||
path = "list"
|
||||
frappe.local.form_dict.type = doctype
|
||||
frappe.local.form_dict.doctype = doctype
|
||||
else:
|
||||
path = "404"
|
||||
http_status_code = e.http_status_code
|
||||
|
|
|
|||
|
|
@ -74,14 +74,13 @@ class sync(object):
|
|||
break
|
||||
|
||||
# other files
|
||||
for extn in ("md", "html"):
|
||||
fname = page_name + "." + extn
|
||||
if fname in files:
|
||||
self.sync_file(fname, os.path.join(basepath, fname), i)
|
||||
break
|
||||
else:
|
||||
if page_name not in folders:
|
||||
print page_name + " not found in " + basepath
|
||||
if page_name + ".md" in files:
|
||||
self.sync_file(page_name + ".md", os.path.join(basepath, page_name + ".md"), i)
|
||||
elif page_name + ".html" in files:
|
||||
self.sync_file(page_name + ".html", os.path.join(basepath, page_name + ".html"), i)
|
||||
else:
|
||||
if page_name not in folders:
|
||||
print page_name + " not found in " + basepath
|
||||
|
||||
def sync_alphabetically(self, basepath, folders, files):
|
||||
files.sort()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue