[minor] moved wn-web.js and wn-web.css to memcache
This commit is contained in:
parent
b4be1cf18e
commit
627c1f9bd2
19 changed files with 138 additions and 177 deletions
|
|
@ -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() })
|
||||
|
||||
|
|
|
|||
|
|
@ -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<!-- %s -->""" % 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
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
"""clear cache"""
|
||||
from webnotes.sessions import clear_cache
|
||||
clear_cache('Guest')
|
||||
|
||||
from webnotes.webutils import clear_cache
|
||||
clear_cache()
|
||||
|
|
|
|||
0
website/doctype/style_settings/templates/__init__.py
Normal file
0
website/doctype/style_settings/templates/__init__.py
Normal file
|
|
@ -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 %}
|
||||
62
website/doctype/style_settings/templates/pages/wn_web.py
Normal file
62
website/doctype/style_settings/templates/pages/wn_web.py
Normal file
|
|
@ -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(" ", "+")
|
||||
0
website/doctype/website_script/templates/__init__.py
Normal file
0
website/doctype/website_script/templates/__init__.py
Normal file
14
website/doctype/website_script/templates/pages/wn-web.js
Normal file
14
website/doctype/website_script/templates/pages/wn-web.js
Normal file
|
|
@ -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 %}
|
||||
15
website/doctype/website_script/templates/pages/wn_web.py
Normal file
15
website/doctype/website_script/templates/pages/wn_web.py
Normal file
|
|
@ -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")
|
||||
}
|
||||
|
|
@ -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()
|
||||
"""clear cache"""
|
||||
from webnotes.sessions import clear_cache
|
||||
clear_cache('Guest')
|
||||
|
||||
from webnotes.webutils import clear_cache
|
||||
clear_cache()
|
||||
|
|
@ -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);
|
||||
})();
|
||||
"""
|
||||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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 = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">%s
|
||||
</urlset>"""
|
||||
|
||||
link_xml = """\n<url><loc>%s</loc><lastmod>%s</lastmod></url>"""
|
||||
|
||||
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
|
||||
|
|
@ -7,9 +7,9 @@
|
|||
<meta name="generator" content="wnframework">
|
||||
<script type="text/javascript" src="lib/js/lib/jquery/jquery.min.js"></script>
|
||||
<script type="text/javascript" src="js/all-web.min.js"></script>
|
||||
<script type="text/javascript" src="js/wn-web.js"></script>
|
||||
<script type="text/javascript" src="wn-web.js"></script>
|
||||
<link type="text/css" rel="stylesheet" href="css/all-web.css">
|
||||
<link type="text/css" rel="stylesheet" href="css/wn-web.css">
|
||||
<link type="text/css" rel="stylesheet" href="wn-web.css">
|
||||
<link rel="shortcut icon" href="{{ favicon }}" type="image/x-icon">
|
||||
<link rel="icon" href="{{ favicon }}" type="image/x-icon">
|
||||
{% block head %}{% endblock %}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
@ -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")]
|
||||
}
|
||||
|
||||
9
wnf.py
9
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]))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue