web pages don't render into Page and Page does not get written as HTML. Welcome Jinja2 Templates
This commit is contained in:
parent
cc53afcef3
commit
96bf0b7f53
@ -8,21 +8,11 @@
|
|||||||
<div class="layout-main">
|
<div class="layout-main">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ doc.main_section_html }}
|
{{ doc.main_section_html }}
|
||||||
{% if doc.next_page_html %}
|
|
||||||
{{ doc.next_page_html }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if doc.layout and doc.layout.startswith('Two column') %}
|
{% if doc.layout and doc.layout.startswith('Two column') %}
|
||||||
<div class="layout-side-section">
|
<div class="layout-side-section">
|
||||||
{{ doc.side_section_html }}
|
{{ doc.side_section_html }}
|
||||||
{% if doc.see_also %}
|
|
||||||
<div class="info-box">
|
|
||||||
<h4>See Also</h4>
|
|
||||||
{{ doc.see_also }}
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div style="clear: both"></div>
|
<div style="clear: both"></div>
|
||||||
|
|||||||
@ -28,60 +28,29 @@ class DocType:
|
|||||||
def validate(self):
|
def validate(self):
|
||||||
"""make page for this product"""
|
"""make page for this product"""
|
||||||
from jinja2 import Template
|
from jinja2 import Template
|
||||||
from webnotes.utils import global_date_format
|
|
||||||
from webnotes.model.code import get_obj
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
# we need the name for the templates
|
# we need the name for the templates
|
||||||
if self.doc.name.startswith('New Web Page'):
|
if self.doc.name.startswith('New Web Page'):
|
||||||
self.autoname()
|
self.autoname()
|
||||||
|
|
||||||
if self.doc.page_name:
|
# page name updates with the title
|
||||||
webnotes.conn.sql("""delete from tabPage where name=%s""", self.doc.page_name)
|
self.doc.page_name = website.utils.page_name(self.doc.title)
|
||||||
|
|
||||||
p = website.utils.add_page(self.doc.name)
|
# markdown
|
||||||
self.doc.page_name = p.name
|
|
||||||
|
|
||||||
self.doc.updated = global_date_format(self.doc.modified)
|
|
||||||
website.utils.markdown(self.doc, ['head_section','main_section', 'side_section'])
|
website.utils.markdown(self.doc, ['head_section','main_section', 'side_section'])
|
||||||
|
|
||||||
|
# make page layout
|
||||||
with open(os.path.join(os.path.dirname(__file__), 'template.html'), 'r') as f:
|
with open(os.path.join(os.path.dirname(__file__), 'template.html'), 'r') as f:
|
||||||
p.content = Template(f.read()).render(doc=self.doc)
|
self.doc.content = Template(f.read()).render(doc=self.doc)
|
||||||
|
|
||||||
p.title = self.doc.title
|
|
||||||
p.web_page = 'Yes'
|
|
||||||
|
|
||||||
if self.doc.insert_code:
|
|
||||||
p.script = self.doc.javascript
|
|
||||||
|
|
||||||
if self.doc.insert_style:
|
|
||||||
p.style = self.doc.css
|
|
||||||
|
|
||||||
p.save()
|
|
||||||
get_obj(doc=p).write_cms_page()
|
|
||||||
|
|
||||||
website.utils.add_guest_access_to_page(p.name)
|
|
||||||
self.cleanup_temp()
|
self.cleanup_temp()
|
||||||
self.if_home_clear_cache()
|
self.if_home_clear_cache()
|
||||||
|
|
||||||
def add_page_links(self):
|
|
||||||
"""add links for next_page and see_also"""
|
|
||||||
if self.doc.next_page:
|
|
||||||
self.doc.next_page_html = """<div class="info-box round" style="text-align: right">
|
|
||||||
<b>Next:</b>
|
|
||||||
<a href="#!%(name)s">%(title)s</a></div>""" % {"name":self.doc.next_page, \
|
|
||||||
"title": webnotes.conn.get_value("Page", self.doc.next_page, "title")}
|
|
||||||
|
|
||||||
self.doc.see_also = ''
|
|
||||||
for d in self.doclist:
|
|
||||||
if d.doctype=='Related Page':
|
|
||||||
tmp = {"page":d.page, "title":webnotes.conn.get_value('Page', d.page, 'title')}
|
|
||||||
self.doc.see_also += """<div><a href="#!%(page)s">%(title)s</a></div>""" % tmp
|
|
||||||
|
|
||||||
def cleanup_temp(self):
|
def cleanup_temp(self):
|
||||||
"""cleanup temp fields"""
|
"""cleanup temp fields"""
|
||||||
fl = ['main_section_html', 'side_section_html', 'see_also', \
|
fl = ['main_section_html', 'side_section_html', \
|
||||||
'next_page_html', 'head_section_html', 'updated']
|
'head_section_html']
|
||||||
for f in fl:
|
for f in fl:
|
||||||
if f in self.doc.fields:
|
if f in self.doc.fields:
|
||||||
del self.doc.fields[f]
|
del self.doc.fields[f]
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
{
|
{
|
||||||
'creation': '2012-04-02 16:02:43',
|
'creation': '2012-04-02 16:02:43',
|
||||||
'docstatus': 0,
|
'docstatus': 0,
|
||||||
'modified': '2012-05-02 15:24:31',
|
'modified': '2012-06-15 17:18:59',
|
||||||
'modified_by': u'Administrator',
|
'modified_by': u'Administrator',
|
||||||
'owner': u'Administrator'
|
'owner': u'Administrator'
|
||||||
},
|
},
|
||||||
@ -86,6 +86,17 @@
|
|||||||
'reqd': 1
|
'reqd': 1
|
||||||
},
|
},
|
||||||
|
|
||||||
|
# DocField
|
||||||
|
{
|
||||||
|
'colour': u'White:FFF',
|
||||||
|
'description': u'Page url name (auto-generated) ',
|
||||||
|
'doctype': u'DocField',
|
||||||
|
'fieldname': u'page_name',
|
||||||
|
'fieldtype': u'Data',
|
||||||
|
'label': u'Page Name',
|
||||||
|
'permlevel': 1
|
||||||
|
},
|
||||||
|
|
||||||
# DocField
|
# DocField
|
||||||
{
|
{
|
||||||
'doctype': u'DocField',
|
'doctype': u'DocField',
|
||||||
@ -101,7 +112,7 @@
|
|||||||
'fieldname': u'layout',
|
'fieldname': u'layout',
|
||||||
'fieldtype': u'Select',
|
'fieldtype': u'Select',
|
||||||
'label': u'Layout',
|
'label': u'Layout',
|
||||||
'options': u'Two column with header\nTwo column\nSingle column',
|
'options': u'Single column\nTwo column\nTwo column with header',
|
||||||
'permlevel': 0
|
'permlevel': 0
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -152,6 +163,17 @@
|
|||||||
'permlevel': 0
|
'permlevel': 0
|
||||||
},
|
},
|
||||||
|
|
||||||
|
# DocField
|
||||||
|
{
|
||||||
|
'colour': u'White:FFF',
|
||||||
|
'doctype': u'DocField',
|
||||||
|
'fieldname': u'content',
|
||||||
|
'fieldtype': u'Code',
|
||||||
|
'hidden': 1,
|
||||||
|
'label': u'Content',
|
||||||
|
'permlevel': 0
|
||||||
|
},
|
||||||
|
|
||||||
# DocField
|
# DocField
|
||||||
{
|
{
|
||||||
'colour': u'White:FFF',
|
'colour': u'White:FFF',
|
||||||
@ -176,6 +198,7 @@
|
|||||||
# DocField
|
# DocField
|
||||||
{
|
{
|
||||||
'colour': u'White:FFF',
|
'colour': u'White:FFF',
|
||||||
|
'description': u'Add code as <script>',
|
||||||
'doctype': u'DocField',
|
'doctype': u'DocField',
|
||||||
'fieldname': u'insert_code',
|
'fieldname': u'insert_code',
|
||||||
'fieldtype': u'Check',
|
'fieldtype': u'Check',
|
||||||
@ -212,15 +235,6 @@
|
|||||||
'permlevel': 0
|
'permlevel': 0
|
||||||
},
|
},
|
||||||
|
|
||||||
# DocField
|
|
||||||
{
|
|
||||||
'doctype': u'DocField',
|
|
||||||
'fieldname': u'page_name',
|
|
||||||
'fieldtype': u'Data',
|
|
||||||
'label': u'Page Name',
|
|
||||||
'permlevel': 1
|
|
||||||
},
|
|
||||||
|
|
||||||
# DocField
|
# DocField
|
||||||
{
|
{
|
||||||
'doctype': u'DocField',
|
'doctype': u'DocField',
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
{% block header %}
|
{% block header %}
|
||||||
{{ super() }}
|
{{ super() }}
|
||||||
{% if script %}
|
{% if insert_code %}
|
||||||
<script>
|
<script>
|
||||||
window.page_name = "{{ name }}";
|
window.page_name = "{{ name }}";
|
||||||
|
|
||||||
@ -12,7 +12,7 @@
|
|||||||
var _page = new wn.views.Page(window.page_name);
|
var _page = new wn.views.Page(window.page_name);
|
||||||
|
|
||||||
// page script
|
// page script
|
||||||
{{ script }}
|
{{ insert_code }}
|
||||||
|
|
||||||
// trigger onload
|
// trigger onload
|
||||||
_page.trigger('onload');
|
_page.trigger('onload');
|
||||||
@ -22,8 +22,8 @@
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if style %}
|
{% if insert_style %}
|
||||||
<style>{{ style }}</style>
|
<style>{{ insert_style }}</style>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
return a dynamic page from website templates
|
return a dynamic page from website templates
|
||||||
|
|
||||||
|
all html pages except login-page.html get generated here
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import cgi, cgitb, os, sys
|
import cgi, cgitb, os, sys
|
||||||
@ -29,6 +31,11 @@ def get_outer_env():
|
|||||||
'copyright': webnotes.conn.get_value('Website Settings', None, 'copyright'),
|
'copyright': webnotes.conn.get_value('Website Settings', None, 'copyright'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def get_page_by_short_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():
|
def get_html():
|
||||||
import webnotes
|
import webnotes
|
||||||
from jinja2 import Environment, FileSystemLoader
|
from jinja2 import Environment, FileSystemLoader
|
||||||
@ -42,12 +49,17 @@ def get_html():
|
|||||||
webnotes.connect()
|
webnotes.connect()
|
||||||
|
|
||||||
if 'page' in webnotes.form_dict:
|
if 'page' in webnotes.form_dict:
|
||||||
try:
|
page_name = webnotes.form_dict['page']
|
||||||
page = Document('Page', webnotes.form_dict['page'])
|
if page_name.endswith('.html'):
|
||||||
|
page_name = page_name[:-5]
|
||||||
|
|
||||||
|
#try:
|
||||||
|
page_name = get_page_by_short_name(page_name)
|
||||||
|
page = Document('Web Page', page_name)
|
||||||
page.fields.update(get_outer_env())
|
page.fields.update(get_outer_env())
|
||||||
return jenv.get_template('page.html').render(page.fields)
|
return jenv.get_template('page.html').render(page.fields)
|
||||||
except Exception, e:
|
#except Exception, e:
|
||||||
return jenv.get_template('404.html').render(get_outer_env())
|
# return jenv.get_template('404.html').render(get_outer_env())
|
||||||
else:
|
else:
|
||||||
return jenv.get_template('404.html').render(get_outer_env())
|
return jenv.get_template('404.html').render(get_outer_env())
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user