blob: 06bb60d94b405bf6996dcd881fcbc4b28521a5ee [file] [log] [blame]
Rushabh Mehta3966f1d2012-02-23 12:35:32 +05301# ERPNext - web based ERP (http://erpnext.com)
2# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053017import webnotes
18from webnotes.model.doc import Document
19
Rushabh Mehta949496c2012-01-25 18:48:46 +053020def make_template(doc, path, convert_fields = ['main_section', 'side_section']):
21 """make template"""
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053022 import os, jinja2
Rushabh Mehta949496c2012-01-25 18:48:46 +053023
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053024 markdown(doc, convert_fields)
Rushabh Mehta949496c2012-01-25 18:48:46 +053025
26 # write template
27 with open(path, 'r') as f:
28 temp = jinja2.Template(f.read())
29
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053030 return temp.render(doc = doc.fields)
31
Rushabh Mehtaab1148c2012-01-31 18:01:16 +053032def page_name(title):
Anand Doshi72c945b2012-06-22 20:01:07 +053033 """make page name from title"""
34 import re
35 name = title.lower()
36 name = re.sub('[~!@#$%^&*()<>,."\']', '', name)
37 return '-'.join(name.split()[:4])
Rushabh Mehtaa9209432012-05-07 18:00:57 +053038
Rushabh Mehta458ca8e2012-05-09 10:17:08 +053039def get_header(page_name):
Rushabh Mehtaa9209432012-05-07 18:00:57 +053040 """get page header"""
41
42 from webnotes.model.doc import Document
43 from jinja2 import Template
Nabin Haita15740a2012-05-10 12:56:40 +053044 import webnotes.utils
Rushabh Mehtaa9209432012-05-07 18:00:57 +053045
46 def get_item(l, label):
47 for i in l:
48 if i['label']==label:
49 return i
50
51 top_bar_items = webnotes.conn.sql("""select * from `tabTop Bar Item`
52 where parent='Website Settings' and parentfield='top_bar_items'
53 order by idx asc""", as_dict=1)
54
55 # build child items
56 for t in top_bar_items:
57 if t.get('parent_label'):
Rushabh Mehtaceb2ab32012-05-21 15:56:50 +020058 pi = get_item(top_bar_items, t['parent_label'])
59 if 'child_items' not in pi:
Rushabh Mehtaa9209432012-05-07 18:00:57 +053060 pi['child_items'] = []
61 pi['child_items'].append(t)
62
63 website_settings = Document('Website Settings', 'Website Settings')
64
65 return Template("""<div class="navbar navbar-fixed-top">
66 <div class="navbar-inner">
67 <div class="container">
Rushabh Mehtaa933b632012-05-08 16:06:44 +053068 <a class="brand" href="index.html">{{ brand }}</a>
Rushabh Mehtaa9209432012-05-07 18:00:57 +053069 <ul class="nav">
70 {% for page in top_bar_items %}
71 {% if not page.parent_label %}
72 <li data-label="{{ page.label }}">
73 <a href="{{ page.url }}" {{ page.target }}>
74 {{ page.label }}
75 {% if page.child_items %}
76 <ul class="dropdown-menu">
77 {% for child in page.child_items %}
78 <li data-label="{{ child.label }}">
79 <a href="{{ child.url }}" {{ child.target }}>
80 {% endfor %}
81 </ul>
82 {% endif %}
83 </a></li>
84 {% endif %}
85 {% endfor %}
86 </ul>
87 <img src="images/lib/ui/spinner.gif" id="spinner"/>
88 <ul class="nav pull-right">
Rushabh Mehta5ab81632012-05-08 12:58:32 +053089 <li id="login-topbar-item"><a href="login-page.html">Login</a></li>
Rushabh Mehtaa9209432012-05-07 18:00:57 +053090 </ul>
91 </div>
92 </div>
93 </div>""").render(top_bar_items = top_bar_items,
Nabin Haita15740a2012-05-10 12:56:40 +053094 brand=website_settings.brand_html or webnotes.utils.get_defaults('company') or 'ERPNext')
Rushabh Mehtaa9209432012-05-07 18:00:57 +053095
Rushabh Mehta458ca8e2012-05-09 10:17:08 +053096def get_footer(page_name):
Rushabh Mehtaa9209432012-05-07 18:00:57 +053097 """get page footer"""
98
99 from webnotes.model.doc import Document
100 from jinja2 import Template
101
102 website_settings = Document('Website Settings', 'Website Settings')
103
104 website_settings.footer_items = webnotes.conn.sql("""select * from `tabTop Bar Item`
105 where parent='Website Settings' and parentfield='footer_items'
106 order by idx asc""", as_dict=1)
107
108 return Template("""<div class="web-footer">
109 <div class="web-footer-menu"><ul>
110 {% for item in footer_items %}
111 <li><a href="{{ item.url }}" {{ item.target }}
112 data-label="{{ item.label }}">{{ item.label }}</a></li>
113 {% endfor %}
114 </ul></div>
115 <div class="web-footer-copyright">&copy; {{ copyright }}
Anand Doshi72c945b2012-06-22 20:01:07 +0530116 </div>""").render(website_settings.fields)