Merge pull request #511 from rmehta/develop

bugfix in search, added role_home_page and sort_field, sort_order in doctype
This commit is contained in:
Anand Doshi 2014-05-08 17:44:11 +05:30
commit 407c5eb092
17 changed files with 469 additions and 128 deletions

View file

@ -1,6 +1,6 @@
{
"autoname": "DL.####",
"creation": "2013-01-29 17:55:08.000000",
"creation": "2013-01-29 17:55:08",
"docstatus": 0,
"doctype": "DocType",
"fields": [
@ -8,6 +8,7 @@
"fieldname": "doc_type",
"fieldtype": "Link",
"hidden": 0,
"in_list_view": 1,
"label": "Enter Form Type",
"no_copy": 0,
"options": "DocType",
@ -25,23 +26,37 @@
"fieldtype": "Column Break",
"permlevel": 0
},
{
"fieldname": "default_print_format",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Default Print Format",
"no_copy": 0,
"options": "Print Format",
"permlevel": 0,
"search_index": 0
},
{
"description": "Fields separated by comma (,) will be included in the<br /><b>Search By</b> list of Search dialog box",
"fieldname": "search_fields",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Search Fields",
"no_copy": 0,
"permlevel": 0,
"search_index": 0
},
{
"fieldname": "default_print_format",
"fieldtype": "Link",
"label": "Default Print Format",
"no_copy": 0,
"options": "Print Format",
"permlevel": 0,
"search_index": 0
"fieldname": "sort_field",
"fieldtype": "Data",
"label": "Sort Field",
"permlevel": 0
},
{
"fieldname": "sort_order",
"fieldtype": "Data",
"label": "Sort Order",
"permlevel": 0
},
{
"fieldname": "column_break1",
@ -111,7 +126,7 @@
"icon": "icon-glass",
"idx": 1,
"issingle": 1,
"modified": "2014-01-15 16:16:22.000000",
"modified": "2014-05-08 09:27:44.167026",
"modified_by": "Administrator",
"module": "Core",
"name": "Customize Form",

View file

@ -14,6 +14,8 @@ from frappe.core.doctype.doctype.doctype import validate_fields_for_doctype
class CustomizeForm(Document):
doctype_properties = {
'search_fields': 'Data',
'sort_field': 'Data',
'sort_order': 'Data',
'default_print_format': 'Data',
'read_only_onload': 'Check',
'allow_attach': 'Check',

View file

@ -138,6 +138,17 @@
"options": "\nTitle Case\nUPPER CASE",
"permlevel": 0
},
{
"fieldname": "description",
"fieldtype": "Small Text",
"hidden": 0,
"label": "Description",
"oldfieldname": "description",
"oldfieldtype": "Text",
"permlevel": 0,
"reqd": 0,
"search_index": 0
},
{
"fieldname": "column_break_15",
"fieldtype": "Column Break",
@ -162,15 +173,20 @@
"search_index": 0
},
{
"fieldname": "description",
"fieldtype": "Small Text",
"hidden": 0,
"label": "Description",
"oldfieldname": "description",
"oldfieldtype": "Text",
"permlevel": 0,
"reqd": 0,
"search_index": 0
"default": "modified",
"description": "",
"fieldname": "sort_field",
"fieldtype": "Data",
"label": "Sort Field",
"permlevel": 0
},
{
"default": "DESC",
"fieldname": "sort_order",
"fieldtype": "Select",
"label": "Sort Order",
"options": "ASC\nDESC",
"permlevel": 0
},
{
"depends_on": "eval:!doc.istable",
@ -329,7 +345,7 @@
"idx": 1,
"issingle": 0,
"istable": 0,
"modified": "2014-05-01 05:27:22.582492",
"modified": "2014-05-08 09:23:56.952829",
"modified_by": "Administrator",
"module": "Core",
"name": "DocType",
@ -361,5 +377,7 @@
}
],
"read_only": 0,
"search_fields": "module"
"search_fields": "module",
"sort_field": "name",
"sort_order": "ASC"
}

View file

@ -8,21 +8,21 @@
DROP TABLE IF EXISTS `tabDocField`;
CREATE TABLE `tabDocField` (
`name` varchar(120) NOT NULL,
`name` varchar(255) NOT NULL,
`creation` datetime(6) DEFAULT NULL,
`modified` datetime(6) DEFAULT NULL,
`modified_by` varchar(40) DEFAULT NULL,
`owner` varchar(40) DEFAULT NULL,
`modified_by` varchar(255) DEFAULT NULL,
`owner` varchar(255) DEFAULT NULL,
`docstatus` int(1) DEFAULT '0',
`parent` varchar(120) DEFAULT NULL,
`parentfield` varchar(120) DEFAULT NULL,
`parenttype` varchar(120) DEFAULT NULL,
`parent` varchar(255) DEFAULT NULL,
`parentfield` varchar(255) DEFAULT NULL,
`parenttype` varchar(255) DEFAULT NULL,
`idx` int(8) DEFAULT NULL,
`fieldname` varchar(180) DEFAULT NULL,
`label` varchar(180) DEFAULT NULL,
`oldfieldname` varchar(180) DEFAULT NULL,
`fieldtype` varchar(180) DEFAULT NULL,
`oldfieldtype` varchar(180) DEFAULT NULL,
`fieldname` varchar(255) DEFAULT NULL,
`label` varchar(255) DEFAULT NULL,
`oldfieldname` varchar(255) DEFAULT NULL,
`fieldtype` varchar(255) DEFAULT NULL,
`oldfieldtype` varchar(255) DEFAULT NULL,
`options` text,
`search_index` int(1) DEFAULT NULL,
`hidden` int(1) DEFAULT NULL,
@ -32,12 +32,12 @@ CREATE TABLE `tabDocField` (
`reqd` int(1) DEFAULT NULL,
`no_copy` int(1) DEFAULT NULL,
`allow_on_submit` int(1) DEFAULT NULL,
`trigger` varchar(180) DEFAULT NULL,
`depends_on` varchar(180) DEFAULT NULL,
`trigger` varchar(255) DEFAULT NULL,
`depends_on` varchar(255) DEFAULT NULL,
`permlevel` int(11) DEFAULT '0',
`ignore_restrictions` int(1) DEFAULT NULL,
`width` varchar(180) DEFAULT NULL,
`print_width` varchar(180) DEFAULT NULL,
`width` varchar(255) DEFAULT NULL,
`print_width` varchar(255) DEFAULT NULL,
`default` text,
`description` text,
`in_filter` int(1) DEFAULT NULL,
@ -57,22 +57,22 @@ CREATE TABLE `tabDocField` (
--
DROP TABLE IF EXISTS `tabDocPerm`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
/*!255101 SET @saved_cs_client = @@character_set_client */;
/*!255101 SET character_set_client = utf8 */;
CREATE TABLE `tabDocPerm` (
`name` varchar(120) NOT NULL,
`name` varchar(255) NOT NULL,
`creation` datetime(6) DEFAULT NULL,
`modified` datetime(6) DEFAULT NULL,
`modified_by` varchar(40) DEFAULT NULL,
`owner` varchar(40) DEFAULT NULL,
`modified_by` varchar(255) DEFAULT NULL,
`owner` varchar(255) DEFAULT NULL,
`docstatus` int(1) DEFAULT '0',
`parent` varchar(120) DEFAULT NULL,
`parentfield` varchar(120) DEFAULT NULL,
`parenttype` varchar(120) DEFAULT NULL,
`parent` varchar(255) DEFAULT NULL,
`parentfield` varchar(255) DEFAULT NULL,
`parenttype` varchar(255) DEFAULT NULL,
`idx` int(8) DEFAULT NULL,
`permlevel` int(11) DEFAULT '0',
`role` varchar(180) DEFAULT NULL,
`match` varchar(180) DEFAULT NULL,
`role` varchar(255) DEFAULT NULL,
`match` varchar(255) DEFAULT NULL,
`read` int(1) DEFAULT NULL,
`write` int(1) DEFAULT NULL,
`create` int(1) DEFAULT NULL,
@ -89,43 +89,45 @@ CREATE TABLE `tabDocPerm` (
PRIMARY KEY (`name`),
KEY `parent` (`parent`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!255101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `tabDocType`
--
DROP TABLE IF EXISTS `tabDocType`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
/*!255101 SET @saved_cs_client = @@character_set_client */;
/*!255101 SET character_set_client = utf8 */;
CREATE TABLE `tabDocType` (
`name` varchar(180) NOT NULL DEFAULT '',
`name` varchar(255) NOT NULL DEFAULT '',
`creation` datetime(6) DEFAULT NULL,
`modified` datetime(6) DEFAULT NULL,
`modified_by` varchar(40) DEFAULT NULL,
`owner` varchar(180) DEFAULT NULL,
`modified_by` varchar(255) DEFAULT NULL,
`owner` varchar(255) DEFAULT NULL,
`docstatus` int(1) DEFAULT '0',
`parent` varchar(120) DEFAULT NULL,
`parentfield` varchar(120) DEFAULT NULL,
`parenttype` varchar(120) DEFAULT NULL,
`parent` varchar(255) DEFAULT NULL,
`parentfield` varchar(255) DEFAULT NULL,
`parenttype` varchar(255) DEFAULT NULL,
`idx` int(8) DEFAULT NULL,
`search_fields` varchar(180) DEFAULT NULL,
`search_fields` varchar(255) DEFAULT NULL,
`issingle` int(1) DEFAULT NULL,
`istable` int(1) DEFAULT NULL,
`version` int(11) DEFAULT NULL,
`module` varchar(180) DEFAULT NULL,
`plugin` varchar(180) DEFAULT NULL,
`autoname` varchar(180) DEFAULT NULL,
`name_case` varchar(180) DEFAULT NULL,
`title_field` varchar(180) DEFAULT NULL,
`module` varchar(255) DEFAULT NULL,
`plugin` varchar(255) DEFAULT NULL,
`autoname` varchar(255) DEFAULT NULL,
`name_case` varchar(255) DEFAULT NULL,
`title_field` varchar(255) DEFAULT NULL,
`sort_field` varchar(255) DEFAULT NULL,
`sort_order` varchar(255) DEFAULT NULL,
`description` text,
`colour` varchar(180) DEFAULT NULL,
`colour` varchar(255) DEFAULT NULL,
`read_only` int(1) DEFAULT NULL,
`in_create` int(1) DEFAULT NULL,
`show_in_menu` int(1) DEFAULT NULL,
`menu_index` int(11) DEFAULT NULL,
`parent_node` varchar(180) DEFAULT NULL,
`smallicon` varchar(180) DEFAULT NULL,
`parent_node` varchar(255) DEFAULT NULL,
`smallicon` varchar(255) DEFAULT NULL,
`allow_print` int(1) DEFAULT NULL,
`allow_email` int(1) DEFAULT NULL,
`allow_copy` int(1) DEFAULT NULL,
@ -136,47 +138,37 @@ CREATE TABLE `tabDocType` (
`allow_attach` int(1) DEFAULT NULL,
`use_template` int(1) DEFAULT NULL,
`max_attachments` int(11) DEFAULT NULL,
`section_style` varchar(180) DEFAULT NULL,
`client_script` mediumtext,
`client_script_core` mediumtext,
`server_code` mediumtext,
`server_code_core` mediumtext,
`server_code_compiled` mediumtext,
`client_string` mediumtext,
`server_code_error` varchar(180) DEFAULT NULL,
`print_outline` varchar(180) DEFAULT NULL,
`dt_template` mediumtext,
`print_outline` varchar(255) DEFAULT NULL,
`is_transaction_doc` int(1) DEFAULT NULL,
`change_log` mediumtext,
`read_only_onload` int(1) DEFAULT NULL,
`allow_trash` int(1) DEFAULT NULL,
`in_dialog` int(1) DEFAULT NULL,
`document_type` varchar(180) DEFAULT NULL,
`icon` varchar(180) DEFAULT NULL,
`tag_fields` varchar(180) DEFAULT NULL,
`subject` varchar(180) DEFAULT NULL,
`document_type` varchar(255) DEFAULT NULL,
`icon` varchar(255) DEFAULT NULL,
`tag_fields` varchar(255) DEFAULT NULL,
`subject` varchar(255) DEFAULT NULL,
`_last_update` varchar(32) DEFAULT NULL,
`default_print_format` varchar(180) DEFAULT NULL,
`default_print_format` varchar(255) DEFAULT NULL,
`is_submittable` int(1) DEFAULT NULL,
`_user_tags` varchar(180) DEFAULT NULL,
`_user_tags` varchar(255) DEFAULT NULL,
`custom` int(1) DEFAULT NULL,
PRIMARY KEY (`name`),
KEY `parent` (`parent`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!255101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `tabSeries`
--
DROP TABLE IF EXISTS `tabSeries`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
/*!255101 SET @saved_cs_client = @@character_set_client */;
/*!255101 SET character_set_client = utf8 */;
CREATE TABLE `tabSeries` (
`name` varchar(100) DEFAULT NULL,
`current` int(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!255101 SET character_set_client = @saved_cs_client */;
--
@ -184,18 +176,18 @@ CREATE TABLE `tabSeries` (
--
DROP TABLE IF EXISTS `tabSessions`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
/*!255101 SET @saved_cs_client = @@character_set_client */;
/*!255101 SET character_set_client = utf8 */;
CREATE TABLE `tabSessions` (
`user` varchar(255) DEFAULT NULL,
`sid` varchar(120) DEFAULT NULL,
`sid` varchar(255) DEFAULT NULL,
`sessiondata` longtext,
`ipaddress` varchar(16) DEFAULT NULL,
`lastupdate` datetime(6) DEFAULT NULL,
`status` varchar(20) DEFAULT NULL,
KEY `sid` (`sid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!255101 SET character_set_client = @saved_cs_client */;
--
@ -203,11 +195,11 @@ CREATE TABLE `tabSessions` (
--
DROP TABLE IF EXISTS `tabSingles`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
/*!255101 SET @saved_cs_client = @@character_set_client */;
/*!255101 SET character_set_client = utf8 */;
CREATE TABLE `tabSingles` (
`doctype` varchar(40) DEFAULT NULL,
`field` varchar(40) DEFAULT NULL,
`doctype` varchar(255) DEFAULT NULL,
`field` varchar(255) DEFAULT NULL,
`value` text,
KEY `singles_doctype_field_index` (`doctype`, `field`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@ -217,11 +209,11 @@ CREATE TABLE `tabSingles` (
--
DROP TABLE IF EXISTS `__Auth`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
/*!255101 SET @saved_cs_client = @@character_set_client */;
/*!255101 SET character_set_client = utf8 */;
CREATE TABLE `__Auth` (
`user` VARCHAR(180) NOT NULL PRIMARY KEY,
`password` VARCHAR(180) NOT NULL,
`user` VARCHAR(255) NOT NULL PRIMARY KEY,
`password` VARCHAR(255) NOT NULL,
KEY `user` (`user`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@ -231,22 +223,22 @@ CREATE TABLE `__Auth` (
DROP TABLE IF EXISTS `tabFile Data`;
CREATE TABLE `tabFile Data` (
`name` varchar(120) NOT NULL,
`name` varchar(255) NOT NULL,
`creation` datetime(6) DEFAULT NULL,
`modified` datetime(6) DEFAULT NULL,
`modified_by` varchar(40) DEFAULT NULL,
`owner` varchar(40) DEFAULT NULL,
`modified_by` varchar(255) DEFAULT NULL,
`owner` varchar(255) DEFAULT NULL,
`docstatus` int(1) DEFAULT '0',
`parent` varchar(120) DEFAULT NULL,
`parentfield` varchar(120) DEFAULT NULL,
`parenttype` varchar(120) DEFAULT NULL,
`parent` varchar(255) DEFAULT NULL,
`parentfield` varchar(255) DEFAULT NULL,
`parenttype` varchar(255) DEFAULT NULL,
`idx` int(8) DEFAULT NULL,
`file_name` varchar(180) DEFAULT NULL,
`file_url` varchar(180) DEFAULT NULL,
`module` varchar(180) DEFAULT NULL,
`attached_to_name` varchar(180) DEFAULT NULL,
`file_name` varchar(255) DEFAULT NULL,
`file_url` varchar(255) DEFAULT NULL,
`module` varchar(255) DEFAULT NULL,
`attached_to_name` varchar(255) DEFAULT NULL,
`file_size` int(11) DEFAULT NULL,
`attached_to_doctype` varchar(180) DEFAULT NULL,
`attached_to_doctype` varchar(255) DEFAULT NULL,
PRIMARY KEY (`name`),
KEY `parent` (`parent`),
KEY `attached_to_name` (`attached_to_name`),
@ -259,18 +251,18 @@ CREATE TABLE `tabFile Data` (
DROP TABLE IF EXISTS `tabDefaultValue`;
CREATE TABLE `tabDefaultValue` (
`name` varchar(120) NOT NULL,
`name` varchar(255) NOT NULL,
`creation` datetime(6) DEFAULT NULL,
`modified` datetime(6) DEFAULT NULL,
`modified_by` varchar(40) DEFAULT NULL,
`owner` varchar(40) DEFAULT NULL,
`modified_by` varchar(255) DEFAULT NULL,
`owner` varchar(255) DEFAULT NULL,
`docstatus` int(1) DEFAULT '0',
`parent` varchar(120) DEFAULT NULL,
`parentfield` varchar(120) DEFAULT NULL,
`parenttype` varchar(120) DEFAULT NULL,
`parent` varchar(255) DEFAULT NULL,
`parentfield` varchar(255) DEFAULT NULL,
`parenttype` varchar(255) DEFAULT NULL,
`idx` int(8) DEFAULT NULL,
`defvalue` text,
`defkey` varchar(180) DEFAULT NULL,
`defkey` varchar(255) DEFAULT NULL,
PRIMARY KEY (`name`),
KEY `parent` (`parent`),
KEY `defaultvalue_parent_defkey_index` (`parent`,`defkey`)

View file

@ -74,7 +74,8 @@ class DatabaseQuery(object):
args.conditions = ' and '.join(self.conditions)
args.fields = ', '.join(self.fields)
args.order_by = self.order_by or self.tables[0] + '.modified desc'
self.set_order_by(args)
args.group_by = self.group_by and (" group by " + self.group_by) or ""
self.check_sort_by_table(args.order_by)
@ -279,6 +280,14 @@ class DatabaseQuery(object):
query = query.replace('%(key)s', 'name')
return frappe.db.sql(query, as_dict = (not self.as_list))
def set_order_by(self, args):
meta = frappe.get_meta(self.doctype)
if self.order_by:
args.order_by = self.order_by
else:
args.order_by = "`tab{0}`.`{1}` {2}".format(self.doctype,
meta.sort_field or "modified", meta.sort_order or "desc")
def check_sort_by_table(self, order_by):
if "." in order_by:
tbl = order_by.split('.')[0]

View file

@ -99,6 +99,21 @@ class Meta(Document):
def get_options(self, fieldname):
return self.get_field(fieldname).options
def get_search_fields(self):
search_fields = self.search_fields or "name"
search_fields = [d.strip() for d in search_fields.split(",")]
if "name" not in search_fields:
search_fields.append("name")
return search_fields
def get_list_fields(self):
list_fields = ["name"] + [d.fieldname \
for d in self.fields if (d.in_list_view and d.fieldtype in type_map)]
if self.title_field and self.title_field not in list_fields:
list_fields.append(self.title_field)
return list_fields
def process(self):
# don't process for special doctypes
# prevent's circular dependency
@ -203,7 +218,7 @@ doctype_table_fields = [
def is_single(doctype):
try:
return frappe.db.get_value("DocType", doctype, "issingle")
except IndexError, e:
except IndexError:
raise Exception, 'Cannot determine whether %s is single' % doctype
def get_parent_dt(dt):

View file

@ -32,7 +32,7 @@ def clear_cache(user=None):
"time_zone"])
def delete_user_cache(user):
for key in ("bootinfo", "lang", "roles", "restrictions"):
for key in ("bootinfo", "lang", "roles", "restrictions", "home_page"):
cache.delete_value(key + ":" + user)
def clear_notifications(user=None):

View file

@ -0,0 +1,84 @@
{% block title %}{{ type }} {{ _("List") }}{% endblock %}
{% block header %}
<h2>{{ type }} {{ _("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"
placeholder="Search..." value="{{ txt or '' }}">
<input type="hidden" name="type" value="{{ type }}">
<span class="input-group-btn">
<button class="btn btn-default" type="submit">
<i class="icon-search"></i></button>
</span>
</div>
</form>
</div>
</div>
<br>
{% if txt %}
<div class="alert alert-warning">Results filtered by <b>{{ txt }}</b>. <a href="/list?type={{ type }}" class="close">&times;</a></div>
{% endif %}
<div class="list-group" data-type="{{ type }}" data-txt="{{ txt or '[notxt]' }}">
{% for item in items %}
<div class="list-group-item">
{{ item }}
</div>
{% endfor %}
</div>
<div class="more-block text-center hide">
<button class="btn btn-default btn-more">More</button>
</div>
{% endblock %}
{% block script %}
<script>
frappe.ready(function() {
// show more button if len is 20
$list_group = $(".list-group[data-type='{{ type }}'][data-txt='{{ txt or "[notxt]" }}']");
// more ajax
frappe.start = 20;
$(".btn-more").on("click", function() {
$.ajax({
url:"/api/method/frappe.templates.pages.list.get_items",
data: {
type: "{{ type }}",
txt: "{{ txt or '' }}",
limit_start: frappe.start
},
statusCode: {
200: function(data) {
frappe.start += 20;
$.each(data.message.items, function(i, d) {
$('<div class="list-group-item">')
.html(d)
.appendTo($list_group);
});
show_more();
}
}
})
})
var show_more = function() {
var $items = $list_group.find(".list-group-item")
if($items.length && ($items.length % 20 === 0)) {
if($(".more-block").hasClass("hide"))
$(".more-block").removeClass("hide");
} else {
if(!$(".more-block").hasClass("hide"))
$(".more-block").addClass("hide");
}
};
show_more();
})
</script>
{% endblock %}

View file

@ -0,0 +1,50 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt
from __future__ import unicode_literals
import frappe, os
from frappe.modules import get_doc_path
from jinja2 import Environment, Template, FileSystemLoader
no_cache = 1
no_sitemap = 1
def get_context(context):
context.type = frappe.local.form_dict.type
context.txt = frappe.local.form_dict.txt
context.update(get_items(context.type, context.txt))
return context
@frappe.whitelist(allow_guest=True)
def get_items(type, txt, limit_start=0):
meta = frappe.get_meta(type)
filters, or_filters = [], []
out = frappe._dict()
if txt:
if meta.search_fields:
for f in meta.get_search_fields():
or_filters.append([type, f.strip(), "like", "%" + txt + "%"])
else:
filters.append([type, "name", "like", "%" + txt + "%"])
out.raw_items = frappe.get_list(type, 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)
else:
template = Template("""<div><a href="/{{ doctype }}/{{ doc.name }}">
{{ 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.meta = meta
return out

View file

@ -7,4 +7,4 @@
<div class="message-content">
<p>{{ message }}</p>
</div>
{% endblock %}
{% endblock %}

View file

@ -0,0 +1,78 @@
{% block title %}{{ doc.doctype }} / {{ doc[meta.title_field or "name"] }}{% endblock %}
{% block header %}
<h2>{{ doc[meta.title_field or "name"] }}</h2>
<p><a href="/{{ doc.doctype }}">{{ doc.doctype }} {{ _("List") }}</a></p>
{% endblock %}
{% block content %}
{% if custom_view %}
{{ custom_view }}
{% else %}
{% macro print_value(df, d, meta) -%}
{% if df.fieldtype=="Check" %}
<i class="{{ 'icon-check' if d[df.fieldname] else 'icon-check-empty' }}"></i>
{% elif df.fieldtype=="Image" %}
<img src="{{ doc[meta.get_field(df.fieldname).options] }}" class="img-responsive">
{% else %}
{{ d[df.fieldname] or "" }}
{% endif %}
{%- endmacro %}
{% macro get_width(fieldtype) -%}
{%- if fieldtype in ("Int", "Check") -%}{{ 60 }}
{%- else -%}{{ 150 }}{% endif -%}
{%- endmacro %}
{% for df in meta.fields %}
{% if not df.hidden and not df.permlevel and not df.print_hide %}
{% if df.fieldtype=="Section Break" %}
<h4>{{ df.label or "" }}</h4>
{% elif df.fieldtype=="Column Break" %}
{% elif df.fieldtype=="Table" %}
{% set table_meta = frappe.get_meta(df.options) %}
<div style="overflow-x: auto;">
<table class="table table-bordered" style="table-layout: fixed">
<thead>
<tr>
<th style="width: 40px">Sr</th>
{% for tdf in table_meta.fields %}
{% if tdf.fieldtype not in ("Column Break", "Section Break")
and tdf.label %}
<th style="width: {{ get_width(tdf.fieldtype) }}px">
{{ tdf.label }}</th>
{% endif %}
{% endfor %}
</tr>
</thead>
<tbody>
{% for d in doc[df.fieldname] %}
<tr>
<td>{{ d.idx }}</td>
{% for tdf in table_meta.fields %}
{% if tdf.fieldtype not in ("Column Break", "Section Break") %}
<td>{{ print_value(tdf, d, table_meta) }}</td>
{% endif %}
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="row">
<div class="col-sm-4 text-right">
{% if df.fieldtype not in ("Image","HTML") %}
<label>{{ df.label }}</label>
{% endif %}
</div>
<div class="col-sm-8">
{{ print_value(df, doc, meta) }}
</div>
</div>
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{% endblock %}

View file

@ -0,0 +1,16 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt
from __future__ import unicode_literals
import frappe
no_cache = 1
no_sitemap = 1
def get_context(context):
doc = frappe.get_doc(frappe.local.form_dict.doctype, frappe.local.form_dict.name)
doc.run_method("make_view")
return {
"doc": doc,
"meta": doc.meta
}

View file

@ -115,6 +115,17 @@ app_version = "0.0.1"
# web_include_css = "/assets/{app_name}/css/{app_name}.css"
# web_include_js = "/assets/{app_name}/js/{app_name}.js"
# Home Pages
# ----------
# application home page (will override Website Settings)
# home_page = "login"
# website user home page (by Role)
# role_home_page = {
# "Role": "home_page"
# }
# Installation
# ------------

View file

@ -221,6 +221,9 @@ $.extend(frappe, {
if ( event.which > 1 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey )
return;
if (link.getAttribute("target"))
return;
// Ignore cross origin links
if ( location.protocol !== link.protocol || location.hostname !== link.hostname )
return;

View file

@ -8,7 +8,7 @@ from werkzeug.wrappers import Response
from frappe.website.context import get_context
from frappe.website.utils import scrub_relative_urls, get_home_page, can_cache
from frappe.website.permissions import get_access, clear_permissions
from frappe.website.permissions import clear_permissions
class PageNotFoundError(Exception): pass
@ -18,9 +18,25 @@ def render(path, http_status_code=None):
try:
data = render_page(path)
except frappe.DoesNotExistError, e:
path = "404"
doctype, name = get_doctype_from_path(path)
if doctype and name:
path = "view"
frappe.local.form_dict.doctype = doctype
frappe.local.form_dict.name = name
elif doctype:
path = "list"
frappe.local.form_dict.type = doctype
else:
path = "404"
http_status_code = e.http_status_code
data = render_page(path)
except frappe.PermissionError, e:
path = "message"
frappe.local.message = "Did you log out?"
frappe.local.message_title = "Not Permitted"
data = render_page(path)
http_status_code = e.http_status_code
@ -31,6 +47,24 @@ def render(path, http_status_code=None):
return build_response(path, data, http_status_code or 200)
def get_doctype_from_path(path):
doctypes = [d[0] for d in frappe.get_list("DocType", as_list=True)]
parts = path.split("/")
doctype = parts[0]
name = parts[1] if len(parts) > 1 else None
if doctype in doctypes:
return doctype, name
# try scrubbed
doctype = doctype.replace("_", " ").title()
if doctype in doctypes:
return doctype, name
return None, None
def build_response(path, data, http_status_code):
# build response
response = Response()

View file

@ -21,12 +21,26 @@ def can_cache(no_cache=False):
return not (frappe.conf.disable_website_cache or no_cache)
def get_home_page():
home_page = frappe.cache().get_value("home_page", \
lambda: (frappe.get_hooks("home_page") \
or [frappe.db.get_value("Website Settings", None, "home_page") \
or "login"])[0])
def _get_home_page():
role_home_page = frappe.get_hooks("role_home_page")
home_page = None
return home_page
for role in frappe.get_roles():
if role in role_home_page:
home_page = role_home_page[role][0]
break
if not home_page:
home_page = frappe.get_hooks("home_page")
if home_page:
home_page = home_page[0]
if not home_page:
home_page = frappe.db.get_value("Website Settings", None, "home_page") or "login"
return home_page
return frappe.cache().get_value("home_page:" + frappe.session.user, _get_home_page)
def is_signup_enabled():
if getattr(frappe.local, "is_signup_enabled", None) is None:

View file

@ -61,7 +61,7 @@ def search_widget(doctype, txt, query=None, searchfield=None, start=0,
# build from doctype
if txt:
if meta.search_fields:
for f in meta.search_fields.split(","):
for f in meta.get_search_fields():
or_filters.append([doctype, f.strip(), "like", "%" + txt + "%"])
else:
filters.append([doctype, searchfield or "name", "like",
@ -74,7 +74,7 @@ def search_widget(doctype, txt, query=None, searchfield=None, start=0,
frappe.response["values"] = frappe.widgets.reportview.execute(doctype,
filters=filters, fields = get_std_fields_list(meta, searchfield or "name"),
or_filters = or_filters, limit_start = start,
limit_page_length=page_len, as_list=True, debug=1)
limit_page_length=page_len, as_list=True)
def get_std_fields_list(meta, key):
# get additional search fields