diff --git a/core/doctype/print_format/print_format.py b/core/doctype/print_format/print_format.py index 090566dc01..0521d35422 100644 --- a/core/doctype/print_format/print_format.py +++ b/core/doctype/print_format/print_format.py @@ -22,7 +22,9 @@ from __future__ import unicode_literals import webnotes, conf, os +import webnotes.utils from webnotes.utils import get_base_path +from webnotes.modules import get_doc_path class DocType: def __init__(self, d, dl): @@ -64,73 +66,54 @@ def get_args():
%s
""" % repr(webnotes.form_dict) } - obj = webnotes.get_obj(webnotes.form_dict.doctype, webnotes.form_dict.name) + obj = webnotes.bean(webnotes.form_dict.doctype, webnotes.form_dict.name) return { - "body": get_html(obj.doc, obj.doclist) + "body": get_html(obj.doc, obj.doclist), + "css": get_print_style(webnotes.form_dict.style) } def get_html(doc, doclist): from jinja2 import Environment - from core.doctype.print_style.print_style import get_print_style from core.doctype.print_format.print_format import get_print_format - template = Environment().from_string(get_print_format(webnotes.form_dict.format)) + template = Environment().from_string(get_print_format(doc.doctype, webnotes.form_dict.format)) doctype = webnotes.get_doctype(doc.doctype) args = { "doc": doc, "doclist": doclist, - "print_style": get_print_style(), - "doctype_structure": make_doctype_structure(doctype), - "doctype": doctype + "doctype": doctype, + "webnotes": webnotes, + "utils": webnotes.utils } html = template.render(args) return html -def make_doctype_structure(doctype): - """wip""" - s = [] - fields = doctype.get({"doctype":"DocField"}) - - # first get all section breaks - for docfield in fields: - if docfield.fieldtype=="Section Break": - s.append(docfield) - - if s[0].idx != 1: - s = [webnotes._dict({"fieldtype":"Section Break", "idx":-1})] + s - - # then get columns in inside section break - for sb in s: - sb.columns = [] - - for docfield in fields: - if docfield.idx > sb.idx: - # missing first column break - if docfield.idx == sb.idx + 1 and docfield.fieldtype!="Column Break": - sb.columns.append(webnotes._dict({"fieldtype":"Column Break", - "idx":sb.idx})) - elif docfield.fieldtype=="Column Break": - sb.columns.append(docfield) - elif docfield.fieldtype=="Section Break": - break - - for cb in sb.columns: - cb.fields = [] - - return s - -def get_print_format(name): - html = webnotes.conn.get_value("Print Format", name, "html") - if html: - return html - +def get_print_format(doctype, format): # server, find template - path = os.path.join(get_base_path(), "lib", "core", "doctype", "print_format", - "templates", name.lower() + ".html") + path = os.path.join(get_doc_path(webnotes.conn.get_value("DocType", doctype, "module"), + "Print Format", format), format + ".html") if os.path.exists(path): with open(path, "r") as pffile: return pffile.read() else: - return "" + html = webnotes.conn.get_value("Print Format", format, "html") + if html: + return html + else: + return "No template found.\npath: " + path +def get_print_style(style=None): + if not style: + style = webnotes.conn.get_default("print_style") or "Standard" + path = os.path.join(get_doc_path("Core", "DocType", "Print Format"), "styles", + style.lower() + ".css") + if not os.path.exists(path): + if style!="Standard": + return get_print_style("Standard") + else: + return "/* Standard Style Missing ?? */" + else: + with open(path, 'r') as sfile: + return sfile.read() + """ \* test *\ """ + \ No newline at end of file diff --git a/core/doctype/print_format/print_format.txt b/core/doctype/print_format/print_format.txt index bc81048e43..1e4abc4dd0 100644 --- a/core/doctype/print_format/print_format.txt +++ b/core/doctype/print_format/print_format.txt @@ -1,8 +1,8 @@ [ { - "creation": "2013-01-10 16:34:04", + "creation": "2013-01-23 19:54:43", "docstatus": 0, - "modified": "2013-01-22 14:56:41", + "modified": "2013-03-21 15:44:15", "modified_by": "Administrator", "owner": "Administrator" }, @@ -31,22 +31,18 @@ "name": "__common__", "parent": "Print Format", "parentfield": "fields", - "parenttype": "DocType", - "permlevel": 0 + "parenttype": "DocType" }, { - "cancel": 1, - "create": 1, + "amend": 0, "doctype": "DocPerm", "name": "__common__", "parent": "Print Format", "parentfield": "permissions", "parenttype": "DocType", - "permlevel": 0, "read": 1, "report": 1, - "submit": 0, - "write": 1 + "submit": 0 }, { "doctype": "DocType", @@ -64,6 +60,7 @@ "oldfieldname": "module", "oldfieldtype": "Select", "options": "link:Module Def", + "permlevel": 0, "print_hide": 0, "report_hide": 0, "reqd": 1, @@ -77,9 +74,16 @@ "in_filter": 1, "label": "DocType", "options": "link:DocType", + "permlevel": 0, "reqd": 0, "search_index": 0 }, + { + "doctype": "DocField", + "fieldname": "column_break_3", + "fieldtype": "Column Break", + "permlevel": 0 + }, { "allow_on_submit": 0, "default": "No", @@ -93,14 +97,30 @@ "oldfieldname": "standard", "oldfieldtype": "Select", "options": "No\nYes", + "permlevel": 1, "print_hide": 0, - "read_only": 1, + "read_only": 0, "report_hide": 0, "reqd": 1, "search_index": 1 }, + { + "doctype": "DocField", + "fieldname": "print_format_type", + "fieldtype": "Select", + "label": "Print Format Type", + "options": "Client\nServer", + "permlevel": 0 + }, + { + "doctype": "DocField", + "fieldname": "section_break_6", + "fieldtype": "Section Break", + "permlevel": 0 + }, { "allow_on_submit": 0, + "depends_on": "eval:doc.print_format_type!=\"Server\"", "doctype": "DocField", "fieldname": "html", "fieldtype": "Code", @@ -111,18 +131,41 @@ "oldfieldname": "html", "oldfieldtype": "Text Editor", "options": "HTML", + "permlevel": 0, "print_hide": 0, "report_hide": 0, "reqd": 0, "search_index": 0 }, { - "amend": 0, + "cancel": 1, + "create": 1, "doctype": "DocPerm", + "permlevel": 0, + "role": "Administrator", + "write": 1 + }, + { + "cancel": 1, + "create": 1, + "doctype": "DocPerm", + "permlevel": 0, + "role": "System Manager", + "write": 1 + }, + { + "cancel": 0, + "create": 0, + "doctype": "DocPerm", + "permlevel": 1, "role": "System Manager" }, { + "cancel": 0, + "create": 0, "doctype": "DocPerm", - "role": "Administrator" + "permlevel": 1, + "role": "Administrator", + "write": 1 } ] \ No newline at end of file diff --git a/core/doctype/print_format/styles/classic.css b/core/doctype/print_format/styles/classic.css new file mode 100644 index 0000000000..d6a08f06d8 --- /dev/null +++ b/core/doctype/print_format/styles/classic.css @@ -0,0 +1,82 @@ +/* + common style for whole page + This should include: + + page size related settings + + font family settings + + line spacing settings +*/ +@media screen { + body { + width: 8.3in; + } +} + +html, body, div, span, td { + font-family: "Georgia", serif; + font-size: 12px; +} + +body { + padding: 10px; + margin: auto; + font-size: 12px; + line-height: 150%; +} + +.common { + font-family: "Georgia", serif !important; + font-size: 12px; + padding: 10px 0px; +} + +table { + border-collapse: collapse; + width: 100%; + vertical-align: top; +} + +table td { + padding: 2px 0px; +} + +table.table-bordered td, +table.table-bordered th { + border: 1px solid #000; + padding: 2px; + vertical-align: top; +} + +table h1, h2, h3, h4, h5, h6 { + padding: 0px; + margin: 0px; +} + +table.header-table td { + vertical-align: top; +} + +table.header-table thead { + border-bottom: 1px solid black; +} + +table.header-table h3 { + color: gray; +} + +table.header-table thead td { + padding: 5px 0px; +} + +div.page-body table td:nth-child(6), +div.page-body table td:nth-child(7) { + text-align: right; +} + +table.footer-table td { + vertical-align: top; +} + +table.footer-table td table td:nth-child(2), +table.footer-table td table td:nth-child(3) { + text-align: right; +} diff --git a/core/doctype/print_format/styles/modern.css b/core/doctype/print_format/styles/modern.css new file mode 100644 index 0000000000..e9f9a95501 --- /dev/null +++ b/core/doctype/print_format/styles/modern.css @@ -0,0 +1,97 @@ +@media screen { + body { + width: 8.3in; + } +} + +html, body, div, span, td { + font-family: "Helvetica", "Arial", sans-serif; + font-size: 12px; +} + +body { + padding: 10px; + margin: auto; + font-size: 12px; + line-height: 150%; +} + +.common { + font-family: "Helvetica", "Arial", sans-serif !important; + font-size: 12px; + padding: 10px 0px; +} + +table { + border-collapse: collapse; + width: 100%; + vertical-align: top; + border-style: none !important; +} + +table td { + padding: 2px 0px; + border-style: none !important; +} + +table.table-bordered td, +table.table-bordered th { + padding: 2px; + vertical-align: top; +} + +table h1, h2, h3, h4, h5, h6 { + padding: 0px; + margin: 0px; +} + +table.header-table td { + vertical-align: top; +} + +table.header-table h1 { + text-transform: uppercase; + color: white; + font-size: 55px; + font-style: italic; +} + +table.header-table thead tr:nth-child(1) td { + height: 24px; + background-color: #696969; + vertical-align: middle; + padding: 12px 0px 0px 0px; + width: 100%; +} + +div.page-body table td:nth-child(6), +div.page-body table td:nth-child(7) { + text-align: right; +} + +div.page-body table tr td { + background-color: #DCDCDC !important; +} + +div.page-body table th { + background-color: #696969 !important; + color: white !important; +} + +table.footer-table td { + vertical-align: top; +} + +table.footer-table td table td:nth-child(2), +table.footer-table td table td:nth-child(3) { + text-align: right; +} + +table.footer-table tfoot td { + background-color: #696969; + height: 10px; +} + +.imp-details { + background-color: #DCDCDC; +} \ No newline at end of file diff --git a/core/doctype/print_style/standard/standard.css b/core/doctype/print_format/styles/standard.css similarity index 98% rename from core/doctype/print_style/standard/standard.css rename to core/doctype/print_format/styles/standard.css index 05eaf9cd11..17b18bb050 100644 --- a/core/doctype/print_style/standard/standard.css +++ b/core/doctype/print_format/styles/standard.css @@ -1,5 +1,11 @@ +@media screen { + body { + width: 8.3in; + } +} body { - margin: 0; + padding: 10px; + margin: auto; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; line-height: 20px; @@ -78,6 +84,10 @@ table { border-spacing: 0; } +td { + vertical-align: top; +} + .table { width: 100%; margin-bottom: 20px; diff --git a/core/doctype/print_format/templates/standard.html b/core/doctype/print_format/templates/standard.html deleted file mode 100644 index 5566ea3030..0000000000 --- a/core/doctype/print_format/templates/standard.html +++ /dev/null @@ -1,16 +0,0 @@ - - -

{{ doc.name }}

- -{% macro make_section(sb) %} -

{{ sb.label }}

-{% for cb in sb.columns %} -

{{ cb.label }}

-{% endfor %} -{% endmacro %} - -{% for sb in doctype_structure %} -{{ make_section(sb) }} -{% endfor %} \ No newline at end of file diff --git a/core/doctype/print_style/__init__.py b/core/doctype/print_style/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/core/doctype/print_style/print_style.py b/core/doctype/print_style/print_style.py deleted file mode 100644 index 94d7664d55..0000000000 --- a/core/doctype/print_style/print_style.py +++ /dev/null @@ -1,27 +0,0 @@ -# For license information, please see license.txt - -from __future__ import unicode_literals -import webnotes -from webnotes.utils import get_base_path -import os - -class DocType: - def __init__(self, d, dl): - self.doc, self.doclist = d, dl - -def get_print_style(): - name = webnotes.conn.get_default("print_style") or "Standard" - css = webnotes.conn.get_value("Print Style", name, "css") - if css: - return css - - # find in local - path = os.path.join(get_base_path(), "lib", "core", "doctype", "print_style", - "standard", name.lower() + ".css") - if os.path.exists(path): - with open(path, "r") as psfile: - return psfile.read() - else: - return "" - - \ No newline at end of file diff --git a/core/doctype/print_style/print_style.txt b/core/doctype/print_style/print_style.txt deleted file mode 100644 index 5ce9623be0..0000000000 --- a/core/doctype/print_style/print_style.txt +++ /dev/null @@ -1,52 +0,0 @@ -[ - { - "creation": "2013-03-19 11:23:14", - "docstatus": 0, - "modified": "2013-03-19 11:23:14", - "modified_by": "Administrator", - "owner": "Administrator" - }, - { - "autoname": "Prompt", - "description": "Stylesheet for Print Format (Server)", - "doctype": "DocType", - "module": "Core", - "name": "__common__" - }, - { - "doctype": "DocField", - "fieldname": "css", - "fieldtype": "Code", - "label": "CSS", - "name": "__common__", - "parent": "Print Style", - "parentfield": "fields", - "parenttype": "DocType", - "permlevel": 0 - }, - { - "amend": 0, - "cancel": 1, - "create": 1, - "doctype": "DocPerm", - "name": "__common__", - "parent": "Print Style", - "parentfield": "permissions", - "parenttype": "DocType", - "permlevel": 0, - "read": 1, - "report": 1, - "role": "System Manager", - "write": 1 - }, - { - "doctype": "DocType", - "name": "Print Style" - }, - { - "doctype": "DocField" - }, - { - "doctype": "DocPerm" - } -] \ No newline at end of file