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


Python Notification.find方法代码示例

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


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

示例1: notifications_index

# 需要导入模块: from notifications.models import Notification [as 别名]
# 或者: from notifications.models.Notification import find [as 别名]
def notifications_index(request):
    # get the page
    page = int(request.GET.get('page', 1))

    # Get the total pages (rounding up, ex: 1.2 pages means 2 pages)
    total_pages = int(math.ceil(float(Notification.count(request.user)) / NOTIFICATIONS_PER_PAGE))

    # If the page doesn't exists then 404
    if page > total_pages and total_pages > 0:
        raise Http404

    # Get the notifications
    offset = NOTIFICATIONS_PER_PAGE * (page - 1)
    limit = offset + NOTIFICATIONS_PER_PAGE
    notifications = Notification.find(request.user, offset, limit-1)

    context = {
        "total_pages": total_pages,
        "actual_page": page,
        "notifications": notifications
    }

    return render_to_response('notifications/notifications-index.html',
                              context,
                              context_instance=RequestContext(request))
开发者ID:slok,项目名称:dwarf,代码行数:27,代码来源:views.py

示例2: user_dashboard

# 需要导入模块: from notifications.models import Notification [as 别名]
# 或者: from notifications.models.Notification import find [as 别名]
def user_dashboard(request):

    # Notifications
    # Rest one beacause is the upper limit inclusive
    notifs = Notification.find(user=request.user, limit=NOTIFS_IN_DASHBOARD-1)

    # Stats
    total_links = UserLink.objects.filter(user=request.user).count()
    total_achieves = UserAchievement.objects.filter(user=request.user).count()

    # Latest links
    links_aux = UserLink.objects.filter(
                        user=request.user).order_by('-id')[:LINKS_IN_DASHBOARD]
    links = [ShortLink.find(token=i.token) for i in links_aux]

    # Latest achievements
    achievements = UserAchievement.objects.filter(
                        user=request.user).order_by('-id')[:ACHIEV_IN_DASHBOARD]
    context = {
        "notifications": notifs,
        "links": links,
        "stats": {
            "Total Links": total_links,
            "Achievements": total_achieves,
            "Level": request.user.profile.level.level_number,
            "Points": request.user.profile.points,
        },
        "achievements": achievements
    }

    return render_to_response('userprofile/dashboard.html',
                              context,
                              context_instance=RequestContext(request))
开发者ID:slok,项目名称:dwarf,代码行数:35,代码来源:views.py

示例3: test_achievement_notification_find_all_with_limits

# 需要导入模块: from notifications.models import Notification [as 别名]
# 或者: from notifications.models.Notification import find [as 别名]
    def test_achievement_notification_find_all_with_limits(self):
        achieves = Achievement.objects.all()[:5]
        user = User.objects.get(id=1)
        r = get_redis_connection()

        for i in achieves:
            notif = AchievementNotification(achievement=i, user=user)
            time.sleep(1)

            if random.randrange(100) % 2:
                key = Notification.STORE_KEY_UNREAD_FORMAT.format(user.id)
            else:
                key = Notification.STORE_KEY_READ_FORMAT.format(user.id)

            r.zadd(key, notif.date, notif.to_json())

        # Get notifications
        res = Notification.find(user, offset=2, limit=3, desc=False, mode=2)

        achieves = achieves[2:4]  # 2 and 3 only
        a_len = len(achieves)

        self.assertEquals(a_len, len(res))

        for i in range(len(res)):
            before = achieves[i]
            after = res[i]

            self.assertEquals(before.id, after.achievement_id)
开发者ID:slok,项目名称:dwarf,代码行数:31,代码来源:tests.py


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