fixed T(T('..')) and added tools.Wiki
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.00.0 (2012-07-13 18:04:08) dev
|
Version 2.00.0 (2012-07-14 17:50:45) dev
|
||||||
|
|||||||
+1
-1
@@ -847,7 +847,7 @@ class DIV(XmlComponent):
|
|||||||
|
|
||||||
# get the xml for the inner components
|
# get the xml for the inner components
|
||||||
co = join([xmlescape(component) for component in
|
co = join([xmlescape(component) for component in
|
||||||
self.components])
|
self.components])
|
||||||
|
|
||||||
return (fa, co)
|
return (fa, co)
|
||||||
|
|
||||||
|
|||||||
+6
-9
@@ -53,17 +53,12 @@ regex_langinfo = re.compile("^[^'\"]*['\"]([^'\"]*)['\"]\s*:\s*['\"]([^'\"]*)['\
|
|||||||
tcache={}
|
tcache={}
|
||||||
|
|
||||||
def get_from_cache(cache, val, fun):
|
def get_from_cache(cache, val, fun):
|
||||||
lock=cache[1]
|
lock = cache[1]
|
||||||
lock.acquire()
|
lock.acquire()
|
||||||
try:
|
try:
|
||||||
result=cache[0].get(val);
|
result = cache[0].get(val);
|
||||||
finally:
|
if not result:
|
||||||
lock.release()
|
result = cache[0].setdefault(val, fun())
|
||||||
if result:
|
|
||||||
return result
|
|
||||||
lock.acquire()
|
|
||||||
try:
|
|
||||||
result=cache[0].setdefault(val, fun())
|
|
||||||
finally:
|
finally:
|
||||||
lock.release()
|
lock.release()
|
||||||
return result
|
return result
|
||||||
@@ -497,6 +492,8 @@ class translator(object):
|
|||||||
"""
|
"""
|
||||||
get cached translated message with inserted parameters(symbols)
|
get cached translated message with inserted parameters(symbols)
|
||||||
"""
|
"""
|
||||||
|
if isinstance(message,lazyT):
|
||||||
|
message = str(message)
|
||||||
message = get_from_cache(self.cache, (message, filter),
|
message = get_from_cache(self.cache, (message, filter),
|
||||||
lambda: self.get_t(message,filter))
|
lambda: self.get_t(message,filter))
|
||||||
if symbols or symbols == 0 or symbols == "":
|
if symbols or symbols == 0 or symbols == "":
|
||||||
|
|||||||
+5
-3
@@ -771,7 +771,8 @@ class SQLFORM(FORM):
|
|||||||
# if no fields are provided, build it from the provided table
|
# if no fields are provided, build it from the provided table
|
||||||
# will only use writable or readable fields, unless forced to ignore
|
# will only use writable or readable fields, unless forced to ignore
|
||||||
if fields is None:
|
if fields is None:
|
||||||
fields = [f.name for f in table if (ignore_rw or f.writable or f.readable) and not f.compute]
|
fields = [f.name for f in table if (
|
||||||
|
ignore_rw or f.writable or f.readable) and not f.compute]
|
||||||
self.fields = fields
|
self.fields = fields
|
||||||
|
|
||||||
# make sure we have an id
|
# make sure we have an id
|
||||||
@@ -1586,6 +1587,7 @@ class SQLFORM(FORM):
|
|||||||
field_id = tables[0]._id
|
field_id = tables[0]._id
|
||||||
columns = [str(field) for field in fields \
|
columns = [str(field) for field in fields \
|
||||||
if field._tablename in tablenames]
|
if field._tablename in tablenames]
|
||||||
|
|
||||||
if not str(field_id) in [str(f) for f in fields]:
|
if not str(field_id) in [str(f) for f in fields]:
|
||||||
fields.append(field_id)
|
fields.append(field_id)
|
||||||
table = field_id.table
|
table = field_id.table
|
||||||
@@ -1816,12 +1818,12 @@ class SQLFORM(FORM):
|
|||||||
if create:
|
if create:
|
||||||
search_actions.append(gridbutton(
|
search_actions.append(gridbutton(
|
||||||
buttonclass='buttonadd',
|
buttonclass='buttonadd',
|
||||||
buttontext=T('Add'),
|
buttontext='Add',
|
||||||
buttonurl=url(args=['new',tablename])))
|
buttonurl=url(args=['new',tablename])))
|
||||||
if csv and nrows:
|
if csv and nrows:
|
||||||
search_actions.append(gridbutton(
|
search_actions.append(gridbutton(
|
||||||
buttonclass='buttonexport',
|
buttonclass='buttonexport',
|
||||||
buttontext=T('Export'),
|
buttontext='Export',
|
||||||
trap = False,
|
trap = False,
|
||||||
buttonurl=url(args=['csv'],
|
buttonurl=url(args=['csv'],
|
||||||
vars=dict(keywords=request.vars.keywords or ''))))
|
vars=dict(keywords=request.vars.keywords or ''))))
|
||||||
|
|||||||
+101
-1
@@ -41,7 +41,7 @@ except ImportError:
|
|||||||
except:
|
except:
|
||||||
import contrib.simplejson as json_parser # fallback to pure-Python module
|
import contrib.simplejson as json_parser # fallback to pure-Python module
|
||||||
|
|
||||||
__all__ = ['Mail', 'Auth', 'Recaptcha', 'Crud', 'Service',
|
__all__ = ['Mail', 'Auth', 'Recaptcha', 'Crud', 'Service', 'Wiki',
|
||||||
'PluginManager', 'fetch', 'geocode', 'prettydate']
|
'PluginManager', 'fetch', 'geocode', 'prettydate']
|
||||||
|
|
||||||
### mind there are two loggers here (logger and crud.settings.logger)!
|
### mind there are two loggers here (logger and crud.settings.logger)!
|
||||||
@@ -4344,6 +4344,106 @@ class Expose(object):
|
|||||||
H3('Files'),
|
H3('Files'),
|
||||||
self.table_files()).xml()
|
self.table_files()).xml()
|
||||||
|
|
||||||
|
class Wiki(object):
|
||||||
|
def __init__(self,auth):
|
||||||
|
self.auth = auth
|
||||||
|
db = auth.db
|
||||||
|
db.define_table(
|
||||||
|
'wiki_page',
|
||||||
|
db.Field('slug',requires=[IS_SLUG(),IS_NOT_IN_DB(db,'wiki_page.slug')],
|
||||||
|
readable=False,writable=False),
|
||||||
|
db.Field('title',unique=True),
|
||||||
|
db.Field('body','text',notnull=True),
|
||||||
|
db.Field('menu'),
|
||||||
|
db.Field('html','text',readable=False,writable=False,
|
||||||
|
compute= lambda t: MARKMIN(t.body).xml()),
|
||||||
|
auth.signature)
|
||||||
|
db.define_table(
|
||||||
|
'wiki_media',
|
||||||
|
db.Field('title',required=True),
|
||||||
|
db.Field('file','upload',required=True),
|
||||||
|
auth.signature)
|
||||||
|
def getslug(self,args):
|
||||||
|
if not args: return 'index'
|
||||||
|
return '/'.join(args)
|
||||||
|
def __call__(self):
|
||||||
|
if current.request.args(0)=='_edit':
|
||||||
|
return self.edit(self.getslug(current.request.args[1:]))
|
||||||
|
elif current.request.args(0)=='_pages':
|
||||||
|
return self.pages()
|
||||||
|
elif current.request.args(0)=='_media':
|
||||||
|
return self.media()
|
||||||
|
else:
|
||||||
|
return self.read(self.getslug(current.request.args))
|
||||||
|
def read(self,slug):
|
||||||
|
page = self.auth.db.wiki_page(slug=slug)
|
||||||
|
if not page:
|
||||||
|
url = URL(args=('_edit',slug))
|
||||||
|
return dict(content=A('Create page "%s"' % slug,_href=url,_class="btn"))
|
||||||
|
else:
|
||||||
|
return dict(content=XML(page.html))
|
||||||
|
def check_authorization(self,act=False):
|
||||||
|
if not self.auth.user:
|
||||||
|
if not act: return False
|
||||||
|
redirect(self.auth.settings.login_url)
|
||||||
|
elif not self.auth.has_membership('wiki_editor'):
|
||||||
|
if not act: return False
|
||||||
|
raise HTTP(401, "Not Authorized")
|
||||||
|
return True
|
||||||
|
def edit(self,slug):
|
||||||
|
self.check_authorization()
|
||||||
|
auth = self.auth
|
||||||
|
db = auth.db
|
||||||
|
page = db.wiki_page(slug=slug)
|
||||||
|
title_guess = ' '.join(c.capitalize() for c in slug.split('-'))
|
||||||
|
db.wiki_page.title.default = title_guess
|
||||||
|
db.wiki_page.slug.default = slug
|
||||||
|
db.wiki_page.menu.default = slug
|
||||||
|
db.wiki_page.body.default = '## %s\n\npage content' % title_guess
|
||||||
|
form = SQLFORM(db.wiki_page,page,deletable=True,showid=False).process()
|
||||||
|
if form.accepted:
|
||||||
|
current.session.flash = 'page created'
|
||||||
|
redirect(URL(args=slug))
|
||||||
|
return dict(content=form)
|
||||||
|
def pages(self):
|
||||||
|
self.check_authorization()
|
||||||
|
self.auth.db.wiki_page.slug.writable = True
|
||||||
|
content=SQLFORM.grid(self.auth.db.wiki_page,args=['_pages'])
|
||||||
|
return dict(content=content)
|
||||||
|
def media(self):
|
||||||
|
self.check_authorization()
|
||||||
|
content=SQLFORM.grid(self.auth.db.wiki_media,args=['_media'])
|
||||||
|
return dict(content=content)
|
||||||
|
def menu(self,controller,function):
|
||||||
|
db = self.auth.db
|
||||||
|
request = current.request
|
||||||
|
rows = db().select(db.wiki_page.menu,db.wiki_page.title,db.wiki_page.slug,
|
||||||
|
orderby = db.wiki_page.menu)
|
||||||
|
menu = []
|
||||||
|
tree = {'.':menu}
|
||||||
|
for row in rows:
|
||||||
|
key = './'+row.menu
|
||||||
|
base = key.rsplit('/',1)[0]
|
||||||
|
subtree = tree[key] = []
|
||||||
|
tree[base].append((current.T(row.title),
|
||||||
|
request.args(0)==row.slug,
|
||||||
|
URL(controller,function,args=row.slug),
|
||||||
|
subtree))
|
||||||
|
if self.check_authorization(act=False):
|
||||||
|
submenu = []
|
||||||
|
if URL() == URL(controller,function) and \
|
||||||
|
not str(request.args(0)).startswith('_'):
|
||||||
|
submenu.append((current.T('Edit'),None,
|
||||||
|
URL(controller,function,
|
||||||
|
args=('_edit',self.getslug(request.args)))))
|
||||||
|
submenu.append((current.T('Manage Pages'),None,
|
||||||
|
URL(controller,function,args=('_pages'))))
|
||||||
|
submenu.append((current.T('Manage Madia'),None,
|
||||||
|
URL(controller,function,args=('_media'))))
|
||||||
|
menu.append((current.T('[Wiki]'),None,None,submenu))
|
||||||
|
return menu
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import doctest
|
import doctest
|
||||||
|
|||||||
Reference in New Issue
Block a user