Rushabh Mehta | 3966f1d | 2012-02-23 12:35:32 +0530 | [diff] [blame] | 1 | # 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 Mehta | ab1148c | 2012-01-31 18:01:16 +0530 | [diff] [blame] | 17 | import webnotes |
| 18 | from webnotes.model.doc import Document |
| 19 | |
Rushabh Mehta | 949496c | 2012-01-25 18:48:46 +0530 | [diff] [blame] | 20 | def make_template(doc, path, convert_fields = ['main_section', 'side_section']): |
| 21 | """make template""" |
Rushabh Mehta | ab1148c | 2012-01-31 18:01:16 +0530 | [diff] [blame] | 22 | import os, jinja2 |
Rushabh Mehta | 949496c | 2012-01-25 18:48:46 +0530 | [diff] [blame] | 23 | |
Rushabh Mehta | ab1148c | 2012-01-31 18:01:16 +0530 | [diff] [blame] | 24 | markdown(doc, convert_fields) |
Rushabh Mehta | 949496c | 2012-01-25 18:48:46 +0530 | [diff] [blame] | 25 | |
| 26 | # write template |
| 27 | with open(path, 'r') as f: |
| 28 | temp = jinja2.Template(f.read()) |
| 29 | |
Rushabh Mehta | ab1148c | 2012-01-31 18:01:16 +0530 | [diff] [blame] | 30 | return temp.render(doc = doc.fields) |
| 31 | |
Rushabh Mehta | ab1148c | 2012-01-31 18:01:16 +0530 | [diff] [blame] | 32 | def page_name(title): |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 33 | """make page name from title""" |
| 34 | import re |
| 35 | name = title.lower() |
| 36 | name = re.sub('[~!@#$%^&*()<>,."\']', '', name) |
| 37 | return '-'.join(name.split()[:4]) |
Rushabh Mehta | a920943 | 2012-05-07 18:00:57 +0530 | [diff] [blame] | 38 | |
Rushabh Mehta | 458ca8e | 2012-05-09 10:17:08 +0530 | [diff] [blame] | 39 | def get_header(page_name): |
Rushabh Mehta | a920943 | 2012-05-07 18:00:57 +0530 | [diff] [blame] | 40 | """get page header""" |
| 41 | |
| 42 | from webnotes.model.doc import Document |
| 43 | from jinja2 import Template |
Nabin Hait | a15740a | 2012-05-10 12:56:40 +0530 | [diff] [blame] | 44 | import webnotes.utils |
Rushabh Mehta | a920943 | 2012-05-07 18:00:57 +0530 | [diff] [blame] | 45 | |
| 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 Mehta | ceb2ab3 | 2012-05-21 15:56:50 +0200 | [diff] [blame] | 58 | pi = get_item(top_bar_items, t['parent_label']) |
| 59 | if 'child_items' not in pi: |
Rushabh Mehta | a920943 | 2012-05-07 18:00:57 +0530 | [diff] [blame] | 60 | 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 Mehta | a933b63 | 2012-05-08 16:06:44 +0530 | [diff] [blame] | 68 | <a class="brand" href="index.html">{{ brand }}</a> |
Rushabh Mehta | a920943 | 2012-05-07 18:00:57 +0530 | [diff] [blame] | 69 | <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 Mehta | 5ab8163 | 2012-05-08 12:58:32 +0530 | [diff] [blame] | 89 | <li id="login-topbar-item"><a href="login-page.html">Login</a></li> |
Rushabh Mehta | a920943 | 2012-05-07 18:00:57 +0530 | [diff] [blame] | 90 | </ul> |
| 91 | </div> |
| 92 | </div> |
| 93 | </div>""").render(top_bar_items = top_bar_items, |
Nabin Hait | a15740a | 2012-05-10 12:56:40 +0530 | [diff] [blame] | 94 | brand=website_settings.brand_html or webnotes.utils.get_defaults('company') or 'ERPNext') |
Rushabh Mehta | a920943 | 2012-05-07 18:00:57 +0530 | [diff] [blame] | 95 | |
Rushabh Mehta | 458ca8e | 2012-05-09 10:17:08 +0530 | [diff] [blame] | 96 | def get_footer(page_name): |
Rushabh Mehta | a920943 | 2012-05-07 18:00:57 +0530 | [diff] [blame] | 97 | """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">© {{ copyright }} |
Anand Doshi | 72c945b | 2012-06-22 20:01:07 +0530 | [diff] [blame] | 116 | </div>""").render(website_settings.fields) |