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


Python CachedCall.queryset_details方法代码示例

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


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

示例1: _make_activities

# 需要导入模块: from canvas.cache_patterns import CachedCall [as 别名]
# 或者: from canvas.cache_patterns.CachedCall import queryset_details [as 别名]
    def _make_activities(self, activity_ids, earlier_than=None, later_than=None):
        from apps.activity.models import Activity, LegacyActivity

        def filter_by_ts(query):
            if earlier_than is not None:
                query = query.filter(timestamp__lt=earlier_than)

            if later_than is not None:
                query = query.filter(timestamp__gt=later_than)

            return query

        activity_ids = [int(id_) for id_ in activity_ids]

        activities = Activity.objects.filter(id__in=activity_ids).order_by('-timestamp')
        activities = filter_by_ts(activities)
        activities = CachedCall.queryset_details(activities)

        if len(activities) < len(activity_ids):
            legacy_ids = set(activity_ids) - set(int(activity['id']) for activity in activities)
            legacy_activities = LegacyActivity.objects.filter(id__in=legacy_ids).order_by('-timestamp')
            legacy_activities = filter_by_ts(legacy_activities)
            legacy_activities = CachedCall.queryset_details(legacy_activities)
            activities.extend(legacy_activities)

        ret = []

        for activity_data in activities:
            try:
                ret.append(self._activity_types[activity_data['activity_type']](activity_data))
            except KeyError as e:
                continue

        return ret
开发者ID:MichaelBechHansen,项目名称:drawquest-web,代码行数:36,代码来源:redis_models.py

示例2: gallery_comments

# 需要导入模块: from canvas.cache_patterns import CachedCall [as 别名]
# 或者: from canvas.cache_patterns.CachedCall import queryset_details [as 别名]
def gallery_comments(quest, offset='top', direction='next', force_comment=None, viewer=None,
                     include_reactions=True):
    """
    Returns comments, pagination. Each comment is itself a dict.
    """
    if force_comment is not None:
        newer_comments = QuestComment.objects.filter(parent_comment=quest, id__gt=force_comment.id).order_by('id').values_list('id', flat=True)
        try:
            offset = list(newer_comments[:knobs.COMMENTS_PER_PAGE / 2])[-1]
        except IndexError:
            offset = force_comment.id

    pagination = Paginator(_exclude_flagged(_all_gallery_comments(quest), viewer), knobs.COMMENTS_PER_PAGE, offset=offset, direction=direction)

    comments = pagination.items

    promoter = None if include_reactions else QuestCommentGalleryDetails
    comments = CachedCall.queryset_details(comments, promoter=promoter)

    add_viewer_has_starred_field(comments, viewer=viewer)

    if force_comment is not None and force_comment.id not in [cmt['id'] for cmt in comments]:
        if force_comment.visibility != Visibility.CURATED:
            raise Http404()

        comments.append(force_comment.details())
        comments = sorted(comments, key=lambda cmt: -cmt['id'])

    if viewer is not None and viewer.is_authenticated():
        following = viewer.following_ids()

        for comment in comments:
            comment.user.viewer_is_following = comment.user.id in following

    return comments, pagination
开发者ID:MichaelBechHansen,项目名称:drawquest-web,代码行数:37,代码来源:models.py

示例3: search_stamps

# 需要导入模块: from canvas.cache_patterns import CachedCall [as 别名]
# 或者: from canvas.cache_patterns.CachedCall import queryset_details [as 别名]
def search_stamps(request, query, start):
    """
    Searches the special "stamps" group for stamps that match the search query.

    Returns {comments: [list of comment details]}
    """
    qs = query
    try:
        start = int(start)
    except TypeError:
        raise ServiceError('Invalid "start" parameter.')

    stamps = models.Category.objects.get(name="stamps")
    if qs:
        ids = [x for x in models.Comment.objects.filter(category=stamps).filter(
            Q(reply_text__icontains=qs) | Q(title__icontains=qs)
        ).values_list('id', flat=True)]
        ids = ids[start:start+32]
        comments = models.Comment.curated.exclude(reply_content__id=None).in_bulk(ids)
        details = CachedCall.multicall([comments[id].details for id in ids if id in comments])

    else:
        comments = models.Comment.curated.filter(category=stamps).exclude(reply_content__id=None).order_by('-id')
        comments = comments[start:start+32]
        details = CachedCall.queryset_details(comments)

    return {'comments': details}
开发者ID:StetHD,项目名称:canvas-2,代码行数:29,代码来源:api.py

示例4: test_queryset_details

# 需要导入模块: from canvas.cache_patterns import CachedCall [as 别名]
# 或者: from canvas.cache_patterns.CachedCall import queryset_details [as 别名]
    def test_queryset_details(self):
        comments = [create_comment(reply_content=create_content()) for _ in xrange(10)]
        details1 = CachedCall.multicall([cmt.details for cmt in comments])

        queryset = Comment.objects.filter(id__in=[cmt.id for cmt in comments])
        details2 = CachedCall.queryset_details(queryset)

        self.assertEquals(details1, details2)
开发者ID:MichaelBechHansen,项目名称:drawquest-web,代码行数:10,代码来源:test_cache_patterns.py

示例5: staff_pick_stamps

# 需要导入模块: from canvas.cache_patterns import CachedCall [as 别名]
# 或者: from canvas.cache_patterns.CachedCall import queryset_details [as 别名]
def staff_pick_stamps(request, page):
    page = int(page)
    page_size = 20

    b36_ids = knobs.REMIX_IMAGES_STAFF_PICKS[page*page_size:(page+1)*page_size]

    ids = [util.base36decode(b36_id) for b36_id in b36_ids]

    details = CachedCall.queryset_details(Comment.objects.in_bulk_list(ids))

    return {'comments': details}
开发者ID:StetHD,项目名称:canvas-2,代码行数:13,代码来源:api.py

示例6: ugq_by_user

# 需要导入模块: from canvas.cache_patterns import CachedCall [as 别名]
# 或者: from canvas.cache_patterns.CachedCall import queryset_details [as 别名]
def ugq_by_user(user, offset='top', direction='next', viewer=None):
    quests = Quest.objects.filter(author=user, ugq=True)

    if viewer is not None and viewer.is_authenticated():
        quests = quests.exclude(flags__user=viewer)

    quests = quests.order_by('-id')

    pagination = Paginator(quests, knobs.QUESTS_PER_PAGE, offset=offset, direction=direction)
    quests = pagination.items
    quests = CachedCall.queryset_details(quests)

    return quests, pagination
开发者ID:MichaelBechHansen,项目名称:drawquest-web,代码行数:15,代码来源:models.py

示例7: user_comments

# 需要导入模块: from canvas.cache_patterns import CachedCall [as 别名]
# 或者: from canvas.cache_patterns.CachedCall import queryset_details [as 别名]
def user_comments(request, username, page='top'):
    user = get_object_or_404(User, username=username)
    comments = QuestComment.by_author(user)

    if request.user.id != user.id:
        comments = comments.exclude(visibility=Visibility.CURATED)

    comments = comments[:knobs.COMMENTS_PER_PAGE]
    comments = CachedCall.queryset_details(comments)

    return {
        'comments': comments,
    }
开发者ID:MichaelBechHansen,项目名称:drawquest-web,代码行数:15,代码来源:api.py

示例8: top_gallery_comments

# 需要导入模块: from canvas.cache_patterns import CachedCall [as 别名]
# 或者: from canvas.cache_patterns.CachedCall import queryset_details [as 别名]
def top_gallery_comments(quest, viewer=None, include_reactions=False):
    comment_ids = top_gallery_comment_ids(quest)

    comments = QuestComment.objects.filter(id__in=comment_ids).order_by('-star_count')
    comments = _exclude_flagged(comments, viewer)

    promoter = None if include_reactions else QuestCommentGalleryDetails
    comments = CachedCall.queryset_details(comments, promoter=promoter)

    add_viewer_has_starred_field(comments, viewer=viewer)

    if viewer is not None and viewer.is_authenticated():
        following = viewer.following_ids()

        for comment in comments:
            comment.user.viewer_is_following = comment.user.id in following

    return comments
开发者ID:MichaelBechHansen,项目名称:drawquest-web,代码行数:20,代码来源:models.py

示例9: _profile

# 需要导入模块: from canvas.cache_patterns import CachedCall [as 别名]
# 或者: from canvas.cache_patterns.CachedCall import queryset_details [as 别名]
def _profile(request, user, template='profiles/profile.html'):
    comments = QuestComment.by_author(user)

    top_comments = models.top_comments(user)

    if top_comments is None:
        comments = CachedCall.queryset_details(comments)
    else:
        comments, top_comments = CachedCall.many_queryset_details(comments, top_comments)

    follow_counts = following_models.counts(user)

    return r2r_jinja(template, {
        'target_user': user,
        'comments': comments,
        'top_comments': top_comments,
        'follower_count': follow_counts['followers'],
        'following_count': follow_counts['following'],
    }, request)
开发者ID:MichaelBechHansen,项目名称:drawquest-web,代码行数:21,代码来源:views.py

示例10: user_comments

# 需要导入模块: from canvas.cache_patterns import CachedCall [as 别名]
# 或者: from canvas.cache_patterns.CachedCall import queryset_details [as 别名]
def user_comments(user, viewer, offset="top", include_ugq=True, include_reactions=True):
    comments = QuestComment.by_author(user)

    if not include_ugq:
        comments = comments.filter(parent_comment__ugq=False)

    if viewer.id != user.id:
        comments = comments.exclude(visibility=Visibility.CURATED)

        if viewer.is_authenticated():
            comments = comments.exclude(flags__user=viewer)

    pagination = Paginator(comments, knobs.COMMENTS_PER_PAGE, offset=offset)

    comments = pagination.items

    promoter = None if include_reactions else QuestCommentGalleryDetails
    comments = CachedCall.queryset_details(comments, promoter=promoter)

    add_viewer_has_starred_field(comments, viewer=viewer)

    return comments, pagination
开发者ID:MichaelBechHansen,项目名称:drawquest-web,代码行数:24,代码来源:models.py

示例11: quest_comments

# 需要导入模块: from canvas.cache_patterns import CachedCall [as 别名]
# 或者: from canvas.cache_patterns.CachedCall import queryset_details [as 别名]
def quest_comments(request, quest_id, force_comment_id=None):
    quest = get_object_or_404(Quest, id=quest_id)

    # Exclude curated comments here since we ignore curation status for forced comments, below.
    comments = QuestComment.objects.filter(parent_comment=quest).exclude(visibility=Visibility.CURATED)
    comments = comments.order_by('-id')

    comments = comments[:knobs.COMMENTS_PER_PAGE]
    comments = CachedCall.queryset_details(comments)

    forced_comment = None
    if force_comment_id:
        for comment in comments:
            if str(comment.id) == str(force_comment_id):
                forced_comment = comment
                break

    if force_comment_id and forced_comment is None:
        forced_comment = QuestComment.details_by_id(force_comment_id)()

    if forced_comment is not None and str(forced_comment.id) not in [str(comment.id) for comment in comments]:
        comments.append(forced_comment)

    return {'comments': comments}
开发者ID:MichaelBechHansen,项目名称:drawquest-web,代码行数:26,代码来源:api.py

示例12: from_ids

# 需要导入模块: from canvas.cache_patterns import CachedCall [as 别名]
# 或者: from canvas.cache_patterns.CachedCall import queryset_details [as 别名]
 def from_ids(cls, quest_ids):
     from drawquest.apps.quests.models import Quest
     return CachedCall.queryset_details(Quest.objects.in_bulk_list(quest_ids))
开发者ID:MichaelBechHansen,项目名称:drawquest-web,代码行数:5,代码来源:details_models.py


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