From 7c2312a74c7e186bd7d16c9b872dbc0e1d32c883 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 10 Sep 2013 12:51:52 +0530 Subject: [PATCH] [website] [minor] moving to framework --- selling/utils/product.py | 14 ++++++++------ setup/doctype/item_group/templates/__init__.py | 0 .../templates/generators/__init__.py | 0 .../templates/{ => generators}/item_group.html | 10 +++++----- .../templates/generators/item_group.py | 2 ++ setup/doctype/sales_partner/sales_partner.py | 8 +------- .../sales_partner/templates/__init__.py | 0 .../templates/generators/__init__.py | 0 .../partner.html} | 2 +- .../templates/generators/partner.py | 2 ++ .../sales_partner/templates/pages/__init__.py | 0 .../templates/{ => pages}/partners.html | 2 +- .../sales_partner/templates/pages/partners.py | 7 +++++++ stock/doctype/item/templates/__init__.py | 0 .../item/templates/generators/__init__.py | 0 .../item/templates/{ => generators}/item.html | 18 +++++++++++------- .../doctype/item/templates/generators/item.py | 2 ++ .../includes/product_breadcrumbs.html | 2 +- .../templates/includes/product_in_grid.html | 2 +- .../templates/{ => pages}/product_search.html | 2 +- 20 files changed, 43 insertions(+), 30 deletions(-) create mode 100644 setup/doctype/item_group/templates/__init__.py create mode 100644 setup/doctype/item_group/templates/generators/__init__.py rename setup/doctype/item_group/templates/{ => generators}/item_group.html (72%) create mode 100644 setup/doctype/item_group/templates/generators/item_group.py create mode 100644 setup/doctype/sales_partner/templates/__init__.py create mode 100644 setup/doctype/sales_partner/templates/generators/__init__.py rename setup/doctype/sales_partner/templates/{partner_page.html => generators/partner.html} (94%) create mode 100644 setup/doctype/sales_partner/templates/generators/partner.py create mode 100644 setup/doctype/sales_partner/templates/pages/__init__.py rename setup/doctype/sales_partner/templates/{ => pages}/partners.html (93%) create mode 100644 setup/doctype/sales_partner/templates/pages/partners.py create mode 100644 stock/doctype/item/templates/__init__.py create mode 100644 stock/doctype/item/templates/generators/__init__.py rename stock/doctype/item/templates/{ => generators}/item.html (79%) create mode 100644 stock/doctype/item/templates/generators/item.py rename stock/doctype/item/templates/{ => pages}/product_search.html (93%) diff --git a/selling/utils/product.py b/selling/utils/product.py index fb0605e51d..13a9b15a22 100644 --- a/selling/utils/product.py +++ b/selling/utils/product.py @@ -4,8 +4,8 @@ from __future__ import unicode_literals import webnotes -from webnotes.utils import cstr, cint, fmt_money -from webnotes.webutils import build_html, delete_page_cache +from webnotes.utils import cstr, cint, fmt_money, get_base_path +from webnotes.webutils import delete_page_cache from selling.utils.cart import _get_cart_quotation @webnotes.whitelist(allow_guest=True) @@ -106,10 +106,12 @@ def get_group_item_count(item_group): or name in (select parent from `tabWebsite Item Group` where item_group in (%s))) """ % (child_groups, child_groups))[0][0] -def get_item_for_list_in_html(r): - scrub_item_for_list(r) - r.template = "app/website/templates/html/product_in_grid.html" - return build_html(r) +def get_item_for_list_in_html(context): + from jinja2 import Environment, FileSystemLoader + scrub_item_for_list(context) + jenv = Environment(loader = FileSystemLoader(get_base_path())) + template = jenv.get_template("app/stock/doctype/item/templates/includes/product_in_grid.html") + return template.render(context) def scrub_item_for_list(r): if not r.website_description: diff --git a/setup/doctype/item_group/templates/__init__.py b/setup/doctype/item_group/templates/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/setup/doctype/item_group/templates/generators/__init__.py b/setup/doctype/item_group/templates/generators/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/setup/doctype/item_group/templates/item_group.html b/setup/doctype/item_group/templates/generators/item_group.html similarity index 72% rename from setup/doctype/item_group/templates/item_group.html rename to setup/doctype/item_group/templates/generators/item_group.html index 4bf52c5372..22570d10c8 100644 --- a/setup/doctype/item_group/templates/item_group.html +++ b/setup/doctype/item_group/templates/generators/item_group.html @@ -1,11 +1,11 @@ -{% extends "app/website/templates/html/page.html" %} +{% extends base_template %} {% block content %} -{% include 'app/website/templates/html/product_search_box.html' %} -{% include 'app/website/templates/html/product_breadcrumbs.html' %} +{% include 'app/stock/doctype/item/templates/includes/product_search_box.html' %} +{% include 'app/stock/doctype/item/templates/includes/product_breadcrumbs.html' %}
{% if slideshow %} - {% include "app/website/templates/html/slideshow.html" %} + {% include "lib/website/templates/includes/slideshow.html" %} {% endif %} {% if description %}
{{ description or ""}}
@@ -31,7 +31,7 @@ {{ item }} {% endfor %}
- {% if len(items)==100 %} + {% if (items|length)==100 %}
Showing top 100 items.
{% endif %} {% else %} diff --git a/setup/doctype/item_group/templates/generators/item_group.py b/setup/doctype/item_group/templates/generators/item_group.py new file mode 100644 index 0000000000..12ef51378c --- /dev/null +++ b/setup/doctype/item_group/templates/generators/item_group.py @@ -0,0 +1,2 @@ +doctype = "Item Group" +condition_field = "show_in_website" \ No newline at end of file diff --git a/setup/doctype/sales_partner/sales_partner.py b/setup/doctype/sales_partner/sales_partner.py index 545ae71f0e..0d7e12d999 100644 --- a/setup/doctype/sales_partner/sales_partner.py +++ b/setup/doctype/sales_partner/sales_partner.py @@ -42,10 +42,4 @@ class DocType: "email": address.email_id, "partner_address": filter_strip_join(address_rows, "\n
"), "phone": filter_strip_join(cstr(address.phone).split(","), "\n
") - }) - -def get_partner_args(): - return { - "partners": webnotes.conn.sql("""select * from `tabSales Partner` - where show_in_website=1 order by name asc""", as_dict=True), - } \ No newline at end of file + }) \ No newline at end of file diff --git a/setup/doctype/sales_partner/templates/__init__.py b/setup/doctype/sales_partner/templates/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/setup/doctype/sales_partner/templates/generators/__init__.py b/setup/doctype/sales_partner/templates/generators/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/setup/doctype/sales_partner/templates/partner_page.html b/setup/doctype/sales_partner/templates/generators/partner.html similarity index 94% rename from setup/doctype/sales_partner/templates/partner_page.html rename to setup/doctype/sales_partner/templates/generators/partner.html index e5aac3593b..eb1481b224 100644 --- a/setup/doctype/sales_partner/templates/partner_page.html +++ b/setup/doctype/sales_partner/templates/generators/partner.html @@ -1,4 +1,4 @@ -{% extends "app/website/templates/html/page.html" %} +{% extends base_template %} {% block content %}
diff --git a/setup/doctype/sales_partner/templates/generators/partner.py b/setup/doctype/sales_partner/templates/generators/partner.py new file mode 100644 index 0000000000..2229f0379b --- /dev/null +++ b/setup/doctype/sales_partner/templates/generators/partner.py @@ -0,0 +1,2 @@ +doctype = "Sales Partner" +condition_field = "show_in_website" \ No newline at end of file diff --git a/setup/doctype/sales_partner/templates/pages/__init__.py b/setup/doctype/sales_partner/templates/pages/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/setup/doctype/sales_partner/templates/partners.html b/setup/doctype/sales_partner/templates/pages/partners.html similarity index 93% rename from setup/doctype/sales_partner/templates/partners.html rename to setup/doctype/sales_partner/templates/pages/partners.html index 50a095dd1b..14c72ae87e 100644 --- a/setup/doctype/sales_partner/templates/partners.html +++ b/setup/doctype/sales_partner/templates/pages/partners.html @@ -1,4 +1,4 @@ -{% extends "app/website/templates/html/page.html" %} +{% extends base_template %} {% set title="Partners" %} diff --git a/setup/doctype/sales_partner/templates/pages/partners.py b/setup/doctype/sales_partner/templates/pages/partners.py new file mode 100644 index 0000000000..5245ec0e3f --- /dev/null +++ b/setup/doctype/sales_partner/templates/pages/partners.py @@ -0,0 +1,7 @@ +import webnotes + +def get_context(): + return { + "partners": webnotes.conn.sql("""select * from `tabSales Partner` + where show_in_website=1 order by name asc""", as_dict=True), + } \ No newline at end of file diff --git a/stock/doctype/item/templates/__init__.py b/stock/doctype/item/templates/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/stock/doctype/item/templates/generators/__init__.py b/stock/doctype/item/templates/generators/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/stock/doctype/item/templates/item.html b/stock/doctype/item/templates/generators/item.html similarity index 79% rename from stock/doctype/item/templates/item.html rename to stock/doctype/item/templates/generators/item.html index 5ac0b480b6..d85547994e 100644 --- a/stock/doctype/item/templates/item.html +++ b/stock/doctype/item/templates/generators/item.html @@ -1,28 +1,32 @@ -{% extends "app/website/templates/html/page.html" %} +{% extends base_template %} {% block javascript %} - {% include "app/website/templates/js/product_page.js" %} + {% endblock %} {% block css %} - {% include "app/website/templates/css/product_page.css" %} + {% endblock %} {% block content %} - {% include 'app/website/templates/html/product_search_box.html' %} - {% include 'app/website/templates/html/product_breadcrumbs.html' %} + {% include 'app/stock/doctype/item/templates/includes/product_search_box.html' %} + {% include 'app/stock/doctype/item/templates/includes/product_breadcrumbs.html' %}
{% if slideshow %} - {% include "app/website/templates/html/slideshow.html" %} + {% include "lib/website/templates/includes/html/slideshow.html" %} {% else %} {% if website_image %} {% else %}
- {% include 'app/website/templates/html/product_missing_image.html' %} + {% include 'app/stock/doctype/item/templates/includes/product_missing_image.html' %}
{% endif %} {% endif %} diff --git a/stock/doctype/item/templates/generators/item.py b/stock/doctype/item/templates/generators/item.py new file mode 100644 index 0000000000..c9146d1640 --- /dev/null +++ b/stock/doctype/item/templates/generators/item.py @@ -0,0 +1,2 @@ +doctype = "Item" +condition_field = "show_in_website" \ No newline at end of file diff --git a/stock/doctype/item/templates/includes/product_breadcrumbs.html b/stock/doctype/item/templates/includes/product_breadcrumbs.html index 6d267489d0..f073e6f4df 100644 --- a/stock/doctype/item/templates/includes/product_breadcrumbs.html +++ b/stock/doctype/item/templates/includes/product_breadcrumbs.html @@ -1,4 +1,4 @@ -{% if obj.parent_groups and len(obj.parent_groups) > 1 %} +{% if obj.parent_groups and (obj.parent_groups|length) > 1 %}
diff --git a/stock/doctype/item/templates/product_search.html b/stock/doctype/item/templates/pages/product_search.html similarity index 93% rename from stock/doctype/item/templates/product_search.html rename to stock/doctype/item/templates/pages/product_search.html index e969f75825..37e50dc0a1 100644 --- a/stock/doctype/item/templates/product_search.html +++ b/stock/doctype/item/templates/pages/product_search.html @@ -1,4 +1,4 @@ -{% extends "app/website/templates/html/page.html" %} +{% extends base_template %} {% set title="Product Search" %}