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


Python DBSession.query方法代码示例

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


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

示例1: edit

# 需要导入模块: from tagger.model import DBSession [as 别名]
# 或者: from tagger.model.DBSession import query [as 别名]
    def edit(self, linkid, **kwargs):
        """Display a EDIT form."""
        tmpl_context.form = f_edit
        lang = tmpl_context.lang
        link = DBSession.query(Link).get(linkid.decode())

        tags = ', '.join([t.name[lang] for t in link.tags])
        fargs = dict(linkid=link.id, id_=link.id,
                     uri=link.uri,
                     languageid=link.language_id,
                     version=link.version,
                     modified=link.data[0].modified,
                     name=link.name[''],
                     description=link.description[''],
                     tagids=tags,
                    )

        languages = [(l.id, l.name) for l in DBSession.query(Language)]

        data = link.data[0]
        DataHistory = data.__history_mapper__.class_
        query = DBSession.query(DataHistory).filter_by(id=data.id)
        versions = range(query.count(), 0, -1)
        versions.insert(0, int(data.version))

        fcargs = dict(
            languageid=dict(options=languages),
            version=dict(options=versions),
            )
        return dict(title='%s %s' % (_('Edit link:'), link.id),
                                                args=fargs, child_args=fcargs)
开发者ID:lento,项目名称:tagger,代码行数:33,代码来源:link.py

示例2: edit

# 需要导入模块: from tagger.model import DBSession [as 别名]
# 或者: from tagger.model.DBSession import query [as 别名]
    def edit(self, articleid, pagestringid, **kwargs):
        """Display a EDIT form."""
        tmpl_context.form = f_edit
        article = DBSession.query(Article).get(articleid.decode())
        page = article.pages[pagestringid]

        fargs = dict(pageid=page.id, id_=page.id,
                     languageid=page.language_id,
                     version=page.version,
                     modified=page.data[0].modified,
                     name=page.name[''],
                     text=page.text[''],
                    )

        languages = [(l.id, l.name) for l in DBSession.query(Language)]

        data = page.data[0]
        DataHistory = data.__history_mapper__.class_
        query = DBSession.query(DataHistory).filter_by(id=data.id)
        versions = range(query.count(), 0, -1)
        versions.insert(0, int(data.version))

        fcargs = dict(
            languageid=dict(options=languages),
            version=dict(options=versions),
            )
        return dict(title='%s %s' % (_('Edit page:'), page.string_id),
                                                args=fargs, child_args=fcargs)
开发者ID:lento,项目名称:tagger,代码行数:30,代码来源:page.py

示例3: get_all

# 需要导入模块: from tagger.model import DBSession [as 别名]
# 或者: from tagger.model.DBSession import query [as 别名]
    def get_all(self, tag=[], max_results=None, mode='all'):
        """Return a list of links"""
        settings = dict([(s.id, s.value) for s in DBSession.query(Setting)])
        if max_results is None:
            max_results = int(settings.get('max_results', 0))
        else:
            max_results = int(max_results)

        tmpl_context.w_object_title = w_object_title
        tmpl_context.w_link = w_link
        query = DBSession.query(Link)
        query = query.join(Link.associable).filter_by(published=True)
        query = query.order_by(desc(Link.created))

        tot_results = query.count()
        if max_results:
            links = query[0:max_results]
            more_results = max(tot_results - max_results, 0)
        else:
            links = query.all()
            more_results = False

        if tag:
            tagids = isinstance(tag, list) and tag or [tag]
            tagstring = ', '.join(tagids)
            tags = set(tags_from_string(tagstring, create=False))
            if mode == 'all':
                links = [obj for obj in links if set(obj.tags) >= (tags)]
            elif mode == 'any':
                links = [obj for obj in links if set(obj.tags) & (tags)]

        return dict(links=links, recent=find_recent(), path=('links', ''),
                                                    more_results=more_results)
开发者ID:lento,项目名称:tagger,代码行数:35,代码来源:link.py

示例4: settings

# 需要导入模块: from tagger.model import DBSession [as 别名]
# 或者: from tagger.model.DBSession import query [as 别名]
    def settings(self):
        """Return a form to edit settings"""
        tmpl_context.f_settings = f_settings
        lang = tmpl_context.lang

        query = DBSession.query(Setting)
        settings = dict([('v_%s' % s.id, s.value) for s in query])
        fargs = settings

        querymedia = DBSession.query(Media).filter_by(type=u'image')
        media_list = [('', '')]
        media_list.extend([(m.id, m.name[lang]) for m in querymedia])
        link_list = [('', '')]
        link_list.extend([(l.id, l.name[lang]) for l in DBSession.query(Link)])
        cc_list = [
            ('', ''),
            ('cc by', 'CC Attribution'),
            ('cc by-sa', 'CC Attribution Share Alike'),
            ('cc by-nd', 'CC Attribution No Derivatives'),
            ('cc by-nc', 'CC Attribution Non-Commercial'),
            ('cc by-nc-sa', 'CC Attribution Non-Commercial Share Alike'),
            ('cc by-nc-nd', 'CC Attribution Non-Commercial No Derivatives'),
        ]
        fcargs = dict(v_logo_media=dict(options=media_list),
                      v_banner_media=dict(options=media_list),
                      v_banner_link=dict(options=link_list),
                      v_theme = dict(options=G.themes),
                      v_cc = dict(options=cc_list),
                     )
        return dict(args=fargs, child_args=fcargs, path=('admin', 'settings'))
开发者ID:lento,项目名称:tagger,代码行数:32,代码来源:admin.py

示例5: put

# 需要导入模块: from tagger.model import DBSession [as 别名]
# 或者: from tagger.model.DBSession import query [as 别名]
    def put(self, linkid, name, uri, languageid, description=None, tagids=None,
                                                version=None, modified=None):
        """Edit a link"""
        lang = tmpl_context.lang or DBSession.query(Language).first().id
        link = DBSession.query(Link).get(linkid.decode())

        modified = False
        if link.uri != uri:
            link.uri = uri
            modified = True

        if link.name[languageid] != name:
            link.name[languageid] = name
            modified = True

        if link.description[languageid] != description:
            link.description[languageid] = description
            modified = True

        tags = tags_from_string(tagids, lang=lang)
        if link.tags != tags:
            link.tags[:] = tags
            modified = True

        if modified:
            link.data[languageid].modified = datetime.datetime.now()
            flash('%s %s' % (_('Updated Link:'), link.id), 'ok')
        else:
            flash('%s %s' % (_('Link is unchanged:'), link.id), 'info')
        return dict(redirect_to=url('/admin/link/'))
开发者ID:lento,项目名称:tagger,代码行数:32,代码来源:link.py

示例6: new

# 需要导入模块: from tagger.model import DBSession [as 别名]
# 或者: from tagger.model.DBSession import query [as 别名]
    def new(self, articleid, **kwargs):
        """Display a NEW form."""
        tmpl_context.form = f_new
        article = DBSession.query(Article).get(articleid.decode())

        fargs = dict(articleid=article.id)
        lang_list = [(l.id, l.name) for l in DBSession.query(Language)]
        fcargs = dict(languageid=dict(options=lang_list))
        return dict(title=_('Create a new Page'), args=fargs, child_args=fcargs)
开发者ID:lento,项目名称:tagger,代码行数:11,代码来源:page.py

示例7: edit

# 需要导入模块: from tagger.model import DBSession [as 别名]
# 或者: from tagger.model.DBSession import query [as 别名]
 def edit(self, tagid, **kwargs):
     """Display a EDIT form."""
     tmpl_context.form = f_edit
     tag = DBSession.query(Tag).get(tagid.decode())
     fargs = dict(tagid=tag.id, id_=tag.id,
                  languageid=tag.language_id,
                  name=tag.name[''],
                 )
     languages = [(l.id, l.name) for l in DBSession.query(Language)]
     fcargs = dict(languageid=dict(options=languages))
     return dict(title='%s %s' % (_('Edit tag:'), tag.id),
                                             args=fargs, child_args=fcargs)
开发者ID:lento,项目名称:tagger,代码行数:14,代码来源:tag.py

示例8: new

# 需要导入模块: from tagger.model import DBSession [as 别名]
# 或者: from tagger.model.DBSession import query [as 别名]
    def new(self, **kwargs):
        """Display a NEW form."""
        tmpl_context.form = f_new
        lang = tmpl_context.lang

        fargs = dict()
        
        cat_list = [(c.id, c.name[lang]) for c in DBSession.query(Category)]
        lang_list = [(l.id, l.name) for l in DBSession.query(Language)]
        fcargs = dict(categoryid=dict(options=cat_list),
                                            languageid=dict(options=lang_list))
        return dict(title=_('Create a new Article'),
                                                args=fargs, child_args=fcargs)
开发者ID:lento,项目名称:tagger,代码行数:15,代码来源:article.py

示例9: post

# 需要导入模块: from tagger.model import DBSession [as 别名]
# 或者: from tagger.model.DBSession import query [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

示例10: edit

# 需要导入模块: from tagger.model import DBSession [as 别名]
# 或者: from tagger.model.DBSession import query [as 别名]
 def edit(self, categoryid, **kwargs):
     """Display a EDIT form."""
     tmpl_context.form = f_edit
     lang = tmpl_context.lang
     category = DBSession.query(Category).get(categoryid.decode())
     fargs = dict(categoryid=category.id, id_=category.id,
                  languageid=category.language_id,
                  name=category.name[lang],
                  description=category.description[lang])
     languages = [(l.id, l.name) for l in DBSession.query(Language)]
     fcargs = dict(languageid=dict(options=languages))
     return dict(title='%s %s' % (_('Edit Category:'), category.id),
                                             args=fargs, child_args=fcargs)
开发者ID:lento,项目名称:tagger,代码行数:15,代码来源:category.py

示例11: get_page

# 需要导入模块: from tagger.model import DBSession [as 别名]
# 或者: from tagger.model.DBSession import query [as 别名]
def get_page(pageid):
    """Return a page given its id or its article/string_id path"""
    try:
        if isinstance(pageid, int) or pageid.isdigit():
            page = DBSession.query(Page).get(pageid)
        elif '/' in pageid:
            articleid, pageid = pageid.split('/')
            query = DBSession.query(Page)
            query = query.filter_by(string_id=pageid, article_id=articleid)
            page = query.one()
        else:
            page = None
    except NoResultFound, MultipleResultsFound:
        page = None
开发者ID:lento,项目名称:tagger,代码行数:16,代码来源:helpers.py

示例12: post_delete

# 需要导入模块: from tagger.model import DBSession [as 别名]
# 或者: from tagger.model.DBSession import query [as 别名]
    def post_delete(self, languageid):
        """Delete a Language"""
        language = DBSession.query(Language).get(languageid.decode())

        DBSession.delete(language)
        flash('%s %s' % (_('Deleted Language:'), language.id), 'ok')
        return dict(redirect_to=url('/admin/language/'))
开发者ID:lento,项目名称:tagger,代码行数:9,代码来源:language.py

示例13: post

# 需要导入模块: from tagger.model import DBSession [as 别名]
# 或者: from tagger.model.DBSession import query [as 别名]
 def post(self, associableid, name, email, text, came_from='/'):
     """create a new Comment"""
     associable = DBSession.query(Associable).get(associableid)
     comment = Comment(name, email, text)
     associable.comments.append(comment)
     flash('%s %s' % (_('Created Comment:'), comment.header), 'ok')
     return dict(redirect_to=url(came_from))
开发者ID:lento,项目名称:tagger,代码行数:9,代码来源:comment.py

示例14: spam

# 需要导入模块: from tagger.model import DBSession [as 别名]
# 或者: from tagger.model.DBSession import query [as 别名]
    def spam(self, commentid):
        """Mark a comment as spam"""
        comment = DBSession.query(Comment).get(commentid)

        comment.status = 'spam'
        flash('%s %s' % (_('Comment marked as spam:'), comment.id), 'ok')
        redirect(url('/admin/comment'))
开发者ID:lento,项目名称:tagger,代码行数:9,代码来源:comment.py

示例15: revoke

# 需要导入模块: from tagger.model import DBSession [as 别名]
# 或者: from tagger.model.DBSession import query [as 别名]
    def revoke(self, commentid):
        """Revoke comment approval and make it invisible"""
        comment = DBSession.query(Comment).get(commentid)

        comment.status = 'waiting'
        flash('%s %s' % (_('Revoked approval for Comment:'), comment.id), 'ok')
        redirect(url('/admin/comment'))
开发者ID:lento,项目名称:tagger,代码行数:9,代码来源:comment.py


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