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


Python TagEngine.add_tags方法代码示例

本文整理汇总了Python中tractags.api.TagEngine.add_tags方法的典型用法代码示例。如果您正苦于以下问题:Python TagEngine.add_tags方法的具体用法?Python TagEngine.add_tags怎么用?Python TagEngine.add_tags使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tractags.api.TagEngine的用法示例。


在下文中一共展示了TagEngine.add_tags方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: set_password

# 需要导入模块: from tractags.api import TagEngine [as 别名]
# 或者: from tractags.api.TagEngine import add_tags [as 别名]
    def set_password(self, user, password):
        import re

        if len(user) < 3:
            raise TracError("user name must be at least 3 characters long")
        if not re.match(r"^\w+$", user):
            raise TracError("user name must consist only of alpha-numeric characters")
        if user not in self.get_users():
            from trac.wiki.model import WikiPage

            db = self.env.get_db_cnx()
            page = WikiPage(self.env, user, db=db)
            # User creation with existing page
            if page.exists:
                raise TracError('wiki page "%s" already exists' % user)
            else:
                from tractags.api import TagEngine

                tagspace = TagEngine(self.env).tagspace.wiki

                tagspace.add_tags(None, user, ["user"])
                page.text = """= %(user)s =\n\n[[ListTagged(%(user)s)]]\n\n[[TagIt(user)]]""" % {"user": user}
                page.save(user, "New user %s registered" % user, None)
                self.env.log.debug("New user %s registered" % user)
        HtPasswdStore.set_password(self, user, password)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:27,代码来源:trachacks.py

示例2: _new_blog_post

# 需要导入模块: from tractags.api import TagEngine [as 别名]
# 或者: from tractags.api.TagEngine import add_tags [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


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