@@ -15,7 +15,6 @@ | |||
} | |||
</script> | |||
<script type="text/javascript" src="js/all-app.js"></script> | |||
<script>window._version_number = "{{ version }}"; window.app = true;</script> | |||
<link type="text/css" rel="stylesheet" href="css/all-app.css"> | |||
</head> | |||
<body> | |||
@@ -23,4 +22,4 @@ | |||
<div id="body_div"> | |||
</div> | |||
<footer></footer> | |||
</body> | |||
</body> |
@@ -15,9 +15,7 @@ wn.provide('wn.settings');wn.provide('wn.ui'); | |||
/* | |||
* lib/js/wn/versions.js | |||
*/ | |||
wn.versions={check:function(){if(window.localStorage){if(window._version_number==-1||parseInt(localStorage._version_number)!=parseInt(window._version_number)){var localversion=localStorage._version_number;localStorage.clear();console.log("Cache cleared - version: "+localversion | |||
+' to '+_version_number)} | |||
localStorage.setItem('_version_number',window._version_number);}}} | |||
wn.versions={check:function(){if(window.localStorage){var localversion=localStorage._version_number;localStorage.clear();}}} | |||
/* | |||
* lib/js/wn/assets.js | |||
*/ | |||
@@ -26,14 +26,8 @@ | |||
wn.versions = { | |||
check: function() { | |||
if(window.localStorage) { | |||
if(window._version_number==-1 || parseInt(localStorage._version_number) | |||
!= parseInt(window._version_number)) { | |||
var localversion = localStorage._version_number; | |||
localStorage.clear(); | |||
console.log("Cache cleared - version: " + localversion | |||
+ ' to ' + _version_number) | |||
} | |||
localStorage.setItem('_version_number', window._version_number); | |||
var localversion = localStorage._version_number; | |||
localStorage.clear(); | |||
} | |||
} | |||
} |
@@ -21,38 +21,15 @@ | |||
# | |||
verbose = False | |||
import os | |||
import os | |||
def generate_hash(): | |||
""" | |||
Generates random hash for session id | |||
""" | |||
import hashlib, time | |||
return hashlib.sha224(str(time.time())).hexdigest() | |||
def build(): | |||
"""concat / minify js files""" | |||
# build js files | |||
from py.build.bundle import Bundle | |||
bundle = Bundle() | |||
bundle.make() | |||
update_version() | |||
# build index.html and app.html | |||
import webnotes.cms.make | |||
webnotes.cms.make.make(get_version()) | |||
def get_version(): | |||
"""get from version.num file and increment it""" | |||
if os.path.exists('version.num'): | |||
with open('version.num', 'r') as vfile: | |||
version = vfile.read() | |||
else: | |||
version = generate_hash() | |||
return version | |||
def update_version(): | |||
"""incremenet version by 1""" | |||
version = generate_hash() | |||
with open('version.num', 'w') as vfile: | |||
vfile.write(str(version)) | |||
return version | |||
webnotes.cms.make.make() |
@@ -129,13 +129,13 @@ class DocType: | |||
with open(fpath, 'r') as f: | |||
self.doc.content = f.read() | |||
def write_cms_page(self, home_page=False): | |||
def write_cms_page(self, force=False): | |||
"""write cms page""" | |||
import webnotes.cms | |||
import os, codecs | |||
from jinja2 import Template | |||
if self.doc.web_page=='Yes' or home_page: | |||
if self.doc.web_page=='Yes' or force: | |||
# doc will be dirty, so save it | |||
_doc = self.doc.fields.copy() | |||
@@ -157,10 +157,10 @@ class DocType: | |||
import startup.event_handlers | |||
if hasattr(startup.event_handlers, 'get_web_header'): | |||
self.doc.header = startup.event_handlers.get_web_header() | |||
self.doc.header = startup.event_handlers.get_web_header(self.doc.name) | |||
if hasattr(startup.event_handlers, 'get_web_footer'): | |||
self.doc.footer = startup.event_handlers.get_web_footer() | |||
self.doc.footer = startup.event_handlers.get_web_footer(self.doc.name) | |||
with codecs.open(fname, 'w', 'utf-8') as page: | |||
with open(os.path.join(os.path.dirname(webnotes.cms.__file__), | |||
@@ -5,7 +5,7 @@ | |||
{ | |||
'creation': '2012-05-01 17:10:24', | |||
'docstatus': 0, | |||
'modified': '2012-05-08 12:54:22', | |||
'modified': '2012-05-09 10:17:33', | |||
'modified_by': u'Administrator', | |||
'owner': u'Administrator' | |||
}, | |||
@@ -24,7 +24,7 @@ | |||
Generate RSS feed for blog | |||
""" | |||
rss = """<?xml version="1.0" encoding="UTF-8" ?> | |||
rss = u"""<?xml version="1.0" encoding="UTF-8" ?> | |||
<rss version="2.0"> | |||
<channel> | |||
<title>%(title)s</title> | |||
@@ -37,10 +37,10 @@ rss = """<?xml version="1.0" encoding="UTF-8" ?> | |||
</channel> | |||
</rss>""" | |||
rss_item = """ | |||
rss_item = u""" | |||
<item> | |||
<title>%(title)s</title> | |||
<description>%(content_html)s</description> | |||
<description>%(content)s</description> | |||
<link>%(link)s</link> | |||
<guid>%(name)s</guid> | |||
<pubDate>%(modified)s</pubDate> | |||
@@ -55,22 +55,25 @@ def generate(): | |||
items = '' | |||
modified = None | |||
for blog in webnotes.conn.sql("""select name, title, content_html, modified from tabBlog | |||
where ifnull(published,0)=1 order by modified desc limit 100""", as_dict=1): | |||
blog['link'] = host + '/#!' + blog['name'] | |||
blog['content_html'] = scrub(blog['content_html'] or '') | |||
for blog in webnotes.conn.sql("""select name, title, content, modified, page_name | |||
from tabBlog | |||
where ifnull(published,0)=1 | |||
order by modified desc limit 100""", as_dict=1): | |||
blog['link'] = host + '/' + blog['page_name'] + '.html' | |||
blog['content'] = scrub(blog['content'][:1000] or '') | |||
if not modified: | |||
modified = blog['modified'] | |||
items += rss_item % blog | |||
ws = Document('Website Settings', 'Website Settings') | |||
return rss % { | |||
return (rss % { | |||
'title': ws.title_prefix, | |||
'description': ws.description or (ws.title_prefix + ' Blog'), | |||
'modified': modified, | |||
'items': items, | |||
'link': host + '/#!blog' | |||
} | |||
'link': host + '/blog.html' | |||
}).encode('utf-8', 'ignore') | |||
def scrub(txt): | |||
return txt.replace('<', '<').replace('>', '>') |
@@ -2,42 +2,57 @@ | |||
make index, wn.js, wn.css pages | |||
- rebuild all pages on change of website settings (toolbar) | |||
""" | |||
def make(version): | |||
def make(): | |||
import os | |||
import webnotes | |||
from webnotes.model.code import get_obj | |||
from jinja2 import Template | |||
import webnotes.cms | |||
webnotes.connect() | |||
if not webnotes.conn: | |||
webnotes.connect() | |||
make_web_core() | |||
def make_web_core(): | |||
"""make index.html, wn-web.js, wn-web.css, sitemap.xml and rss.xml""" | |||
# index.html | |||
from webnotes.model.code import get_obj | |||
import webnotes | |||
# get web home | |||
home_page = webnotes.cms.get_home_page('Guest') | |||
get_obj('Page', home_page).write_cms_page() | |||
# js/wn-web.js and css/wn-web.css | |||
write_web_js_css(home_page) | |||
page = get_obj('Page', home_page) | |||
page.write_cms_page(home_page=True) | |||
# sitemap.xml | |||
# rss.xml | |||
def write_web_js_css(home_page): | |||
"""write web js and css""" | |||
# script - wn.js | |||
import os | |||
import startup.event_handlers | |||
if hasattr(startup.event_handlers, 'get_web_script'): | |||
with open('public/js/wn-web.js', 'w') as f: | |||
script = 'window._version_number = "%s";\n' % version | |||
script += 'window.home_page = "%s";\n' % home_page | |||
fname = 'js/wn-web.js' | |||
if os.path.basename(os.path.abspath('.'))!='public': | |||
fname = os.path.join('public', fname) | |||
if hasattr(startup.event_handlers, 'get_web_script'): | |||
with open(fname, 'w') as f: | |||
script = 'window.home_page = "%s";\n' % home_page | |||
script += startup.event_handlers.get_web_script() | |||
f.write(script) | |||
fname = 'css/wn-web.css' | |||
if os.path.basename(os.path.abspath('.'))!='public': | |||
fname = os.path.join('public', fname) | |||
# style - wn.css | |||
if hasattr(startup.event_handlers, 'get_web_style'): | |||
with open('public/css/wn-web.css', 'w') as f: | |||
f.write(startup.event_handlers.get_web_style()) | |||
# make app.html | |||
with open(os.path.join(os.path.dirname(webnotes.cms.__file__), 'app.html'), 'r') \ | |||
as app_template: | |||
with open('public/app.html', 'w') as app: | |||
app.write(Template(app_template.read()).render(version=version)) | |||
with open(fname, 'w') as f: | |||
f.write(startup.event_handlers.get_web_style()) |
@@ -31,7 +31,7 @@ link_xml = """\n<url><loc>%s</loc><lastmod>%s</lastmod></url>""" | |||
# generate the sitemap XML | |||
def generate(domain): | |||
global frame_xml, link_xml | |||
import urllib | |||
import urllib, os | |||
import webnotes | |||
# settings | |||
@@ -47,9 +47,10 @@ def generate(domain): | |||
FROM tabPage t1, `tabPage Role` t2 | |||
WHERE t1.name = t2.parent | |||
and t2.role = 'Guest' | |||
and t1.web_page = 'Yes' | |||
ORDER BY modified DESC"""): | |||
page_url = domain + '#!' + urllib.quote(r[0]) | |||
page_url = os.path.join(domain, urllib.quote(r[0]) + '.html') | |||
site_map += link_xml % (page_url, r[1].strftime('%Y-%m-%d')) | |||
@@ -155,7 +155,7 @@ class DocList: | |||
user = webnotes.__dict__.get('session', {}).get('user') or 'Administrator' | |||
for d in self.docs: | |||
if self.doc.__islocal: | |||
if self.doc.fields.get('__islocal'): | |||
d.owner = user | |||
d.creation = ts | |||
@@ -191,7 +191,7 @@ class DocList: | |||
Save the main doc | |||
""" | |||
try: | |||
self.doc.save(cint(self.doc.__islocal)) | |||
self.doc.save(cint(self.doc.fields.get('__islocal'))) | |||
except NameError, e: | |||
webnotes.msgprint('%s "%s" already exists' % (self.doc.doctype, self.doc.name)) | |||
@@ -261,30 +261,36 @@ class _DocType: | |||
"""add js, css code""" | |||
import os | |||
from webnotes.modules import scrub, get_module_path | |||
import conf | |||
modules_path = get_module_path(doc.module) | |||
path = os.path.join(modules_path, 'doctype', scrub(doc.name)) | |||
fpath = os.path.join(path, scrub(doc.name) + '.js') | |||
if os.path.exists(fpath): | |||
with open(fpath, 'r') as f: | |||
doc.fields['__js'] = f.read() | |||
fpath = os.path.join(path, scrub(doc.name) + '.css') | |||
if os.path.exists(fpath): | |||
with open(fpath, 'r') as f: | |||
doc.fields['__css'] = f.read() | |||
fpath = os.path.join(path, 'listview.js') | |||
if os.path.exists(fpath): | |||
with open(fpath, 'r') as f: | |||
doc.fields['__listjs'] = f.read() | |||
fpath = os.path.join(path, 'help.md') | |||
if os.path.exists(fpath): | |||
with open(fpath, 'r') as f: | |||
doc.fields['description'] = f.read() | |||
def _add_code(fname, fieldname): | |||
fpath = os.path.join(path, fname) | |||
if os.path.exists(fpath): | |||
with open(fpath, 'r') as f: | |||
doc.fields[fieldname] = f.read() | |||
_add_code(scrub(doc.name) + '.js', '__js') | |||
_add_code(scrub(doc.name) + '.css', '__css') | |||
_add_code('listview.js', '__listjs') | |||
_add_code('help.md', 'description') | |||
# embed all require files | |||
import re | |||
def _sub(match): | |||
fpath = os.path.join(os.path.dirname(conf.modules_path), \ | |||
re.search('["\'][^"\']*["\']', match.group(0)).group(0)[1:-1]) | |||
if os.path.exists(fpath): | |||
with open(fpath, 'r') as f: | |||
return '\n' + f.read() + '\n' | |||
else: | |||
return '\n// no file "%s" found \n' % fpath | |||
if doc.fields.get('__js'): | |||
doc.fields['__js'] = re.sub('(wn.require\([^\)]*.)', _sub, doc.fields['__js']) | |||
# custom script | |||
from webnotes.model.code import get_custom_script | |||
@@ -233,18 +233,19 @@ class EMail: | |||
""" | |||
from webnotes.utils import cint | |||
import smtplib | |||
sess = smtplib.SMTP(self.server.encode('utf-8'), cint(self.port) or None) | |||
sess = smtplib.SMTP(self.server, cint(self.port) or None) | |||
if self.use_ssl: | |||
sess.ehlo() | |||
sess.starttls() | |||
sess.ehlo() | |||
ret = sess.login(self.login.encode('utf-8'), self.password.encode('utf-8')) | |||
if self.login and self.password: | |||
ret = sess.login(self.login, self.password) | |||
# check if logged correctly | |||
if ret[0]!=235: | |||
msgprint(ret[1]) | |||
raise Exception | |||
# check if logged correctly | |||
if ret[0]!=235: | |||
msgprint(ret[1]) | |||
raise Exception | |||
return sess |