wiki services
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.00.0 (2012-07-29 10:04:25) dev
|
Version 2.00.0 (2012-07-29 10:32:43) dev
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)
|
|||||||
import datetime
|
import datetime
|
||||||
import decimal
|
import decimal
|
||||||
from storage import Storage
|
from storage import Storage
|
||||||
from html import TAG
|
from html import TAG, XmlComponent
|
||||||
from html import xmlescape
|
from html import xmlescape
|
||||||
from languages import lazyT
|
from languages import lazyT
|
||||||
import contrib.rss2 as rss2
|
import contrib.rss2 as rss2
|
||||||
@@ -32,6 +32,8 @@ def custom_json(o):
|
|||||||
return str(o)
|
return str(o)
|
||||||
elif isinstance(o, lazyT):
|
elif isinstance(o, lazyT):
|
||||||
return str(o)
|
return str(o)
|
||||||
|
elif isinstance(o,XmlComponent):
|
||||||
|
return str(o)
|
||||||
elif hasattr(o,'as_list') and callable(o.as_list):
|
elif hasattr(o,'as_list') and callable(o.as_list):
|
||||||
return o.as_list()
|
return o.as_list()
|
||||||
elif hasattr(o,'as_dict') and callable(o.as_dict):
|
elif hasattr(o,'as_dict') and callable(o.as_dict):
|
||||||
|
|||||||
+39
-16
@@ -4375,6 +4375,12 @@ class Expose(object):
|
|||||||
H3('Files'),
|
H3('Files'),
|
||||||
self.table_files()).xml()
|
self.table_files()).xml()
|
||||||
|
|
||||||
|
def first_paragraph(mm):
|
||||||
|
mm = mm.replace('\r','')
|
||||||
|
ps = [p for p in mm.split('\n\n') if not p.startswith('#') and p.strip()]
|
||||||
|
if ps: return ps[0]
|
||||||
|
return ''
|
||||||
|
|
||||||
class Wiki(object):
|
class Wiki(object):
|
||||||
regex_redirect = re.compile('redirect\s+(\w+\://\S+)\s*')
|
regex_redirect = re.compile('redirect\s+(\w+\://\S+)\s*')
|
||||||
def __init__(self,auth,env=None,automenu=True,render='markmin'):
|
def __init__(self,auth,env=None,automenu=True,render='markmin'):
|
||||||
@@ -4439,13 +4445,24 @@ class Wiki(object):
|
|||||||
if slug in '_cloud':
|
if slug in '_cloud':
|
||||||
return self.cloud()
|
return self.cloud()
|
||||||
page = self.auth.db.wiki_page(slug=slug)
|
page = self.auth.db.wiki_page(slug=slug)
|
||||||
if not page:
|
if current.request.extension == 'html':
|
||||||
url = URL(args=('_edit',slug))
|
if not page:
|
||||||
return dict(content=A('Create page "%s"' % slug,_href=url,_class="btn"))
|
url = URL(args=('_edit',slug))
|
||||||
|
return dict(content=A('Create page "%s"' % slug,_href=url,_class="btn"))
|
||||||
|
else:
|
||||||
|
match = self.regex_redirect.match(page.body)
|
||||||
|
if match: redirect(match.group(1))
|
||||||
|
return dict(content=XML(page.html))
|
||||||
else:
|
else:
|
||||||
match = self.regex_redirect.match(page.body)
|
if not page:
|
||||||
if match: redirect(match.group(1))
|
raise HTTP(404)
|
||||||
return dict(content=XML(page.html))
|
else:
|
||||||
|
return dict(title=page.title,
|
||||||
|
slug=page.slug,
|
||||||
|
content=page.body,
|
||||||
|
tags=page.tags,
|
||||||
|
created_on=page.created_on,
|
||||||
|
modified_on=page.modified_on)
|
||||||
def check_authorization(self,role='wiki_editor',act=False):
|
def check_authorization(self,role='wiki_editor',act=False):
|
||||||
if not self.auth.user:
|
if not self.auth.user:
|
||||||
if not act: return False
|
if not act: return False
|
||||||
@@ -4524,42 +4541,48 @@ class Wiki(object):
|
|||||||
URL(controller,function,args=('_cloud'))))
|
URL(controller,function,args=('_cloud'))))
|
||||||
menu.append((current.T('[Wiki]'),None,None,submenu))
|
menu.append((current.T('[Wiki]'),None,None,submenu))
|
||||||
return menu
|
return menu
|
||||||
def search(self,tags=None,cloud=True,preview=True,limitby=(0,100),orderby=None):
|
def search(self,tags=None,cloud=True,preview=True,
|
||||||
|
limitby=(0,100),orderby=None):
|
||||||
content = CAT()
|
content = CAT()
|
||||||
if not tags:
|
if not tags:
|
||||||
request = current.request
|
request = current.request
|
||||||
form = SQLFORM.factory(Field('tags',requires=IS_NOT_EMPTY(),
|
form = SQLFORM.factory(Field('tags',requires=IS_NOT_EMPTY(),
|
||||||
default=request.vars.tags,
|
default=request.vars.tags,
|
||||||
label=current.T('Search')))
|
label=current.T('Search')))
|
||||||
|
content.append(DIV(form,_class='w2p_wiki_form'))
|
||||||
if request.vars:
|
if request.vars:
|
||||||
tags = [v.strip() for v in request.vars.tags.split(',')]
|
tags = [v.strip() for v in request.vars.tags.split(',')]
|
||||||
tags = [v for v in tags if v]
|
tags = [v for v in tags if v]
|
||||||
content.append(DIV(form,_class='w2p_wiki_form'))
|
|
||||||
if tags:
|
if tags:
|
||||||
db = self.auth.db
|
db = self.auth.db
|
||||||
count = db.wiki_tag.wiki_page.count()
|
count = db.wiki_tag.wiki_page.count()
|
||||||
fields = [db.wiki_page.slug,db.wiki_page.title,
|
fields = [db.wiki_page.id,db.wiki_page.slug,
|
||||||
db.wiki_page.tags,count]
|
db.wiki_page.title,db.wiki_page.tags,count]
|
||||||
if preview:
|
if preview:
|
||||||
fields.append(db.wiki_page.body)
|
fields.append(db.wiki_page.body)
|
||||||
pages = db(db.wiki_page.id==db.wiki_tag.wiki_page) \
|
pages = db(db.wiki_page.id==db.wiki_tag.wiki_page) \
|
||||||
(db.wiki_tag.name.belongs(tags)).select(
|
(db.wiki_tag.name.belongs(tags)).select(
|
||||||
*fields,**dict(orderby=orderby or ~count,limitby=limitby))
|
*fields,**dict(orderby=orderby or ~count,
|
||||||
if not pages:
|
groupby=db.wiki_page.id,
|
||||||
content.append(DIV(T("No results",_class='w2p_wiki_form')))
|
limitby=limitby))
|
||||||
else:
|
if request.extension=='html':
|
||||||
|
if not pages:
|
||||||
|
content.append(DIV(T("No results",_class='w2p_wiki_form')))
|
||||||
def link(t):
|
def link(t):
|
||||||
return A(t,_href=URL(args='_search',vars=dict(tags=t)))
|
return A(t,_href=URL(args='_search',vars=dict(tags=t)))
|
||||||
items = [DIV(H3(A(p.wiki_page.title,
|
items = [DIV(H3(A(p.wiki_page.title,
|
||||||
_href=URL(args=p.wiki_page.slug))),
|
_href=URL(args=p.wiki_page.slug))),
|
||||||
|
MARKMIN(first_paragraph(p.wiki_page.body)) \
|
||||||
|
if preview else '',
|
||||||
SPAN(*[link(t.strip()) for t in \
|
SPAN(*[link(t.strip()) for t in \
|
||||||
p.wiki_page.tags.split(',') \
|
p.wiki_page.tags.split(',') \
|
||||||
if t.strip()]),
|
if t.strip()]),
|
||||||
MARKMIN(p.wiki_page.body.split('\n\n')[0]) \
|
|
||||||
if preview else '',
|
|
||||||
_class='w2p_wiki_tags')
|
_class='w2p_wiki_tags')
|
||||||
for p in pages]
|
for p in pages]
|
||||||
content.append(DIV(_class='w2p_wiki_pages',*items))
|
content.append(DIV(_class='w2p_wiki_pages',*items))
|
||||||
|
else:
|
||||||
|
cloud=False
|
||||||
|
content = [p.as_dict() for p in pages]
|
||||||
elif cloud:
|
elif cloud:
|
||||||
content.append(self.cloud()['content'])
|
content.append(self.cloud()['content'])
|
||||||
return dict(content=content)
|
return dict(content=content)
|
||||||
|
|||||||
Reference in New Issue
Block a user