当前位置: 首页>>代码示例>>Python>>正文


Python WikiPage.readonly方法代码示例

本文整理汇总了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)
开发者ID:CGI-define-and-primeportal,项目名称:trac-plugin-createtemplate,代码行数:28,代码来源:importer.py

示例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
开发者ID:gdgkyoto,项目名称:kyoto-gtug,代码行数:56,代码来源:web_ui.py

示例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
开发者ID:nextview,项目名称:tracxmlrpc,代码行数:18,代码来源:wiki.py

示例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
开发者ID:Puppet-Finland,项目名称:trac,代码行数:20,代码来源:wiki.py

示例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
开发者ID:Stackato-Apps,项目名称:bloodhound,代码行数:84,代码来源:web_ui.py

示例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
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:67,代码来源:new_blog.py

示例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
开发者ID:zjj,项目名称:trac_hack,代码行数:81,代码来源:web_ui.py

示例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
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:66,代码来源:new_blog.py


注:本文中的trac.wiki.model.WikiPage.readonly方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。