本文整理汇总了Python中mediagoblin.db.base.Session.query方法的典型用法代码示例。如果您正苦于以下问题:Python Session.query方法的具体用法?Python Session.query怎么用?Python Session.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mediagoblin.db.base.Session
的用法示例。
在下文中一共展示了Session.query方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_media_slug_used
# 需要导入模块: from mediagoblin.db.base import Session [as 别名]
# 或者: from mediagoblin.db.base.Session import query [as 别名]
def check_media_slug_used(dummy_db, uploader_id, slug, ignore_m_id):
filt = (MediaEntry.uploader == uploader_id) \
& (MediaEntry.slug == slug)
if ignore_m_id is not None:
filt = filt & (MediaEntry.id != ignore_m_id)
does_exist = Session.query(MediaEntry.id).filter(filt).first() is not None
return does_exist
示例2: check_collection_slug_used
# 需要导入模块: from mediagoblin.db.base import Session [as 别名]
# 或者: from mediagoblin.db.base.Session import query [as 别名]
def check_collection_slug_used(creator_id, slug, ignore_c_id):
filt = (Collection.creator == creator_id) \
& (Collection.slug == slug)
if ignore_c_id is not None:
filt = filt & (Collection.id != ignore_c_id)
does_exist = Session.query(Collection.id).filter(filt).first() is not None
return does_exist
示例3: clean_orphan_tags
# 需要导入模块: from mediagoblin.db.base import Session [as 别名]
# 或者: from mediagoblin.db.base.Session import query [as 别名]
def clean_orphan_tags(commit=True):
"""Search for unused MediaTags and delete them"""
q1 = Session.query(Tag).outerjoin(MediaTag).filter(MediaTag.id==None)
for t in q1:
Session.delete(t)
# The "let the db do all the work" version:
# q1 = Session.query(Tag.id).outerjoin(MediaTag).filter(MediaTag.id==None)
# q2 = Session.query(Tag).filter(Tag.id.in_(q1))
# q2.delete(synchronize_session = False)
if commit:
Session.commit()
示例4: get_all_blogposts_of_blog
# 需要导入模块: from mediagoblin.db.base import Session [as 别名]
# 或者: from mediagoblin.db.base.Session import query [as 别名]
def get_all_blogposts_of_blog(request, blog, state=None):
"""Return all blog posts (and metadata) of a blog as query object"""
# TODO: I would simply make this function a method of the Blog() class.
# next line is just providing shortcuts
MediaEntry, BlogPostData = request.db.MediaEntry, request.db.BlogPostData
blog_posts = Session.query(MediaEntry).join(BlogPostData)\
.filter(BlogPostData.blog == blog.id)
if state is not None:
blog_posts = blog_posts.filter(MediaEntry.state==state)
# we could return the metadata (blog_posts_meta) here too and save some queries later
return blog_posts
示例5: media_data_init
# 需要导入模块: from mediagoblin.db.base import Session [as 别名]
# 或者: from mediagoblin.db.base.Session import query [as 别名]
def media_data_init(self, **kwargs):
"""
Initialize or update the contents of a media entry's media_data row
"""
session = Session()
media_data = session.query(self.media_data_table).filter_by(
media_entry=self.id).first()
# No media data, so actually add a new one
if media_data is None:
media_data = self.media_data_table(
media_entry=self.id,
**kwargs)
session.add(media_data)
# Update old media data
else:
for field, value in kwargs.iteritems():
setattr(media_data, field, value)
示例6: get_all_blog_posts
# 需要导入模块: from mediagoblin.db.base import Session [as 别名]
# 或者: from mediagoblin.db.base.Session import query [as 别名]
def get_all_blog_posts(self, state=None):
blog_posts = Session.query(MediaEntry).join(BlogPostData)\
.filter(BlogPostData.blog == self.id)
if state is not None:
blog_posts = blog_posts.filter(MediaEntry.state==state)
return blog_posts
示例7: media_data
# 需要导入模块: from mediagoblin.db.base import Session [as 别名]
# 或者: from mediagoblin.db.base.Session import query [as 别名]
def media_data(self):
session = Session()
return session.query(self.media_data_table).filter_by(
media_entry=self.id).first()