Przeglądaj źródła

fixes to cms and require files embedded in model/doctype.py

version-14
Rushabh Mehta 13 lat temu
rodzic
commit
5c7df8f371
12 zmienionych plików z 99 dodań i 105 usunięć
  1. +1
    -2
      conf/app.html
  2. +1
    -3
      js/core.min.js
  3. +2
    -8
      js/wn/versions.js
  4. +5
    -28
      py/build/project.py
  5. +4
    -4
      py/core/doctype/page/page.py
  6. +1
    -1
      py/core/page/login_page/login_page.txt
  7. +13
    -10
      py/webnotes/cms/feed.py
  8. +35
    -20
      py/webnotes/cms/make.py
  9. +3
    -2
      py/webnotes/cms/sitemap.py
  10. +2
    -2
      py/webnotes/model/doclist.py
  11. +25
    -19
      py/webnotes/model/doctype.py
  12. +7
    -6
      py/webnotes/utils/email_lib/send.py

py/webnotes/cms/app.html → conf/app.html Wyświetl plik

@@ -15,7 +15,6 @@
} }
</script> </script>
<script type="text/javascript" src="js/all-app.js"></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"> <link type="text/css" rel="stylesheet" href="css/all-app.css">
</head> </head>
<body> <body>
@@ -23,4 +22,4 @@
<div id="body_div"> <div id="body_div">
</div> </div>
<footer></footer> <footer></footer>
</body>
</body>

+ 1
- 3
js/core.min.js Wyświetl plik

@@ -15,9 +15,7 @@ wn.provide('wn.settings');wn.provide('wn.ui');
/* /*
* lib/js/wn/versions.js * 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 * lib/js/wn/assets.js
*/ */


+ 2
- 8
js/wn/versions.js Wyświetl plik

@@ -26,14 +26,8 @@
wn.versions = { wn.versions = {
check: function() { check: function() {
if(window.localStorage) { 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();
} }
} }
} }

+ 5
- 28
py/build/project.py Wyświetl plik

@@ -21,38 +21,15 @@
# #


verbose = False 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(): def build():
"""concat / minify js files""" """concat / minify js files"""
# build js files
from py.build.bundle import Bundle from py.build.bundle import Bundle
bundle = Bundle() bundle = Bundle()
bundle.make() bundle.make()
update_version()
# build index.html and app.html
import webnotes.cms.make 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()

+ 4
- 4
py/core/doctype/page/page.py Wyświetl plik

@@ -129,13 +129,13 @@ class DocType:
with open(fpath, 'r') as f: with open(fpath, 'r') as f:
self.doc.content = f.read() self.doc.content = f.read()


def write_cms_page(self, home_page=False):
def write_cms_page(self, force=False):
"""write cms page""" """write cms page"""
import webnotes.cms import webnotes.cms
import os, codecs import os, codecs
from jinja2 import Template 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 will be dirty, so save it
_doc = self.doc.fields.copy() _doc = self.doc.fields.copy()
@@ -157,10 +157,10 @@ class DocType:


import startup.event_handlers import startup.event_handlers
if hasattr(startup.event_handlers, 'get_web_header'): 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'): 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 codecs.open(fname, 'w', 'utf-8') as page:
with open(os.path.join(os.path.dirname(webnotes.cms.__file__), with open(os.path.join(os.path.dirname(webnotes.cms.__file__),


+ 1
- 1
py/core/page/login_page/login_page.txt Wyświetl plik

@@ -5,7 +5,7 @@
{ {
'creation': '2012-05-01 17:10:24', 'creation': '2012-05-01 17:10:24',
'docstatus': 0, 'docstatus': 0,
'modified': '2012-05-08 12:54:22',
'modified': '2012-05-09 10:17:33',
'modified_by': u'Administrator', 'modified_by': u'Administrator',
'owner': u'Administrator' 'owner': u'Administrator'
}, },


+ 13
- 10
py/webnotes/cms/feed.py Wyświetl plik

@@ -24,7 +24,7 @@
Generate RSS feed for blog 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"> <rss version="2.0">
<channel> <channel>
<title>%(title)s</title> <title>%(title)s</title>
@@ -37,10 +37,10 @@ rss = """<?xml version="1.0" encoding="UTF-8" ?>
</channel> </channel>
</rss>""" </rss>"""


rss_item = """
rss_item = u"""
<item> <item>
<title>%(title)s</title> <title>%(title)s</title>
<description>%(content_html)s</description>
<description>%(content)s</description>
<link>%(link)s</link> <link>%(link)s</link>
<guid>%(name)s</guid> <guid>%(name)s</guid>
<pubDate>%(modified)s</pubDate> <pubDate>%(modified)s</pubDate>
@@ -55,22 +55,25 @@ def generate():
items = '' items = ''
modified = None 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: if not modified:
modified = blog['modified'] modified = blog['modified']
items += rss_item % blog items += rss_item % blog
ws = Document('Website Settings', 'Website Settings') ws = Document('Website Settings', 'Website Settings')
return rss % {
return (rss % {
'title': ws.title_prefix, 'title': ws.title_prefix,
'description': ws.description or (ws.title_prefix + ' Blog'), 'description': ws.description or (ws.title_prefix + ' Blog'),
'modified': modified, 'modified': modified,
'items': items, 'items': items,
'link': host + '/#!blog'
}
'link': host + '/blog.html'
}).encode('utf-8', 'ignore')
def scrub(txt): def scrub(txt):
return txt.replace('<', '&lt;').replace('>', '&gt;') return txt.replace('<', '&lt;').replace('>', '&gt;')

+ 35
- 20
py/webnotes/cms/make.py Wyświetl plik

@@ -2,42 +2,57 @@
make index, wn.js, wn.css pages make index, wn.js, wn.css pages
- rebuild all pages on change of website settings (toolbar) - rebuild all pages on change of website settings (toolbar)
""" """
def make(version):
def make():
import os import os
import webnotes import webnotes
from webnotes.model.code import get_obj
from jinja2 import Template from jinja2 import Template
import webnotes.cms 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') 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 # script - wn.js
import os
import startup.event_handlers 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() script += startup.event_handlers.get_web_script()


f.write(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 # style - wn.css
if hasattr(startup.event_handlers, 'get_web_style'): 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())

+ 3
- 2
py/webnotes/cms/sitemap.py Wyświetl plik

@@ -31,7 +31,7 @@ link_xml = """\n<url><loc>%s</loc><lastmod>%s</lastmod></url>"""
# generate the sitemap XML # generate the sitemap XML
def generate(domain): def generate(domain):
global frame_xml, link_xml global frame_xml, link_xml
import urllib
import urllib, os
import webnotes import webnotes


# settings # settings
@@ -47,9 +47,10 @@ def generate(domain):
FROM tabPage t1, `tabPage Role` t2 FROM tabPage t1, `tabPage Role` t2
WHERE t1.name = t2.parent WHERE t1.name = t2.parent
and t2.role = 'Guest' and t2.role = 'Guest'
and t1.web_page = 'Yes'
ORDER BY modified DESC"""): 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')) site_map += link_xml % (page_url, r[1].strftime('%Y-%m-%d'))




+ 2
- 2
py/webnotes/model/doclist.py Wyświetl plik

@@ -155,7 +155,7 @@ class DocList:
user = webnotes.__dict__.get('session', {}).get('user') or 'Administrator' user = webnotes.__dict__.get('session', {}).get('user') or 'Administrator'


for d in self.docs: for d in self.docs:
if self.doc.__islocal:
if self.doc.fields.get('__islocal'):
d.owner = user d.owner = user
d.creation = ts d.creation = ts


@@ -191,7 +191,7 @@ class DocList:
Save the main doc Save the main doc
""" """
try: try:
self.doc.save(cint(self.doc.__islocal))
self.doc.save(cint(self.doc.fields.get('__islocal')))
except NameError, e: except NameError, e:
webnotes.msgprint('%s "%s" already exists' % (self.doc.doctype, self.doc.name)) webnotes.msgprint('%s "%s" already exists' % (self.doc.doctype, self.doc.name))




+ 25
- 19
py/webnotes/model/doctype.py Wyświetl plik

@@ -261,30 +261,36 @@ class _DocType:
"""add js, css code""" """add js, css code"""
import os import os
from webnotes.modules import scrub, get_module_path from webnotes.modules import scrub, get_module_path
import conf
modules_path = get_module_path(doc.module) modules_path = get_module_path(doc.module)


path = os.path.join(modules_path, 'doctype', scrub(doc.name)) 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 # custom script
from webnotes.model.code import get_custom_script from webnotes.model.code import get_custom_script


+ 7
- 6
py/webnotes/utils/email_lib/send.py Wyświetl plik

@@ -233,18 +233,19 @@ class EMail:
""" """
from webnotes.utils import cint from webnotes.utils import cint
import smtplib 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: if self.use_ssl:
sess.ehlo() sess.ehlo()
sess.starttls() sess.starttls()
sess.ehlo() 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 return sess

Ładowanie…
Anuluj
Zapisz