updates in web.py and template - page.html
This commit is contained in:
parent
40182bada3
commit
5d9fc72753
@ -12,7 +12,7 @@
|
||||
var _page = new wn.views.Page(window.page_name);
|
||||
|
||||
// page script
|
||||
{{ insert_code }}
|
||||
{{ javascript }}
|
||||
|
||||
// trigger onload
|
||||
_page.trigger('onload');
|
||||
@ -23,7 +23,7 @@
|
||||
</script>
|
||||
{% endif %}
|
||||
{% if insert_style %}
|
||||
<style>{{ insert_style }}</style>
|
||||
<style>{{ css }}</style>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
|
@ -15,11 +15,49 @@ import conf
|
||||
sys.path.append('../lib/py')
|
||||
sys.path.append(conf.modules_path)
|
||||
|
||||
def init():
|
||||
import webnotes
|
||||
webnotes.form = cgi.FieldStorage(keep_blank_values=True)
|
||||
for key in webnotes.form.keys():
|
||||
webnotes.form_dict[key] = webnotes.form.getvalue(key)
|
||||
webnotes.connect()
|
||||
|
||||
def respond():
|
||||
html = get_html()
|
||||
print "Content-Type: text/html"
|
||||
print
|
||||
print html.encode('utf-8')
|
||||
|
||||
def get_html():
|
||||
import webnotes
|
||||
from webnotes.model.doc import Document
|
||||
# Get web page
|
||||
outer_env_dict = get_outer_env()
|
||||
try:
|
||||
if 'page' in webnotes.form_dict:
|
||||
page_name = webnotes.form_dict['page']
|
||||
if page_name.endswith('.html'):
|
||||
page_name = page_name[:-5]
|
||||
|
||||
if page_name.startswith('blog'):
|
||||
raise Exception
|
||||
#page_name =
|
||||
else:
|
||||
page_name = get_web_page_name(page_name)
|
||||
else:
|
||||
from webnotes.cms import get_home_page
|
||||
page_name = get_home_page('Guest')
|
||||
|
||||
page = Document('Web Page', page_name)
|
||||
page.fields.update(outer_env_dict)
|
||||
|
||||
return build_html(page.fields, "page: %s" % page_name)
|
||||
|
||||
except Exception, e:
|
||||
return build_html(outer_env_dict, "error: %s" % webnotes.getTraceback(), '404.html')
|
||||
|
||||
def get_outer_env():
|
||||
"""env for outer (cache this)"""
|
||||
|
||||
# TODO: Cache this in cache item
|
||||
|
||||
"""env dict for outer template"""
|
||||
import webnotes
|
||||
return {
|
||||
'top_bar_items': webnotes.conn.sql("""select * from `tabTop Bar Item`
|
||||
@ -34,49 +72,22 @@ def get_outer_env():
|
||||
'copyright': webnotes.conn.get_value('Website Settings', None, 'copyright'),
|
||||
}
|
||||
|
||||
def build_html(args, comments, template='page.html'):
|
||||
"""build html using jinja2 templates"""
|
||||
from webnotes.utils import cstr
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
jenv = Environment(loader = FileSystemLoader('../erpnext/website/templates'))
|
||||
|
||||
html = jenv.get_template(template).render(args)
|
||||
html += "\n<!-- %s -->" % cstr(comments)
|
||||
return html
|
||||
|
||||
def get_web_page_name(page_name):
|
||||
"""get page by shortname"""
|
||||
import webnotes
|
||||
return webnotes.conn.sql("""select name from `tabWeb Page` where page_name=%s""", page_name)[0][0]
|
||||
|
||||
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()
|
||||
|
||||
# Get web page
|
||||
try:
|
||||
if 'page' in webnotes.form_dict:
|
||||
page_name = webnotes.form_dict['page']
|
||||
if page_name.endswith('.html'):
|
||||
page_name = page_name[:-5]
|
||||
|
||||
if page_name.startswith('blog'):
|
||||
pass
|
||||
# page_name =
|
||||
else:
|
||||
page_name = get_web_page_name(page_name)
|
||||
else:
|
||||
from webnotes.cms import get_home_page
|
||||
page_name = get_home_page('Guest')
|
||||
|
||||
page = Document('Web Page', page_name)
|
||||
page.fields.update(get_outer_env())
|
||||
return jenv.get_template('page.html').render(page.fields) + \
|
||||
('\n<!-- page: %s -->' % page_name)
|
||||
|
||||
except Exception, e:
|
||||
return jenv.get_template('404.html').render(get_outer_env()) + \
|
||||
('\n<!-- error: %s -->' % webnotes.getTraceback())
|
||||
|
||||
if __name__=="__main__":
|
||||
print "Content-Type: text/html"
|
||||
print
|
||||
print get_html().encode('utf-8')
|
||||
init()
|
||||
respond()
|
||||
|
Loading…
Reference in New Issue
Block a user