cms now powered by jinja2

This commit is contained in:
Rushabh Mehta 2012-06-15 14:00:06 +05:30
parent 4c56275d26
commit bd7f7231f2
10 changed files with 233 additions and 2 deletions

View File

@ -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 %}

View File

View File

@ -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>

View File

@ -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>

View File

@ -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 %}

View File

@ -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 %}

View File

@ -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;}

View File

@ -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;}

57
public/web.py Executable file
View File

@ -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')