From bd7f7231f21437d969087be249a664831e81c803 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Fri, 15 Jun 2012 14:00:06 +0530 Subject: [PATCH] cms now powered by jinja2 --- erpnext/website/templates/404.html | 12 ++++++ erpnext/website/templates/__init__.py | 0 erpnext/website/templates/base.html | 20 ++++++++++ erpnext/website/templates/blog.html | 53 +++++++++++++++++++++++++ erpnext/website/templates/outer.html | 57 +++++++++++++++++++++++++++ erpnext/website/templates/page.html | 32 +++++++++++++++ public/js/all-app.js | 2 +- public/js/all-web.js | 2 +- public/{index.cgi => server.py} | 0 public/web.py | 57 +++++++++++++++++++++++++++ 10 files changed, 233 insertions(+), 2 deletions(-) create mode 100644 erpnext/website/templates/404.html create mode 100644 erpnext/website/templates/__init__.py create mode 100644 erpnext/website/templates/base.html create mode 100644 erpnext/website/templates/blog.html create mode 100644 erpnext/website/templates/outer.html create mode 100644 erpnext/website/templates/page.html rename public/{index.cgi => server.py} (100%) create mode 100755 public/web.py diff --git a/erpnext/website/templates/404.html b/erpnext/website/templates/404.html new file mode 100644 index 0000000000..8a30892a66 --- /dev/null +++ b/erpnext/website/templates/404.html @@ -0,0 +1,12 @@ +{% extends "outer.html" %} + +{% block content %} +
+
+

Page missing or moved

+
+

We are very sorry for this, but the page you are looking for is missing + (this could be because of a typo in the address) or moved.

+
+
+{% endblock %} \ No newline at end of file diff --git a/erpnext/website/templates/__init__.py b/erpnext/website/templates/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/website/templates/base.html b/erpnext/website/templates/base.html new file mode 100644 index 0000000000..cd64139b82 --- /dev/null +++ b/erpnext/website/templates/base.html @@ -0,0 +1,20 @@ + + + + {% block title %}{% endblock %} + + + + + + + + + + {% block header %} + {% endblock %} + + + {% block body %} + {% endblock %} + \ No newline at end of file diff --git a/erpnext/website/templates/blog.html b/erpnext/website/templates/blog.html new file mode 100644 index 0000000000..30dbd3b87e --- /dev/null +++ b/erpnext/website/templates/blog.html @@ -0,0 +1,53 @@ +{% extends "index.html" %} + +{% block content %} +
+
+
+

Blog

+
+
+ +
+
+
+ +

Subscribe

+

+ + RSS Feed +

+
+
+
+
+ + \ No newline at end of file diff --git a/erpnext/website/templates/outer.html b/erpnext/website/templates/outer.html new file mode 100644 index 0000000000..4b8c04dcab --- /dev/null +++ b/erpnext/website/templates/outer.html @@ -0,0 +1,57 @@ +{# + requires, brand, top_bar_items, footer_items, copyright, content +#} + +{% extends "base.html" %} + +{% block body %} + +
+ +
+
+
+ {% block content %} + {% endblock %} +
+
+ + +{% endblock %} \ No newline at end of file diff --git a/erpnext/website/templates/page.html b/erpnext/website/templates/page.html new file mode 100644 index 0000000000..0eccd87e2e --- /dev/null +++ b/erpnext/website/templates/page.html @@ -0,0 +1,32 @@ +{% extends "outer.html" %} + +{% block title %}{{ title }}{% endblock %} + +{% block header %} + {{ super() }} + {% if script %} + + {% endif %} + {% if style %} + + {% endif %} +{% endblock %} + +{% block content %} + {{ content }} +{% endblock %} \ No newline at end of file diff --git a/public/js/all-app.js b/public/js/all-app.js index 32a2e2965b..859af21f92 100644 --- a/public/js/all-app.js +++ b/public/js/all-app.js @@ -389,7 +389,7 @@ wn.views.make_404=function(){var page=wn.container.add_page('404');$(page).html( /* * lib/js/wn/request.js */ -wn.provide('wn.request');wn.request.url='index.cgi';wn.request.prepare=function(opts){if(opts.btn)$(opts.btn).set_working();if(opts.show_spinner)set_loading();if(opts.freeze)freeze();if(!opts.args.cmd){console.log(opts) +wn.provide('wn.request');wn.request.url='server.py';wn.request.prepare=function(opts){if(opts.btn)$(opts.btn).set_working();if(opts.show_spinner)set_loading();if(opts.freeze)freeze();if(!opts.args.cmd){console.log(opts) throw"Incomplete Request";}} wn.request.cleanup=function(opts,r){if(opts.btn)$(opts.btn).done_working();if(opts.show_spinner)hide_loading();if(opts.freeze)unfreeze();if(wn.boot&&wn.boot.sid&&wn.get_cookie('sid')!=wn.boot.sid){if(!wn.app.logged_out){msgprint('Session Expired. Logging you out');wn.app.logout();} return;} diff --git a/public/js/all-web.js b/public/js/all-web.js index 381d5f844f..1f703109a4 100644 --- a/public/js/all-web.js +++ b/public/js/all-web.js @@ -276,7 +276,7 @@ wn.views.make_404=function(){var page=wn.container.add_page('404');$(page).html( /* * lib/js/wn/request.js */ -wn.provide('wn.request');wn.request.url='index.cgi';wn.request.prepare=function(opts){if(opts.btn)$(opts.btn).set_working();if(opts.show_spinner)set_loading();if(opts.freeze)freeze();if(!opts.args.cmd){console.log(opts) +wn.provide('wn.request');wn.request.url='server.py';wn.request.prepare=function(opts){if(opts.btn)$(opts.btn).set_working();if(opts.show_spinner)set_loading();if(opts.freeze)freeze();if(!opts.args.cmd){console.log(opts) throw"Incomplete Request";}} wn.request.cleanup=function(opts,r){if(opts.btn)$(opts.btn).done_working();if(opts.show_spinner)hide_loading();if(opts.freeze)unfreeze();if(wn.boot&&wn.boot.sid&&wn.get_cookie('sid')!=wn.boot.sid){if(!wn.app.logged_out){msgprint('Session Expired. Logging you out');wn.app.logout();} return;} diff --git a/public/index.cgi b/public/server.py similarity index 100% rename from public/index.cgi rename to public/server.py diff --git a/public/web.py b/public/web.py new file mode 100755 index 0000000000..d05eb940bd --- /dev/null +++ b/public/web.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python + +""" +return a dynamic page from website templates +""" + +import cgi, cgitb, os, sys +cgitb.enable() + +# import libs +sys.path.append('..') +import conf +sys.path.append('../lib/py') +sys.path.append(conf.modules_path) + +def get_outer_env(): + """env for outer (cache this)""" + import webnotes + return { + 'top_bar_items': webnotes.conn.sql("""select * from `tabTop Bar Item` + where parent='Website Settings' and parentfield='top_bar_items' + order by idx asc""", as_dict=1), + + 'footer_items': webnotes.conn.sql("""select * from `tabTop Bar Item` + where parent='Website Settings' and parentfield='footer_items' + order by idx asc""", as_dict=1), + + 'brand': webnotes.conn.get_value('Website Settings', None, 'brand_html'), + 'copyright': webnotes.conn.get_value('Website Settings', None, 'copyright'), + } + +def get_html(): + import webnotes + from jinja2 import Environment, FileSystemLoader + from webnotes.model.doc import Document + + jenv = Environment(loader = FileSystemLoader('../erpnext/website/templates')) + + webnotes.form = cgi.FieldStorage(keep_blank_values=True) + for key in webnotes.form.keys(): + webnotes.form_dict[key] = webnotes.form.getvalue(key) + webnotes.connect() + + if 'page' in webnotes.form_dict: + try: + page = Document('Page', webnotes.form_dict['page']) + page.fields.update(get_outer_env()) + return jenv.get_template('page.html').render(page.fields) + except Exception, e: + return jenv.get_template('404.html').render(get_outer_env()) + else: + return jenv.get_template('404.html').render(get_outer_env()) + +if __name__=="__main__": + print "Content-Type: text/html" + print + print get_html().encode('utf-8')