cms now powered by jinja2
diff --git a/erpnext/website/templates/404.html b/erpnext/website/templates/404.html
new file mode 100644
index 0000000..8a30892
--- /dev/null
+++ b/erpnext/website/templates/404.html
@@ -0,0 +1,12 @@
+{% extends "outer.html" %}
+
+{% block content %}
+<div class="content">
+	<div class="layout-wrapper layout-main">
+		<h3>Page missing or moved</h3>
+		<br>
+		<p>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.</p>
+	</div>
+</div>
+{% 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 0000000..e69de29
--- /dev/null
+++ b/erpnext/website/templates/__init__.py
diff --git a/erpnext/website/templates/base.html b/erpnext/website/templates/base.html
new file mode 100644
index 0000000..cd64139
--- /dev/null
+++ b/erpnext/website/templates/base.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<head>
+	<meta charset="utf-8">
+	<title>{% block title %}{% endblock %}</title>
+	<meta name="generator" content="wnframework">
+	<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">
+	<link rel="icon" href="images/favicon.ico" type="image/x-icon">
+	<script type="text/javascript" src="js/lib/jquery/jquery.min.js"></script>
+	<script type="text/javascript" src="js/all-web.js"></script>
+	<script type="text/javascript" src="js/wn-web.js"></script>
+	<link type="text/css" rel="stylesheet" href="css/all-web.css">
+	<link type="text/css" rel="stylesheet" href="css/wn-web.css">
+	
+	{% block header %}
+	{% endblock %}
+</head>
+<body>
+	{% block body %}
+	{% endblock %}
+</body>
\ 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 0000000..30dbd3b
--- /dev/null
+++ b/erpnext/website/templates/blog.html
@@ -0,0 +1,53 @@
+{% extends "index.html" %}
+
+{% block content %}
+<div class="layout-wrapper layout-wrapper-background">
+	<div class="web-content" id="content-blog">
+		<div class="layout-main-section">
+			<h1>Blog</h1>
+			<br>
+			<div id="blog-list">
+				<!-- blog list will be generated dynamically -->
+			</div>
+		</div>
+		<div class="layout-side-section">
+			<!-- for later
+			<h4>Get Updates</h4>
+			<p>
+			<input name="blog-subscribe">
+			<button class="btn" id="blog-subscribe">Subscribe</button>
+			</p>-->
+			<h4>Subscribe</h4>
+			<p>
+			<img src="images/feed.png" style="margin-right: 4px; margin-bottom: -4px">
+			<a href="rss.xml" target="_blank">RSS Feed</a>
+			</p>
+		</div>
+		<div style="clear: both"></div>
+	</div>
+</div>
+
+<script>
+wrapper.blog_list = new wn.ui.Listing({
+	parent: $(wrapper).find('#blog-list').get(0),
+	query: 'select tabBlog.name, title, left(content, 1000) as content, tabBlog.creation, \
+		ifnull(first_name, "") as first_name, ifnull(last_name, "") as last_name \
+		from tabProfile, tabBlog\
+	 	where ifnull(published,0)=1 and tabBlog.owner = tabProfile.name \
+		order by tabBlog.creation desc',
+	hide_refresh: true,
+	no_toolbar: true,
+	render_row: function(parent, data) {
+		if(data.content && data.content.length==1000) data.content += '... (read on)';
+		data.content = wn.markdown(data.content);
+		if(data.last_name) data.last_name = ' ' + data.last_name;
+		data.date = prettyDate(data.creation);
+		parent.innerHTML = repl('<h2>%(title)s</h2>\
+			<p><div class="help">By %(first_name)s%(last_name)s, %(date)s</div></p>\
+			<p>%(content)s</p>\
+			<a href="%(name)s.html">Read Full Text</a><br>', data);
+	},
+	page_length: 10
+});
+wrapper.blog_list.run();
+</script>
\ 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 0000000..4b8c04d
--- /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 %}
+
+	<header>
+		<div class="navbar navbar-fixed-top">
+			<div class="navbar-inner">
+			<div class="container">
+				<a class="brand" href="index.html">{{ brand }}</a>
+				<ul class="nav">
+					{% for page in top_bar_items %}
+						{% if not page.parent_label %}
+						<li data-label="{{ page.label }}">
+							<a href="{{ page.url }}" {{ page.target }}>
+							{{ page.label }}
+							{% if page.child_items %}
+								<ul class="dropdown-menu">
+								{% for child in page.child_items %}
+									<li data-label="{{ child.label }}">
+										<a href="{{ child.url }}" {{ child.target }}>
+								{% endfor %}
+								</ul>
+							{% endif %}
+							</a></li>
+						{% endif %}
+					{% endfor %}
+				</ul>
+				<img src="images/lib/ui/spinner.gif" id="spinner"/>
+				<ul class="nav pull-right">
+					<li id="login-topbar-item"><a href="login-page.html">Login</a></li>
+				</ul>
+			</div>
+			</div>
+			</div>	
+	</header>
+	<div id="body_div">
+		<div class="content" id="page-{{ name }}" style="display: block;">
+		{% block content %}
+		{% endblock %}
+		</div>
+	</div>
+	<footer><div class="web-footer">
+		<div class="web-footer-menu"><ul>
+		{% for item in footer_items %}
+			<li><a href="{{ item.url }}" {{ item.target }}
+				data-label="{{ item.label }}">{{ item.label }}</a></li>
+		{% endfor %}
+		</ul></div>
+		<div class="web-footer-copyright">&copy; {{ copyright }}
+		</div>
+	</footer>
+
+{% 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 0000000..0eccd87
--- /dev/null
+++ b/erpnext/website/templates/page.html
@@ -0,0 +1,32 @@
+{% extends "outer.html" %}
+
+{% block title %}{{ title }}{% endblock %}
+
+{% block header %}
+	{{ super() }}
+	{% if script %}
+	<script>
+	window.page_name = "{{ name }}";
+
+	$(document).bind('app_ready', function() {
+		var _page = new wn.views.Page(window.page_name);
+	
+		// page script
+		{{ script }}
+	
+		// trigger onload
+		_page.trigger('onload');
+	
+		// activate page
+		wn.container.change_to(window.page_name);
+	});
+	</script>
+	{% endif %}
+	{% if style %}
+	<style>{{ style }}</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 32a2e29..859af21 100644
--- a/public/js/all-app.js
+++ b/public/js/all-app.js
@@ -389,7 +389,7 @@
 /*
  *	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 381d5f8..1f70310 100644
--- a/public/js/all-web.js
+++ b/public/js/all-web.js
@@ -276,7 +276,7 @@
 /*
  *	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 0000000..d05eb94
--- /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')