diff --git a/frappe/core/doctype/customize_form/customize_form.json b/frappe/core/doctype/customize_form/customize_form.json index 5db77d1bbf..a95988f208 100644 --- a/frappe/core/doctype/customize_form/customize_form.json +++ b/frappe/core/doctype/customize_form/customize_form.json @@ -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
Search By 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", diff --git a/frappe/core/doctype/customize_form/customize_form.py b/frappe/core/doctype/customize_form/customize_form.py index 0af80da2fd..0e0eefdcfa 100644 --- a/frappe/core/doctype/customize_form/customize_form.py +++ b/frappe/core/doctype/customize_form/customize_form.py @@ -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', diff --git a/frappe/core/doctype/doctype/doctype.json b/frappe/core/doctype/doctype/doctype.json index 9b89f80b18..646600a471 100644 --- a/frappe/core/doctype/doctype/doctype.json +++ b/frappe/core/doctype/doctype/doctype.json @@ -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" } \ No newline at end of file diff --git a/frappe/data/Framework.sql b/frappe/data/Framework.sql index f6055f257c..819b22b4a9 100644 --- a/frappe/data/Framework.sql +++ b/frappe/data/Framework.sql @@ -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`) diff --git a/frappe/model/db_query.py b/frappe/model/db_query.py index db18b021f5..da49f92fde 100644 --- a/frappe/model/db_query.py +++ b/frappe/model/db_query.py @@ -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] diff --git a/frappe/model/meta.py b/frappe/model/meta.py index f4f2c099a8..b40097ea43 100644 --- a/frappe/model/meta.py +++ b/frappe/model/meta.py @@ -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): diff --git a/frappe/sessions.py b/frappe/sessions.py index 48e02f3eec..5a714fe9da 100644 --- a/frappe/sessions.py +++ b/frappe/sessions.py @@ -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): diff --git a/frappe/templates/pages/list.html b/frappe/templates/pages/list.html new file mode 100644 index 0000000000..11a5b15512 --- /dev/null +++ b/frappe/templates/pages/list.html @@ -0,0 +1,84 @@ +{% block title %}{{ type }} {{ _("List") }}{% endblock %} + +{% block header %} +

{{ type }} {{ _("List") }}

+{% endblock %} + +{% block content %} + +
+
+ +
+
+
+{% if txt %} +
Results filtered by {{ txt }}. ×
+{% endif %} +
+{% for item in items %} +
+ {{ item }} +
+{% endfor %} +
+
+ +
+{% endblock %} + +{% block script %} + +{% endblock %} diff --git a/frappe/templates/pages/list.py b/frappe/templates/pages/list.py new file mode 100644 index 0000000000..0e05b2f288 --- /dev/null +++ b/frappe/templates/pages/list.py @@ -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("""
+ {{ doc[title_field] }}
""") + + 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 diff --git a/frappe/templates/pages/message.html b/frappe/templates/pages/message.html index df8f6ac7af..2c70bf8457 100644 --- a/frappe/templates/pages/message.html +++ b/frappe/templates/pages/message.html @@ -7,4 +7,4 @@

{{ message }}

-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/frappe/templates/pages/view.html b/frappe/templates/pages/view.html new file mode 100644 index 0000000000..3c0acf0a37 --- /dev/null +++ b/frappe/templates/pages/view.html @@ -0,0 +1,78 @@ +{% block title %}{{ doc.doctype }} / {{ doc[meta.title_field or "name"] }}{% endblock %} + +{% block header %} +

{{ doc[meta.title_field or "name"] }}

+

{{ doc.doctype }} {{ _("List") }}

+{% endblock %} + +{% block content %} +{% if custom_view %} +{{ custom_view }} +{% else %} + +{% macro print_value(df, d, meta) -%} + {% if df.fieldtype=="Check" %} + + {% elif df.fieldtype=="Image" %} + + {% 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" %} +

{{ df.label or "" }}

+ {% elif df.fieldtype=="Column Break" %} + {% elif df.fieldtype=="Table" %} + {% set table_meta = frappe.get_meta(df.options) %} +
+ + + + + {% for tdf in table_meta.fields %} + {% if tdf.fieldtype not in ("Column Break", "Section Break") + and tdf.label %} + + {% endif %} + {% endfor %} + + + + {% for d in doc[df.fieldname] %} + + + {% for tdf in table_meta.fields %} + {% if tdf.fieldtype not in ("Column Break", "Section Break") %} + + {% endif %} + {% endfor %} + + {% endfor %} + +
Sr + {{ tdf.label }}
{{ d.idx }}{{ print_value(tdf, d, table_meta) }}
+
+ {% else %} +
+
+ {% if df.fieldtype not in ("Image","HTML") %} + + {% endif %} +
+
+ {{ print_value(df, doc, meta) }} +
+
+ {% endif %} + {% endif %} +{% endfor %} +{% endif %} +{% endblock %} diff --git a/frappe/templates/pages/view.py b/frappe/templates/pages/view.py new file mode 100644 index 0000000000..7e72a8895c --- /dev/null +++ b/frappe/templates/pages/view.py @@ -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 + } diff --git a/frappe/utils/boilerplate.py b/frappe/utils/boilerplate.py index 035525ec55..4ef4c72e7a 100644 --- a/frappe/utils/boilerplate.py +++ b/frappe/utils/boilerplate.py @@ -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 # ------------ diff --git a/frappe/website/js/website.js b/frappe/website/js/website.js index fba7a35934..ee399ca7e0 100644 --- a/frappe/website/js/website.js +++ b/frappe/website/js/website.js @@ -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; diff --git a/frappe/website/render.py b/frappe/website/render.py index c512eb1768..ef16616bfe 100644 --- a/frappe/website/render.py +++ b/frappe/website/render.py @@ -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() diff --git a/frappe/website/utils.py b/frappe/website/utils.py index 7a60df6338..fd605316ec 100644 --- a/frappe/website/utils.py +++ b/frappe/website/utils.py @@ -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: diff --git a/frappe/widgets/search.py b/frappe/widgets/search.py index 3a4200d7dd..4e45eab0f8 100644 --- a/frappe/widgets/search.py +++ b/frappe/widgets/search.py @@ -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