本文整理汇总了Python中trac.wiki.model.WikiPage.readonly方法的典型用法代码示例。如果您正苦于以下问题:Python WikiPage.readonly方法的具体用法?Python WikiPage.readonly怎么用?Python WikiPage.readonly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trac.wiki.model.WikiPage
的用法示例。
在下文中一共展示了WikiPage.readonly方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_wiki_pages
# 需要导入模块: from trac.wiki.model import WikiPage [as 别名]
# 或者: from trac.wiki.model.WikiPage import readonly [as 别名]
def import_wiki_pages(self, template_path):
"""Creates wiki pages from wiki.xml template file.
Creates wiki pages inside the project using data extracted from
an wiki.ml file. We don't set the author or version as that wouldn't
be applicable to a new project.
"""
# open the wiki XML file, parse the data and create wiki pages
full_path = os.path.join(template_path, 'wiki.xml')
try:
tree = ET.ElementTree(file=full_path)
for page in tree.getroot():
if page.text:
wikipage = WikiPage(self.env, page.attrib['name'])
wikipage.readonly = int(page.attrib['readonly']) # we store as a string in xml
wikipage.text = page.text
wikipage.save(None, None, None)
self.log.info("Wiki page %s created", page.attrib['name'])
else:
self.log.debug("Cannot create wiki pages with no text. "
"Unable to import %s", wikipage)
except IOError as exception:
if exception.errno == errno.ENOENT:
self.log.info("Path to wiki.xml file %s does not exist. Unable "
"to import wiki pages from template.", full_path)
示例2: _render_editor
# 需要导入模块: from trac.wiki.model import WikiPage [as 别名]
# 或者: from trac.wiki.model.WikiPage import readonly [as 别名]
def _render_editor(self, req, page, action='edit', has_collision=False):
if has_collision:
if action == 'merge':
page = WikiPage(self.env, page.name, version=None)
req.perm(page.resource).require('WIKI_VIEW')
else:
action = 'collision'
if page.readonly:
req.perm(page.resource).require('WIKI_ADMIN')
else:
req.perm(page.resource).require('WIKI_MODIFY')
original_text = page.text
if 'text' in req.args:
page.text = req.args.get('text')
elif 'template' in req.args:
template = self.PAGE_TEMPLATES_PREFIX + req.args.get('template')
template_page = WikiPage(self.env, template)
if template_page and template_page.exists and \
'WIKI_VIEW' in req.perm(template_page.resource):
page.text = template_page.text
if action == 'preview':
page.readonly = 'readonly' in req.args
author = get_reporter_id(req, 'author')
comment = req.args.get('comment', '')
editrows = req.args.get('editrows')
if editrows:
pref = req.session.get('wiki_editrows', '20')
if editrows != pref:
req.session['wiki_editrows'] = editrows
else:
editrows = req.session.get('wiki_editrows', '20')
data = self._page_data(req, page, action)
data.update({
'author': author,
'comment': comment,
'edit_rows': editrows,
'scroll_bar_pos': req.args.get('scroll_bar_pos', ''),
'diff': None,
})
if action in ('diff', 'merge'):
old_text = original_text and original_text.splitlines() or []
new_text = page.text and page.text.splitlines() or []
diff_data, changes = self._prepare_diff(
req, page, old_text, new_text, page.version, '')
data.update({'diff': diff_data, 'changes': changes,
'action': 'preview', 'merge': action == 'merge',
'longcol': 'Version', 'shortcol': 'v'})
self._wiki_ctxtnav(req, page)
return 'wiki_edit.html', data, None
示例3: putPage
# 需要导入模块: from trac.wiki.model import WikiPage [as 别名]
# 或者: from trac.wiki.model.WikiPage import readonly [as 别名]
def putPage(self, req, pagename, content, attributes):
""" writes the content of the page. """
page = WikiPage(self.env, pagename)
if page.readonly:
req.perm(page.resource).require("WIKI_ADMIN")
elif not page.exists:
req.perm(page.resource).require("WIKI_CREATE")
else:
req.perm(page.resource).require("WIKI_MODIFY")
page.text = content
if req.perm(page.resource).has_permission("WIKI_ADMIN"):
page.readonly = attributes.get("readonly") and 1 or 0
page.save(attributes.get("author", req.authname), attributes.get("comment"), req.remote_addr)
return True
示例4: putPage
# 需要导入模块: from trac.wiki.model import WikiPage [as 别名]
# 或者: from trac.wiki.model.WikiPage import readonly [as 别名]
def putPage(self, req, pagename, content, attributes):
""" writes the content of the page. """
page = WikiPage(self.env, pagename)
if page.readonly:
req.perm.assert_permission('WIKI_ADMIN')
elif not page.exists:
req.perm.assert_permission('WIKI_CREATE')
else:
req.perm.assert_permission('WIKI_MODIFY')
page.text = content
if req.perm.has_permission('WIKI_ADMIN'):
page.readonly = attributes.get('readonly') and 1 or 0
page.save(attributes.get('author', req.authname),
attributes.get('comment'),
req.remote_addr)
return True
示例5: _render_editor
# 需要导入模块: from trac.wiki.model import WikiPage [as 别名]
# 或者: from trac.wiki.model.WikiPage import readonly [as 别名]
def _render_editor(self, req, page, action='edit', has_collision=False):
if has_collision:
if action == 'merge':
page = WikiPage(self.env, page.name, version=None)
req.perm(page.resource).require('WIKI_VIEW')
else:
action = 'collision'
if page.readonly:
req.perm(page.resource).require('WIKI_ADMIN')
else:
req.perm(page.resource).require('WIKI_MODIFY')
original_text = page.text
comment = req.args.get('comment', '')
if 'text' in req.args:
page.text = req.args.get('text')
elif 'template' in req.args:
template = self.PAGE_TEMPLATES_PREFIX + req.args.get('template')
template_page = WikiPage(self.env, template)
if template_page and template_page.exists and \
'WIKI_VIEW' in req.perm(template_page.resource):
page.text = template_page.text
elif 'version' in req.args:
old_page = WikiPage(self.env, page.name,
version=int(req.args['version']))
req.perm(page.resource).require('WIKI_VIEW')
page.text = old_page.text
comment = _("Reverted to version %(version)s.",
version=req.args['version'])
if action in ('preview', 'diff'):
page.readonly = 'readonly' in req.args
author = get_reporter_id(req, 'author')
defaults = {'editrows': 20}
prefs = dict((key, req.session.get('wiki_%s' % key, defaults.get(key)))
for key in ('editrows', 'sidebyside'))
if 'from_editor' in req.args:
sidebyside = req.args.get('sidebyside') or None
if sidebyside != prefs['sidebyside']:
req.session.set('wiki_sidebyside', int(bool(sidebyside)), 0)
else:
sidebyside = prefs['sidebyside']
if sidebyside:
editrows = max(int(prefs['editrows']),
len(page.text.splitlines()) + 1)
else:
editrows = req.args.get('editrows')
if editrows:
if editrows != prefs['editrows']:
req.session.set('wiki_editrows', editrows,
defaults['editrows'])
else:
editrows = prefs['editrows']
data = self._page_data(req, page, action)
context = web_context(req, page.resource)
data.update({
'author': author,
'comment': comment,
'edit_rows': editrows, 'sidebyside': sidebyside,
'scroll_bar_pos': req.args.get('scroll_bar_pos', ''),
'diff': None,
'attachments': AttachmentModule(self.env).attachment_data(context),
})
if action in ('diff', 'merge'):
old_text = original_text.splitlines() if original_text else []
new_text = page.text.splitlines() if page.text else []
diff_data, changes = self._prepare_diff(
req, page, old_text, new_text, page.version, '')
data.update({'diff': diff_data, 'changes': changes,
'action': 'preview', 'merge': action == 'merge',
'longcol': 'Version', 'shortcol': 'v'})
elif sidebyside and action != 'collision':
data['action'] = 'preview'
self._wiki_ctxtnav(req, page)
Chrome(self.env).add_wiki_toolbars(req)
Chrome(self.env).add_auto_preview(req)
add_script(req, 'common/js/folding.js')
return 'wiki_edit.html', data, None
示例6: _new_blog_post
# 需要导入模块: from trac.wiki.model import WikiPage [as 别名]
# 或者: from trac.wiki.model.WikiPage import readonly [as 别名]
def _new_blog_post(self, req):
""" Generate a new blog post
"""
action = req.args.get('action', 'edit')
pg_name_fmt = self.env.config.get('blog', 'page_format',
'%Y/%m/%d/%H.%M')
wikitext = req.args.get('text', '')
blogtitle = req.args.get('blogtitle', '')
pagename = req.args.get('pagename', pg_name_fmt)
pagename = time.strftime(pagename)
if '%@' in pagename and blogtitle:
urltitle = re.sub(r'[^\w]+', '-', blogtitle).lower()
pagename = pagename.replace('%@', urltitle)
while '-' in pagename and len(pagename) > 60:
pagename = '-'.join(pagename.split('-')[:-1])
pagename = pagename.strip('-')
if '$U' in pagename:
pagename = pagename.replace('$U', req.authname)
comment = req.args.get('comment', '')
readonly = int(req.args.has_key('readonly'))
edit_rows = int(req.args.get('edite_rows', 20))
req_tags = req.args.get('tags', [])
if req.method == 'POST':
if action == 'edit':
if req.args.has_key('cancel'):
req.redirect(self.env.href.blog())
page = WikiPage(self.env, pagename, None)
tags = TagEngine(self.env).tagspace.wiki
if req.args.has_key('preview'):
req.hdf['blog.action'] = 'preview'
self._render_editor(req, page, self.env.get_db_cnx(),
preview=True)
else:
titleline = ' '.join(["=", blogtitle, "=\n"])
if blogtitle:
page.text = ''.join([titleline, wikitext])
else:
page.text = wikitext
page.readonly = readonly
page.save(req.authname, comment, req.remote_addr)
# taglist = [x.strip() for x in req_tags.split(',') if x]
taglist = [t.strip() for t in
_tag_split.split(req.args.get('tags'))
if t.strip()]
tags.add_tags(req, pagename, taglist)
req.redirect(self.env.href.blog())
else:
info = {
'title' : blogtitle,
'pagename': pagename,
'page_source': wikitext,
'comment': comment,
'readonly': readonly,
'edit_rows': edit_rows,
'scroll_bar_pos': req.args.get('scroll_bar_pos', '')
}
req.hdf['blog'] = info
req.hdf['title'] = 'New Blog Entry'
tlist = req.args.getlist('tag')
if not tlist:
tlist = [self.env.config.get('blog', 'default_tag', 'blog')]
req.hdf['tags'] = ', '.join(tlist)
pass
示例7: _render_editor
# 需要导入模块: from trac.wiki.model import WikiPage [as 别名]
# 或者: from trac.wiki.model.WikiPage import readonly [as 别名]
def _render_editor(self, req, page, action='edit', has_collision=False):
if has_collision:
if action == 'merge':
page = WikiPage(self.env, page.name, version=None)
req.perm(page.resource).require('WIKI_VIEW')
else:
action = 'collision'
if page.readonly:
req.perm(page.resource).require('WIKI_ADMIN')
else:
req.perm(page.resource).require('WIKI_MODIFY')
original_text = page.text
if 'text' in req.args:
page.text = req.args.get('text')
elif 'template' in req.args:
template = self.PAGE_TEMPLATES_PREFIX + req.args.get('template')
template_page = WikiPage(self.env, template)
if template_page and template_page.exists and \
'WIKI_VIEW' in req.perm(template_page.resource):
page.text = template_page.text
if action in ('preview', 'diff'):
page.readonly = 'readonly' in req.args
author = get_reporter_id(req, 'author')
comment = req.args.get('comment', '')
defaults = {'editrows': 20}
prefs = dict((key, req.session.get('wiki_%s' % key, defaults.get(key)))
for key in ('editrows', 'sidebyside'))
if 'from_editor' in req.args:
sidebyside = req.args.get('sidebyside') or None
if sidebyside != prefs['sidebyside']:
if sidebyside:
req.session['wiki_sidebyside'] = '1'
else:
del req.session['wiki_sidebyside']
else:
sidebyside = prefs['sidebyside']
if sidebyside:
editrows = max(int(prefs['editrows']),
len(page.text.splitlines()) + 1)
else:
editrows = req.args.get('editrows')
if editrows:
if editrows != prefs['editrows']:
req.session['wiki_editrows'] = editrows
else:
editrows = prefs['editrows']
data = self._page_data(req, page, action)
data.update({
'author': author,
'comment': comment,
'edit_rows': editrows, 'sidebyside': sidebyside,
'scroll_bar_pos': req.args.get('scroll_bar_pos', ''),
'diff': None,
'permission_v':page.permission_v,
'permission_w':page.permission_w,
'admin_or_creator':page.admin_or_creator,
'edit_perm':page.edit_perm,
'page_exist':page.page_exist
})
if action in ('diff', 'merge'):
old_text = original_text and original_text.splitlines() or []
new_text = page.text and page.text.splitlines() or []
diff_data, changes = self._prepare_diff(
req, page, old_text, new_text, page.version, '')
data.update({'diff': diff_data, 'changes': changes,
'action': 'preview', 'merge': action == 'merge',
'longcol': 'Version', 'shortcol': 'v'})
elif sidebyside and action != 'collision':
data['action'] = 'preview'
self._wiki_ctxtnav(req, page)
Chrome(self.env).add_wiki_toolbars(req)
Chrome(self.env).add_auto_preview(req)
return 'wiki_edit.html', data, None
示例8: _new_blog_post
# 需要导入模块: from trac.wiki.model import WikiPage [as 别名]
# 或者: from trac.wiki.model.WikiPage import readonly [as 别名]
def _new_blog_post(self, req):
""" Generate a new blog post """
action = req.args.get('action', 'edit')
wikitext = req.args.get('text', '')
blogtitle = req.args.get('blogtitle', '')
page_format = req.args.get('pagename', self.page_format)
tags = self._get_tags(req)
referer = self._get_referer(req)
author = req.authname
pagename = self._generate_pagename(page_format, blogtitle, author)
titleline = ' '.join(["=", blogtitle, "=\n"])
page = WikiPage(self.env, pagename, None)
page.text = wikitext
comment = req.args.get('comment', '')
readonly = int(req.args.has_key('readonly'))
edit_rows = req.args.get('edit_rows', '20')
scroll_bar_pos = req.args.get('scroll_bar_pos', '')
page_source = page.text
if blogtitle:
wikitext = ''.join([titleline, wikitext])
if req.method == 'POST':
if action == 'edit':
if req.args.has_key('cancel'):
req.redirect(referer)
page = WikiPage(self.env, pagename, None)
tagsystem = TagSystem(self.env)
# Add footer
page.text = ''.join([wikitext, "\n\n", self.var_subs(author, self.footer)])
page.readonly = readonly
if req.args.has_key('preview'):
action = 'preview'
else:
page.save(author, comment, req.remote_addr)
tagsystem.set_tags(req, page.resource, tags)
req.redirect(referer)
wiki = {'page_name' : pagename,
'comment' : comment,
'author' : author,
'edit_rows' : edit_rows,
'version' : 0,
'read_only' : readonly,
'scroll_bar_pos' : scroll_bar_pos,
'page_source' : page_source,
'action' : action,
}
data = {'page' : page,
'action' : action,
'title' : self.entry_page_title,
'blog' : {'title' : blogtitle,
'pagename' : pagename,
'referer' : referer,
},
'tags' : ', '.join(tags),
'referer' : referer,
}
data.update(wiki)
return data