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


Python DBSession.add方法代码示例

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


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

示例1: test_banner_set

# 需要导入模块: from tagger.model import DBSession [as 别名]
# 或者: from tagger.model.DBSession import add [as 别名]
    def test_banner_set(self):
        """controllers.admin.Controller.banner_set is working properly"""
        languageid, tadm = self._fill_db()
        media = Media(u'image', u'test image', u'/test.png', tadm, u'xx',
                                                                u'random text')
        DBSession.add(media)
        link = Link(u'test link', u'http://example.com', tadm, u'xx',
                                                                u'random text')
        DBSession.add(link)
        DBSession.flush()
        mediaid = media.id
        linkid = link.id
        transaction.commit()
        
        environ = {'REMOTE_USER': 'test_admin'}
        response = self.app.post('/admin/banner_set',
                                            dict(mediaid=mediaid,
                                                 linkid=linkid,
                                                ),
                                            extra_environ=environ, status=302)
        #redirected = response.follow(extra_environ=environ, status=200)

        bc = DBSession.query(BannerContent).first()
        eq_(bc.media_id, mediaid)
        eq_(bc.link_id, linkid)
开发者ID:lento,项目名称:tagger,代码行数:27,代码来源:test_admin.py

示例2: _fill_db

# 需要导入模块: from tagger.model import DBSession [as 别名]
# 或者: from tagger.model.DBSession import add [as 别名]
 def _fill_db(self):
     language = Language(u'xx', u'test language')
     DBSession.add(language)
     DBSession.flush()
     languageid = language.id
     transaction.commit()
     return languageid.encode()
开发者ID:lento,项目名称:tagger,代码行数:9,代码来源:test_language.py

示例3: test_comment

# 需要导入模块: from tagger.model import DBSession [as 别名]
# 或者: from tagger.model.DBSession import add [as 别名]
    def test_comment(self):
        """controllers.admin.Controller.comment is working properly"""
        languageid, tadm = self._fill_db()
        comment = Comment(u'anonymous', u'[email protected]', u'test comment')
        DBSession.add(comment)
        DBSession.flush()
        commentid = comment.id
        transaction.commit()
        
        environ = {'REMOTE_USER': 'test_admin'}
        response = self.app.get('/admin/comment/', extra_environ=environ,
                                                                    status=200)

        tr = response.html.table('tr')[1]
        # Date
        eq_(str(tr('td')[1]), '<td>%s</td>' % commentid)
        eq_(str(tr('td')[2]), '<td></td>')
        eq_(str(tr('td')[3]), '<td>anonymous</td>')
        eq_(str(tr('td')[4]), '<td>[email protected]</td>')
        eq_(str(tr('td')[5]), '<td>test comment</td>')
        # Status
        actions = tr('td')[7]
        eq_(str(actions('a')[0]['class']), 'icon edit overlay')
        eq_(str(actions('a')[1]['class']), 'icon delete overlay')
        eq_(str(actions('a')[2]['class']), 'icon approve')
        eq_(str(actions('a')[3]['class']), 'icon spam')
开发者ID:lento,项目名称:tagger,代码行数:28,代码来源:test_admin.py

示例4: post

# 需要导入模块: from tagger.model import DBSession [as 别名]
# 或者: from tagger.model.DBSession import add [as 别名]
 def post(self, name, languageid):
     """create a new Tag"""
     user = tmpl_context.user
     tag = Tag(name, languageid)
     DBSession.add(tag)
     flash('%s %s' % (_('Created Tag:'), tag.id), 'ok')
     return dict(redirect_to=url('/admin/tag/'))
开发者ID:lento,项目名称:tagger,代码行数:9,代码来源:tag.py

示例5: test_article

# 需要导入模块: from tagger.model import DBSession [as 别名]
# 或者: from tagger.model.DBSession import add [as 别名]
    def test_article(self):
        """controllers.admin.Controller.article is working properly"""
        languageid, tadm = self._fill_db()
        cat = Category(u'test_category', u'xx')
        DBSession.add(cat)
        article = Article(u'A Test Article!', cat, u'xx', tadm, u'random text')
        DBSession.add(article)
        DBSession.flush()
        categoryid = cat.id
        articleid = article.id
        transaction.commit()

        environ = {'REMOTE_USER': 'test_admin'}
        response = self.app.get('/admin/article/', extra_environ=environ,
                                                                    status=200)

        tr = response.html.table.find('tr', articleid)
        # Date
        eq_(str(tr('td')[1]), '<td>test_category</td>')
        eq_(str(tr('td')[2]), '<td>%s</td>' % articleid)
        eq_(str(tr('td')[3]), '<td>A Test Article!</td>')
        eq_(str(tr('td')[4]), '<td></td>')
        eq_(str(tr('td')[5]), '<td>%s</td>' % languageid)
        # Status
        actions = tr('td')[7]
        eq_(str(actions('a')[0]['class']), 'icon edit')
        eq_(str(actions('a')[1]['class']), 'icon delete overlay')
        eq_(str(actions('a')[2]['class']), 'icon publish')
开发者ID:lento,项目名称:tagger,代码行数:30,代码来源:test_admin.py

示例6: _fill_db

# 需要导入模块: from tagger.model import DBSession [as 别名]
# 或者: from tagger.model.DBSession import add [as 别名]
 def _fill_db(self):
     tadm = DBSession.query(User).filter_by(user_name=u'test_admin').one()
     language = Language(u'xx', u'test language')
     DBSession.add(language)
     DBSession.flush()
     languageid = language.id
     return languageid, tadm
开发者ID:lento,项目名称:tagger,代码行数:9,代码来源:test_admin.py

示例7: do_get_dependencies

# 需要导入模块: from tagger.model import DBSession [as 别名]
# 或者: from tagger.model.DBSession import add [as 别名]
 def do_get_dependencies(self):
     try:
         self.language = content.Language(id=u'xx', name=u'test_lang')
         DBSession.add(self.language)
         DBSession.flush()
         return dict(lang=self.language.id,
                    )
     except:
         DBSession.rollback()
         raise
开发者ID:lento,项目名称:tagger,代码行数:12,代码来源:test_content.py

示例8: _fill_db

# 需要导入模块: from tagger.model import DBSession [as 别名]
# 或者: from tagger.model.DBSession import add [as 别名]
 def _fill_db(self):
     language = Language(u'xx', u'test_langugage')
     DBSession.add(language)
     cat = Category(u'test category', u'xx', u'a test category')
     DBSession.add(cat)
     DBSession.flush()
     languageid = language.id
     categoryid = cat.id
     transaction.commit()
     return languageid, categoryid.encode()
开发者ID:lento,项目名称:tagger,代码行数:12,代码来源:test_category.py

示例9: _fill_db

# 需要导入模块: from tagger.model import DBSession [as 别名]
# 或者: from tagger.model.DBSession import add [as 别名]
 def _fill_db(self):
     language = Language(u'xx', u'test_langugage')
     DBSession.add(language)
     tag = Tag(u'test tag', u'xx')
     DBSession.add(tag)
     DBSession.flush()
     languageid = language.id
     tagid = tag.id
     transaction.commit()
     return languageid, tagid.encode()
开发者ID:lento,项目名称:tagger,代码行数:12,代码来源:test_tag.py

示例10: post

# 需要导入模块: from tagger.model import DBSession [as 别名]
# 或者: from tagger.model.DBSession import add [as 别名]
    def post(self, name, uri, languageid, description=None, tagids=None):
        """create a new Link"""
        user = tmpl_context.user
        lang = tmpl_context.lang or DBSession.query(Language).first().id
        link = Link(name, uri, user, languageid, description)
        DBSession.add(link)

        tags = tags_from_string(tagids, lang=lang)
        link.tags[:] = tags

        flash('%s %s' % (_('Created Link:'), link.id), 'ok')
        return dict(redirect_to=url('/admin/link/'))
开发者ID:lento,项目名称:tagger,代码行数:14,代码来源:link.py

示例11: post

# 需要导入模块: from tagger.model import DBSession [as 别名]
# 或者: from tagger.model.DBSession import add [as 别名]
    def post(self, title, categoryid, languageid, text=None, tagids=None):
        """create a new Article"""
        user = tmpl_context.user
        lang = tmpl_context.lang or DBSession.query(Language).first().id
        category = DBSession.query(Category).get(categoryid)
        article = Article(title, category, languageid, user, text)
        DBSession.add(article)

        tags = tags_from_string(tagids, lang=lang)
        article.tags[:] = tags

        flash('%s %s' % (_('Created Article:'), article.id), 'ok')
        return dict(redirect_to=url('/admin/article/'))
开发者ID:lento,项目名称:tagger,代码行数:15,代码来源:article.py

示例12: tags_from_string

# 需要导入模块: from tagger.model import DBSession [as 别名]
# 或者: from tagger.model.DBSession import add [as 别名]
def tags_from_string(s, create=True, lang=None):
    if lang is None:
        lang = DBSession.query(Language).first().id
    alltags = dict([(t.id, t) for t in DBSession.query(Tag)])
    alltagsdata = dict([(d.name, d) for d in DBSession.query(TagData)])
    tagnames = s and s.split(', ') or []
    tags = []
    for tagname in tagnames:
        if tagname in alltags:
            tag = alltags[tagname]
        elif tagname in alltagsdata:
            tag = alltagsdata[tagname].parent
        elif create:
            tag = Tag(tagname, lang)
            DBSession.add(tag)
        tags.append(tag)
    return tags
开发者ID:lento,项目名称:tagger,代码行数:19,代码来源:helpers.py

示例13: test_tag

# 需要导入模块: from tagger.model import DBSession [as 别名]
# 或者: from tagger.model.DBSession import add [as 别名]
    def test_tag(self):
        """controllers.admin.Controller.tag is working properly"""
        languageid, tadm = self._fill_db()
        tag = Tag(u'test tag', u'xx')
        DBSession.add(tag)
        DBSession.flush()
        tagid = tag.id
        transaction.commit()
        
        environ = {'REMOTE_USER': 'test_admin'}
        response = self.app.get('/admin/tag/', extra_environ=environ,
                                                                    status=200)

        tr = response.html.table('tr')[1]
        eq_(str(tr('td')[0]), '<td>%s</td>' % tagid)
        eq_(str(tr('td')[1]), '<td>test tag</td>')
        eq_(str(tr('td')[2]), '<td>%s</td>' % languageid)
        actions = tr('td')[3]
        eq_(str(actions('a')[0]['class']), 'icon edit overlay')
        eq_(str(actions('a')[1]['class']), 'icon delete overlay')
开发者ID:lento,项目名称:tagger,代码行数:22,代码来源:test_admin.py

示例14: test_category

# 需要导入模块: from tagger.model import DBSession [as 别名]
# 或者: from tagger.model.DBSession import add [as 别名]
    def test_category(self):
        """controllers.admin.Controller.category is working properly"""
        languageid, tadm = self._fill_db()
        category = Category(u'test category', u'xx', u'a test category')
        DBSession.add(category)
        DBSession.flush()
        categoryid = category.id
        transaction.commit()

        environ = {'REMOTE_USER': 'test_admin'}
        response = self.app.get('/admin/category/', extra_environ=environ,
                                                                    status=200)
        
        tr = response.html.table.find('tr', categoryid)
        eq_(str(tr('td')[0]), '<td>%s</td>' % categoryid)
        eq_(str(tr('td')[1]), '<td>test category</td>')
        eq_(str(tr('td')[2]), '<td>a test category</td>')
        eq_(str(tr('td')[3]), '<td>%s</td>' % languageid)
        actions = tr('td')[4]
        eq_(str(actions('a')[0]['class']), 'icon edit overlay')
        eq_(str(actions('a')[1]['class']), 'icon delete overlay')
开发者ID:lento,项目名称:tagger,代码行数:23,代码来源:test_admin.py

示例15: settings_set

# 需要导入模块: from tagger.model import DBSession [as 别名]
# 或者: from tagger.model.DBSession import add [as 别名]
    def settings_set(self, name=None, value=None):
        """Set settings values"""
        query = DBSession.query(Setting)
        settings = dict([(s.id, s) for s in query])
        if not len(name) == len(value):
            raise HTTPBadRequest("names and values don't match")

        modified = False
        for n, v in zip(name, value):
            if n in settings:
                if not settings[n].value == v:
                    settings[n].value = v
                    modified = True
            else:
                DBSession.add(Setting(n, v))
                modified = True

        if modified:
            flash(_('Updated Settings'), 'ok')
        else:
            flash(_('Settings are unchanged'), 'info')
        redirect(url('/admin/settings/'))
开发者ID:lento,项目名称:tagger,代码行数:24,代码来源:admin.py


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