本文整理汇总了Python中mediacore.model.DBSession.query方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.query方法的具体用法?Python DBSession.query怎么用?Python DBSession.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mediacore.model.DBSession
的用法示例。
在下文中一共展示了DBSession.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import query [as 别名]
def index(self, page=1, search=None, podcast_filter=None, **kwargs):
"""List media with pagination and filtering.
:param page: Page number, defaults to 1.
:type page: int
:param search: Optional search term to filter by
:type search: unicode or None
:param podcast_filter: Optional podcast to filter by
:type podcast_filter: int or None
:rtype: dict
:returns:
media
The list of :class:`~mediacore.model.media.Media` instances
for this page.
search
The given search term, if any
search_form
The :class:`~mediacore.forms.admin.SearchForm` instance
podcast_filter
The given podcast ID to filter by, if any
podcast_filter_title
The podcast name for rendering if a ``podcast_filter`` was specified.
podcast_filter_form
The :class:`~mediacore.forms.media.PodcastFilterForm` instance.
"""
media = DBSession.query(Media)\
.filter(Media.status.excludes('trash'))\
.options(orm.undefer('comment_count_published'))\
.options(orm.undefer('comment_count_unreviewed'))\
.order_by(Media.status.desc(),
Media.publish_on.desc(),
Media.modified_on.desc())
if search is not None:
like_search = '%' + search + '%'
media = media.filter(sql.or_(
Media.title.like(like_search),
Media.description.like(like_search),
Media.notes.like(like_search),
Media.tags.any(Tag.name.like(like_search)),
))
podcast_filter_title = podcast_filter
if podcast_filter == 'Unfiled':
media = media.filter(~Media.podcast.has())
elif podcast_filter is not None and podcast_filter != 'All Media':
media = media.filter(Media.podcast.has(Podcast.id == podcast_filter))
podcast_filter_title = DBSession.query(Podcast.title).get(podcast_filter)
podcast_filter = int(podcast_filter)
return dict(
media = media,
podcast_filter = podcast_filter,
podcast_filter_title = podcast_filter_title,
podcast_filter_form = podcast_filter_form,
search = search,
search_form = search_form,
)
示例2: index
# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import query [as 别名]
def index(self, page=1, **kwargs):
"""List podcasts and podcast media.
Our custom paginate decorator allows us to have fewer podcast episodes
display on the first page than on the rest with the ``items_first_page``
param. See :class:`mediacore.lib.custompaginate.CustomPage`.
:param page: Page number, defaults to 1.
:type page: int
:rtype: dict
:returns:
podcasts
The :class:`~mediacore.model.podcasts.Podcast` instance
episodes
The list of :class:`~mediacore.model.media.Media` instances
for this page.
"""
episodes = (
DBSession.query(Media)
.filter(Media.podcast_id != None)
.order_by(Media.publish_on.desc())
.options(orm.undefer("comment_count_published"))
)
episodes = self._filter(episodes)
podcasts = DBSession.query(Podcast).options(orm.undefer("published_media_count")).all()
return dict(podcasts=podcasts, episodes=episodes)
示例3: index
# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import query [as 别名]
def index(self, page=1, search=None, media_filter=None, **kwargs):
"""List comments with pagination and filtering.
:param page: Page number, defaults to 1.
:type page: int
:param search: Optional search term to filter by
:type search: unicode or None
:param media_filter: Optional media ID to filter by
:type media_filter: int or None
:rtype: dict
:returns:
comments
The list of :class:`~mediacore.model.comments.Comment` instances
for this page.
edit_form
The :class:`mediacore.forms.comments.EditCommentForm` instance,
to be rendered for each instance in ``comments``.
search
The given search term, if any
search_form
The :class:`~mediacore.forms.admin.SearchForm` instance
media_filter
The given podcast ID to filter by, if any
media_filter_title
The media title for rendering if a ``media_filter`` was specified.
"""
comments = DBSession.query(Comment)\
.filter(Comment.status.excludes('trash'))\
.order_by(Comment.status.desc(), Comment.created_on.desc())
if search is not None:
like_search = '%' + search + '%'
comments = comments.filter(sql.or_(
Comment.subject.like(like_search),
Comment.body.like(like_search),
))
media_filter_title = media_filter
if media_filter is not None:
comments = comments.filter(Comment.media.has(Media.id == media_filter))
media_filter_title = DBSession.query(Media.title).get(media_filter)
media_filter = int(media_filter)
return dict(
comments = comments,
edit_form = edit_form,
media_filter = media_filter,
media_filter_title = media_filter_title,
search = search,
search_form = search_form,
)
示例4: fetch_and_create_tags
# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import query [as 别名]
def fetch_and_create_tags(tag_names):
tag_dict = dict()
for t in tag_names:
tag_dict[slugify(t)] = t
existing_tags = DBSession.query(Tag).filter(Tag.slug.in_(tag_dict.keys())).all()
existing_slugs = [t.slug for t in existing_tags]
new_slugs = [s for s in tag_dict.keys() if s not in existing_slugs]
new_tags = [{'name': tag_dict[s], 'slug': s} for s in new_slugs]
if new_tags:
DBSession.connection().execute(tags.insert(), new_tags)
DBSession.flush()
existing_tags += DBSession.query(Tag).filter(Tag.slug.in_(new_slugs)).all()
return existing_tags
示例5: permissions_for_request
# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import query [as 别名]
def permissions_for_request(cls, environ, config):
identity = environ.get('repoze.who.identity', {})
user_id = identity.get('repoze.who.userid')
user = None
if user_id is not None:
user = DBSession.query(User).filter(User.id==user_id).first()
return cls.permissions_for_user(user, config)
示例6: feed
# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import query [as 别名]
def feed(self, slug, **kwargs):
"""Serve the feed as RSS 2.0.
If :attr:`~mediacore.model.podcasts.Podcast.feedburner_url` is
specified for this podcast, we redirect there.
:param slug: A :attr:`~mediacore.model.podcasts.Podcast.slug`
:param page: Page number, defaults to 1.
:type page: int
:rtype: dict
:returns:
podcast
A :class:`~mediacore.model.podcasts.Podcast` instance.
episodes
A list of :class:`~mediacore.model.media.Media` instances
that belong to the ``podcast``.
podcasts
A list of all the other podcasts
"""
podcast = fetch_row(Podcast, slug=slug)
episodes = self._filter(podcast.media).order_by(Media.publish_on.desc())
podcasts = DBSession.query(Podcast).options(orm.undefer("published_media_count")).all()
return dict(podcast=podcast, episodes=episodes, podcasts=podcasts)
示例7: _published_media_query
# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import query [as 别名]
def _published_media_query(self):
"""Helper method for getting published media"""
return DBSession.query(Media)\
.filter(Media.status >= 'publish')\
.filter(Media.publish_on <= datetime.now())\
.filter(Media.status.excludes('trash'))\
.order_by(Media.publish_on.desc())
示例8: index
# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import query [as 别名]
def index(self, page=1, **kwargs):
"""List storage engines with pagination.
:rtype: Dict
:returns:
engines
The list of :class:`~mediacore.lib.storage.StorageEngine`
instances for this page.
"""
engines = DBSession.query(StorageEngine)\
.options(orm.undefer('file_count'),
orm.undefer('file_size_sum'))\
.all()
engines = list(sort_engines(engines))
existing_types = set(ecls.engine_type for ecls in engines)
addable_engines = [
ecls
for ecls in StorageEngine
if not ecls.is_singleton or ecls.engine_type not in existing_types
]
return {
'engines': engines,
'addable_engines': addable_engines,
}
示例9: test_can_fake_logged_in_user
# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import query [as 别名]
def test_can_fake_logged_in_user(self):
admin = DBSession.query(User).filter(User.user_name==u'admin').one()
assert_true(admin.has_permission(u'admin'))
self.init_fake_request()
self.set_authenticated_user(admin)
assert_true(has_permission(u'admin'))
示例10: index
# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import query [as 别名]
def index(self, page=1, category='topics', **kwargs):
"""List topics or tags with pagination.
:param category: ``topics`` or ``tags``
:param page: Page number, defaults to 1.
:type page: int
:rtype: Dict
:returns:
categories
The list of :class:`~mediacore.model.tags.Tag`
or :class:`~mediacore.model.topics.Topic`
instances for this page.
category
``topics`` or ``tags``
category_name
``Topics`` or ``Tags``
edit_form
The :class:`~mediacore.forms.categories.EditCategoryForm` instance.
"""
model = self.select_model(category)
categories = DBSession.query(model).order_by(model.name)
return dict(
categories = categories,
category = category,
category_name = category.capitalize(),
edit_form = edit_form,
)
示例11: test_can_restrict_query_if_user_does_not_have_the_required_permission
# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import query [as 别名]
def test_can_restrict_query_if_user_does_not_have_the_required_permission(self):
query = Media.query
permission = u'view'
perm = self.perm()
view_permission = DBSession.query(Permission).filter(Permission.permission_name == permission).one()
view_permission.groups = []
DBSession.flush()
assert_none(self.policy.access_condition_for_query(query, permission, perm))
示例12: _to_python
# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import query [as 别名]
def _to_python(self, value, state):
id = request.environ["pylons.routes_dict"]["id"]
query = DBSession.query(User).filter_by(user_name=value)
if id != "new":
query = query.filter(User.user_id != id)
if query.count() != 0:
raise Invalid(_("User name already exists"), value, state)
return value
示例13: _create_user_with_admin_permission_only
# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import query [as 别名]
def _create_user_with_admin_permission_only(self):
admin_perm = DBSession.query(Permission).filter(Permission.permission_name == u'admin').one()
second_admin_group = Group.example(name=u'Second admin group')
admin_perm.groups.append(second_admin_group)
admin = User.example(groups=[second_admin_group])
DBSession.commit()
perm = MediaCorePermissionSystem.permissions_for_user(admin, config)
assert_true(perm.contains_permission(u'admin'))
assert_false(perm.contains_permission(u'edit'))
return admin
示例14: add_custom_profiles
# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import query [as 别名]
def add_custom_profiles():
# Add all the custom profiles to the first existing PandaStorage instance.
from mediacore.model import DBSession
from mediacoreext.simplestation.panda.lib.storage import PandaStorage
ps = DBSession.query(PandaStorage).all()[0]
profiles = ps.panda_helper().client.get_profiles()
pnames = [p['name'] for p in profiles]
for x in custom_profiles:
if x['name'] not in pnames:
ps.panda_helper().client.add_profile_from_preset(**x)
示例15: update_enabled_players
# 需要导入模块: from mediacore.model import DBSession [as 别名]
# 或者: from mediacore.model.DBSession import query [as 别名]
def update_enabled_players():
"""Ensure that the encoding status of all media is up to date with the new
set of enabled players.
The encoding status of Media objects is dependent on there being an
enabled player that supports that format. Call this method after changing
the set of enabled players, to ensure encoding statuses are up to date.
"""
from mediacore.model import DBSession, Media
media = DBSession.query(Media)
for m in media:
m.update_status()