added boilerplates for list

This commit is contained in:
Rushabh Mehta 2014-08-04 17:33:20 +05:30 committed by Anand Doshi
parent 5e487b7021
commit fa4d327e10
5 changed files with 78 additions and 26 deletions

View file

@ -207,7 +207,9 @@ def setup_utilities(parser):
parser.add_argument("--make_conf", nargs="*", metavar=("DB-NAME", "DB-PASSWORD"),
help="Create new conf.py file")
parser.add_argument("--make_custom_server_script", nargs=1, metavar="DOCTYPE",
help="Create new conf.py file")
help="Create new custome server script")
parser.add_argument("--init_list", nargs=1, metavar="DOCTYPE",
help="Create new list.js and list.html files")
parser.add_argument("--set_admin_password", metavar='ADMIN-PASSWORD', nargs="*",
help="Set administrator password")
parser.add_argument("--request", metavar='URL-ARGS', nargs=1, help="Run request as admin")
@ -534,6 +536,11 @@ def make_custom_server_script(doctype):
make_custom_server_script_file(doctype)
frappe.destroy()
@cmd
def init_list(doctype):
import frappe.core.doctype.doctype.doctype
frappe.core.doctype.doctype.doctype.init_list(doctype)
# clear
@cmd
def clear_cache():

View file

@ -0,0 +1,33 @@
<div class="row" style="max-height: 30px;">
<div class="col-xs-12">
<div class="text-ellipsis">
{{%= list.get_avatar_and_id(doc) %}}
<!-- sample text -->
<span style="margin-right: 8px;" class="filterable"
data-filter="text,=,{{%= doc.text %}}">
{{%= doc.text %}}</span>
<!-- sample icon -->
{{% if(doc.check) {{ %}}
<span style="margin-right: 8px;"
title="{{%= __("Title") %}}" class="filterable"
data-filter="check,=,Yes">
<i class="icon-icon text-muted"></i>
</span>
{{% }} %}}
<!-- sample label -->
<span class="label
label-{{%= frappe.utils.guess_style(doc.status) %}} filterable"
data-filter="status,=,{{%= doc.status %}}">
{{%= doc.status %}}
</span>
</div>
</div>
<!-- sample graph -->
<div class="col-xs-1 text-right">
{{% var completed = doc.completed, title = __("Completed") %}}
{{% include "templates/form_grid/includes/progress.html" %}}
</div>
</div>

View file

@ -0,0 +1,4 @@
frappe.listview_settings['{doctype}'] = {{
add_fields: ["status"],
filters:[["status","=", "Open"]]
}};

View file

@ -13,6 +13,7 @@ from frappe.model.document import Document
from frappe.model.db_schema import type_map
from frappe.core.doctype.property_setter.property_setter import make_property_setter
from frappe.core.doctype.notification_count.notification_count import delete_notification_count_for
from frappe.modules import get_doc_path, get_module_path, scrub
form_grid_templates = {
"fields": "templates/form_grid/fields.html"
@ -146,31 +147,11 @@ class DocType(Document):
import_from_files(record_list=[[self.module, 'doctype', self.name]])
def make_controller_template(self):
from frappe.modules import get_doc_path, get_module_path, scrub
target_path = get_doc_path(self.module, self.doctype, self.name)
app = frappe.local.module_app[scrub(self.module)]
if not app:
frappe.throw(_("App not found"))
app_publisher = frappe.get_hooks(hook="app_publisher", app_name=app)[0]
def _make_boilerplate(template):
template_name = template.replace("controller", scrub(self.name))
target_file_path = os.path.join(target_path, template_name)
if not os.path.exists(target_file_path):
with open(target_file_path, 'w') as target:
with open(os.path.join(get_module_path("core"), "doctype", "doctype",
"boilerplate", template), 'r') as source:
target.write(source.read().format(app_publisher=app_publisher,
classname=self.name.replace(" ", ""), doctype=self.name))
_make_boilerplate("controller.py")
make_boilerplate("controller.py", self)
if not (self.istable or self.issingle):
_make_boilerplate("test_controller.py")
_make_boilerplate("test_records.json")
make_boilerplate("test_controller.py", self)
make_boilerplate("test_records.json", self)
def make_amendable(self):
"""
@ -392,3 +373,25 @@ def make_module_and_roles(doc, perm_fieldname="permissions"):
pass
else:
raise
def init_list(doctype):
doc = frappe.get_meta(doctype)
make_boilerplate("controller_list.js", doc)
make_boilerplate("controller_list.html", doc)
def make_boilerplate(template, doc):
target_path = get_doc_path(doc.module, doc.doctype, doc.name)
template_name = template.replace("controller", scrub(doc.name))
target_file_path = os.path.join(target_path, template_name)
app = frappe.local.module_app[scrub(doc.module)]
if not app:
frappe.throw(_("App not found"))
app_publisher = frappe.get_hooks(hook="app_publisher", app_name=app)[0]
if not os.path.exists(target_file_path):
with open(target_file_path, 'w') as target:
with open(os.path.join(get_module_path("core"), "doctype", "doctype",
"boilerplate", template), 'r') as source:
target.write(source.read().format(app_publisher=app_publisher,
classname=doc.name.replace(" ", ""), doctype=doc.name))

View file

@ -322,11 +322,16 @@ frappe.views.ListView = Class.extend({
}
// title
var full_title = data[this.title_field || "name"], title = full_title;
if(full_title.length > 40) {
title = full_title.slice(0, 40) + "...";
}
html += repl('<a class="form-link list-id" style="margin-left: 5px; margin-right: 8px;" \
href="#Form/%(doctype)s/%(name)s" title="%(title)s">%(title)s</a>', {
href="#Form/%(doctype)s/%(name)s" title="%(full_title)s">%(title)s</a>', {
doctype: data.doctype,
name: encodeURIComponent(data.name),
title: data[this.title_field || "name"]
title: title,
full_title: full_title,
});
this.title_offset_left += 5;