diff --git a/webnotes/app.py b/webnotes/app.py index 98e02fd7a3..6d3233bfd3 100644 --- a/webnotes/app.py +++ b/webnotes/app.py @@ -26,7 +26,7 @@ def application(request): try: site = webnotes.utils.get_site_name(request.host) webnotes.init(site=site) - + webnotes.local.form_dict = webnotes._dict({ k:v[0] if isinstance(v, (list, tuple)) else v \ for k, v in (request.form or request.args).iteritems() }) diff --git a/webnotes/webutils.py b/webnotes/webutils.py index 205a3147ab..ccac9e02b4 100644 --- a/webnotes/webutils.py +++ b/webnotes/webutils.py @@ -19,8 +19,11 @@ def render(page_name): html = render_page("404") except Exception: html = render_page('error') - + webnotes._response.headers["Content-Type"] = "text/html; charset: utf-8" + if "content_type" in webnotes.response: + webnotes._response.headers["Content-Type"] = webnotes.response.pop("content_type") + webnotes._response.data = html def render_page(page_name): @@ -41,7 +44,7 @@ def render_page(page_name): if page_name=="error": html = html.replace("%(error)s", webnotes.getTraceback()) - else: + elif not webnotes.response.content_type: comments = "\npage:"+page_name+\ "\nload status: " + (from_cache and "cache" or "fresh") html += """\n""" % webnotes.utils.cstr(comments) @@ -118,6 +121,7 @@ def build_sitemap(): if p.get("controller"): module = webnotes.get_module(p["controller"]) p["no_cache"] = getattr(module, "no_cache", False) + p["no_sitemap"] = getattr(module, "no_sitemap", False) or p["no_cache"] # generators for g in config["generators"].values(): @@ -186,7 +190,7 @@ def build_website_sitemap_config(): for path, folders, files in os.walk(basepath, followlinks=True): if os.path.basename(path)=="pages" and os.path.basename(os.path.dirname(path))=="templates": for fname in files: - if fname.split(".")[-1] in ("html", "xml"): + if fname.split(".")[-1] in ("html", "xml", "js", "css"): options = get_options(path, fname) config["pages"][options.link_name] = options diff --git a/website/doctype/style_settings/style_settings.py b/website/doctype/style_settings/style_settings.py index d896f4a5ea..e6feb9bc8a 100644 --- a/website/doctype/style_settings/style_settings.py +++ b/website/doctype/style_settings/style_settings.py @@ -13,46 +13,8 @@ class DocType: def validate(self): """make custom css""" - from jinja2 import Template - from webnotes.webutils import get_hex_shade - import os - - default_colours = { - "background_color": "FFFFFF", - "page_background": "FFFFFF", - "top_bar_background": "FFFFFF", - "top_bar_foreground": "444444", - "page_headings": "222222", - "page_text": "000000" - } - - for d in default_colours: - if not self.doc.fields.get(d): - self.doc.fields[d] = default_colours[d] - self.validate_colors() - with open(os.path.join( - os.path.dirname(os.path.abspath(__file__)), - 'custom_template.css'), 'r') as f: - temp = Template(f.read()) - - self.prepare() - - self.doc.custom_css = temp.render(doc = self.doc, get_hex_shade=get_hex_shade) - if self.doc.add_css: - self.doc.custom_css += '\n\n/* User CSS */\n\n' + self.doc.add_css - - from webnotes.sessions import clear_cache - clear_cache('Guest') - - from webnotes.webutils import clear_cache - clear_cache() - - for f in ["small_font_size", "at_import", "heading_text_style"]: - if f in self.doc.fields: - del self.doc.fields[f] - def validate_colors(self): if (self.doc.page_background or self.doc.page_text) and \ self.doc.page_background==self.doc.page_text: @@ -63,36 +25,11 @@ class DocType: self.doc.top_bar_background==self.doc.top_bar_foreground: webnotes.msgprint(_("Top Bar text and background is same color. Please change."), raise_exception=1) - - - def prepare(self): - if not self.doc.font_size: - self.doc.font_size = '13px' - - self.doc.small_font_size = cstr(cint(self.doc.font_size[:-2])-2) + 'px' - self.doc.page_border = cint(self.doc.page_border) - - fonts = [] - if self.doc.google_web_font_for_heading: - fonts.append(self.doc.google_web_font_for_heading) - if self.doc.google_web_font_for_text: - fonts.append(self.doc.google_web_font_for_text) - - fonts = list(set(fonts)) - - if self.doc.heading_text_as: - self.doc.heading_text_style = { - "UPPERCASE": "uppercase", - "Title Case":"capitalize", - "lowercase": "lowercase" - }.get(self.doc.heading_text_as) or "" - - self.doc.at_import = "" - for f in fonts: - self.doc.at_import += "\n@import url(https://fonts.googleapis.com/css?family=%s:400,700);" % f.replace(" ", "+") - def on_update(self): - """rebuild pages""" - from website.doctype.website_settings.make_web_include_files import make - make() \ No newline at end of file + """clear cache""" + from webnotes.sessions import clear_cache + clear_cache('Guest') + + from webnotes.webutils import clear_cache + clear_cache() diff --git a/website/doctype/style_settings/templates/__init__.py b/website/doctype/style_settings/templates/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/website/doctype/style_settings/templates/pages/__init__.py b/website/doctype/style_settings/templates/pages/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/website/doctype/style_settings/custom_template.css b/website/doctype/style_settings/templates/pages/wn-web.css similarity index 98% rename from website/doctype/style_settings/custom_template.css rename to website/doctype/style_settings/templates/pages/wn-web.css index c306194afd..a8c49cd5cb 100644 --- a/website/doctype/style_settings/custom_template.css +++ b/website/doctype/style_settings/templates/pages/wn-web.css @@ -231,3 +231,8 @@ hr { border-top: 1px solid #{{ get_hex_shade(doc.page_background, 15) }}; border-bottom: 1px solid #{{ get_hex_shade(doc.page_background, 5) }}; } + +{% if doc.add_css -%} +/* User CSS */ +{{ doc.add_css }} +{%- endif %} \ No newline at end of file diff --git a/website/doctype/style_settings/templates/pages/wn_web.py b/website/doctype/style_settings/templates/pages/wn_web.py new file mode 100644 index 0000000000..d789140e7a --- /dev/null +++ b/website/doctype/style_settings/templates/pages/wn_web.py @@ -0,0 +1,62 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. +# MIT License. See license.txt + +from __future__ import unicode_literals +import webnotes +no_sitemap = True + +def get_context(): + """returns web style""" + from webnotes.webutils import get_hex_shade + + webnotes.response.content_type = "text/css" + + doc = webnotes.doc("Style Settings", "Style Settings") + prepare(doc) + + return { + "doc": doc, + "get_hex_shade": get_hex_shade + } + +def prepare(doc): + from webnotes.utils import cint, cstr + + # set default colours + default_colours = { + "background_color": "FFFFFF", + "page_background": "FFFFFF", + "top_bar_background": "FFFFFF", + "top_bar_foreground": "444444", + "page_headings": "222222", + "page_text": "000000" + } + + for d in default_colours: + if not doc.fields.get(d): + doc.fields[d] = default_colours[d] + + if not doc.font_size: + doc.font_size = "13px" + + doc.small_font_size = cstr(cint(doc.font_size[:-2])-2) + 'px' + doc.page_border = cint(doc.page_border) + + fonts = [] + if doc.google_web_font_for_heading: + fonts.append(doc.google_web_font_for_heading) + if doc.google_web_font_for_text: + fonts.append(doc.google_web_font_for_text) + + fonts = list(set(fonts)) + + if doc.heading_text_as: + doc.heading_text_style = { + "UPPERCASE": "uppercase", + "Title Case":"capitalize", + "lowercase": "lowercase" + }.get(doc.heading_text_as) or "" + + doc.at_import = "" + for f in fonts: + doc.at_import += "\n@import url(https://fonts.googleapis.com/css?family=%s:400,700);" % f.replace(" ", "+") \ No newline at end of file diff --git a/website/doctype/website_script/templates/__init__.py b/website/doctype/website_script/templates/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/website/doctype/website_script/templates/pages/__init__.py b/website/doctype/website_script/templates/pages/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/website/doctype/website_script/templates/pages/wn-web.js b/website/doctype/website_script/templates/pages/wn-web.js new file mode 100644 index 0000000000..5e382c3332 --- /dev/null +++ b/website/doctype/website_script/templates/pages/wn-web.js @@ -0,0 +1,14 @@ +{% if javascript -%}{{ javascript }}{%- endif %} + +{% if google_analytics_id -%} +// Google Analytics template +window._gaq = window._gaq || []; +window._gaq.push(['_setAccount', '{{ google_analytics_id }}']); +window._gaq.push(['_trackPageview']); + +(function() { + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); +})(); +{%- endif %} \ No newline at end of file diff --git a/website/doctype/website_script/templates/pages/wn_web.py b/website/doctype/website_script/templates/pages/wn_web.py new file mode 100644 index 0000000000..d2e70e723b --- /dev/null +++ b/website/doctype/website_script/templates/pages/wn_web.py @@ -0,0 +1,15 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. +# MIT License. See license.txt + +from __future__ import unicode_literals +import webnotes + +no_sitemap = True + +def get_context(): + """returns web startup script""" + webnotes.response.content_type = "application/javascript" + return { + "javascript": webnotes.conn.get_value('Website Script', None, 'javascript'), + "google_analytics_id": webnotes.conn.get_value("Website Settings", "Website Settings", "google_analytics_id") + } \ No newline at end of file diff --git a/website/doctype/website_script/website_script.py b/website/doctype/website_script/website_script.py index 9f5c6eada7..b93495152f 100644 --- a/website/doctype/website_script/website_script.py +++ b/website/doctype/website_script/website_script.py @@ -11,6 +11,9 @@ class DocType: self.doc, self.doclist = d, dl def on_update(self): - # make js and css - from website.doctype.website_settings.make_web_include_files import make - make() \ No newline at end of file + """clear cache""" + from webnotes.sessions import clear_cache + clear_cache('Guest') + + from webnotes.webutils import clear_cache + clear_cache() \ No newline at end of file diff --git a/website/doctype/website_settings/make_web_include_files.py b/website/doctype/website_settings/make_web_include_files.py deleted file mode 100644 index f20dd812a6..0000000000 --- a/website/doctype/website_settings/make_web_include_files.py +++ /dev/null @@ -1,58 +0,0 @@ -# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. -# MIT License. See license.txt - -import os -import webnotes - -def make(): - from webnotes.webutils import get_home_page - from webnotes.utils import get_path - - if not webnotes.conn: - webnotes.connect() - - home_page = get_home_page() - - if not os.path.exists(get_path("public", "js")): - os.makedirs(get_path("public", "js")) - fname = os.path.join(get_path("public", "js", "wn-web.js")) - with open(fname, 'w') as f: - f.write(get_web_script()) - - if not os.path.exists(get_path("public", "css")): - os.makedirs(get_path("public", "css")) - fname = os.path.join(get_path("public", "css", "wn-web.css")) - with open(fname, 'w') as f: - f.write(get_web_style()) - -def get_web_script(): - """returns web startup script""" - user_script = "" - - ws = webnotes.doc("Website Settings", "Website Settings") - - if ws.google_analytics_id: - user_script += google_analytics_template % ws.google_analytics_id - - user_script += (webnotes.conn.get_value('Website Script', None, 'javascript') or '') - - return user_script - -def get_web_style(): - """returns web css""" - return webnotes.conn.get_value('Style Settings', None, 'custom_css') or '' - -google_analytics_template = """ - -// Google Analytics template - -window._gaq = window._gaq || []; -window._gaq.push(['_setAccount', '%s']); -window._gaq.push(['_trackPageview']); - -(function() { - var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; - ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; - var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); -})(); -""" \ No newline at end of file diff --git a/website/doctype/website_settings/website_settings.py b/website/doctype/website_settings/website_settings.py index b553a56690..fa9557a3fd 100644 --- a/website/doctype/website_settings/website_settings.py +++ b/website/doctype/website_settings/website_settings.py @@ -58,9 +58,6 @@ class DocType: def on_update(self): # make js and css - from website.doctype.website_settings.make_web_include_files import make - make() - # clear web cache (for menus!) from webnotes.webutils import clear_cache clear_cache() diff --git a/website/sitemap.py b/website/sitemap.py deleted file mode 100644 index d1b9267977..0000000000 --- a/website/sitemap.py +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. -# MIT License. See license.txt - -from __future__ import unicode_literals -import urllib -import webnotes -import webnotes.webutils -from webnotes.utils import nowdate - -def generate(domain): - """generate the sitemap XML""" - - frame_xml = """ - %s - """ - - link_xml = """\n%s%s""" - - site_map = "" - if domain: - today = nowdate() - - for page_name, page_options in webnotes.webutils.get_website_sitemap().items(): - if page_options.get("no_cache"): - continue - - url = urllib.basejoin(domain, urllib.quote(page_name.encode("utf-8"))) - site_map += link_xml % (url, today) - - return frame_xml % site_map diff --git a/website/templates/base.html b/website/templates/base.html index 1b727b3df1..0e28af2e2b 100644 --- a/website/templates/base.html +++ b/website/templates/base.html @@ -7,9 +7,9 @@ - + - + {% block head %}{% endblock %} diff --git a/website/templates/pages/rss.py b/website/templates/pages/rss.py index 586566ac5b..133861861e 100644 --- a/website/templates/pages/rss.py +++ b/website/templates/pages/rss.py @@ -1,6 +1,6 @@ import webnotes import os, urllib -from webnotes.utils import escape_html, get_request_site_address +from webnotes.utils import escape_html, get_request_site_address, now no_cache = True @@ -17,8 +17,11 @@ def get_context(): for blog in blog_list: blog.link = urllib.quote(host + '/' + blog.name + '.html') blog.content = escape_html(blog.content or "") - - modified = max((blog['modified'] for blog in blog_list)) + + if blog_list: + modified = max((blog['modified'] for blog in blog_list)) + else: + modified = now() ws = webnotes.doc('Website Settings', 'Website Settings') @@ -30,6 +33,8 @@ def get_context(): 'link': host + '/blog' } - print context + webnotes.response.content_type = "text/xml" + + # print context return context \ No newline at end of file diff --git a/website/templates/pages/sitemap.py b/website/templates/pages/sitemap.py index 99dbf1734e..267b2bea8b 100644 --- a/website/templates/pages/sitemap.py +++ b/website/templates/pages/sitemap.py @@ -14,9 +14,11 @@ def get_context(): host = get_request_site_address() for l in links: - l[1]["loc"] = urllib.basejoin(host, urllib.quote(l[1].get("page_name", l[1]["link_name"]))) + l[1]["loc"] = urllib.basejoin(host, urllib.quote(l[1].get("page_name", l[1]["link_name"]).encode("utf-8"))) + + webnotes.response.content_type = "text/xml" return { - "links": [l[1] for l in links] + "links": [l[1] for l in links if not l[1].get("no_sitemap")] } \ No newline at end of file diff --git a/wnf.py b/wnf.py index f453af08c9..065112f448 100755 --- a/wnf.py +++ b/wnf.py @@ -133,6 +133,8 @@ def setup_git(parser): help="Run git push for both repositories") parser.add_argument("--status", default=False, action="store_true", help="Run git status for both repositories") + parser.add_argument("--commit", nargs=1, metavar="COMMIT-MSG", + help="Run git commit COMMIT-MSG for both repositories") parser.add_argument("--checkout", nargs=1, metavar="BRANCH", help="Run git checkout BRANCH for both repositories") parser.add_argument("--git", nargs="*", metavar="OPTIONS", @@ -344,8 +346,8 @@ def git(opts, args=None): if isinstance(opts, (list, tuple)): cmd = " ".join(opts) import os - os.system("cd lib && git %s" % cmd) - os.system("cd app && git %s" % cmd) + os.system("""cd lib && git %s""" % cmd) + os.system("""cd app && git %s""" % cmd) def pull(opts, args=None): if not opts: @@ -362,6 +364,9 @@ def push(opts, args=None): def status(opts, args=None): git("status") +def commit(opts, args=None): + git("""commit -m "%s" """ % opts[0].replace('"', '\"')) + def checkout(opts, args=None): git(("checkout", opts[0]))