• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python models.ChallengeGame类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中models.ChallengeGame的典型用法代码示例。如果您正苦于以下问题:Python ChallengeGame类的具体用法?Python ChallengeGame怎么用?Python ChallengeGame使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: index

def index(request):
    """ Shows all challenges related to the current user """
    profile = request.user.get_profile()
    chall_user = profile.get_extension(ChallengeUser)

    challs = ChallengeGame.get_active(chall_user)
    played = ChallengeGame.get_played(chall_user)[:10]

    if not chall_user.is_eligible():
        return do_result(request, error='Ne pare rau, nu esti anul I, nu poti provoca. Te invitam pe wouso-next.rosedu.org')

    return render_to_response('challenge/index.html',
            {'challenges': challs, 'played': played, 'challuser': chall_user, 'challenge': ChallengeGame},
            context_instance=RequestContext(request))
开发者ID:anaion,项目名称:wouso,代码行数:14,代码来源:views.py


示例2: index

def index(request):
    """ Shows all challenges related to the current user """
    profile = request.user.get_profile()
    chall_user = profile.get_extension(ChallengeUser)

    challs = ChallengeGame.get_active(chall_user)
    played = ChallengeGame.get_played(chall_user)[:10]

    if not chall_user.is_eligible():
        messages.error(request, _('Your race can\'t play. Go home'))

    return render_to_response('challenge/index.html',
            {'challenges': challs, 'played': played, 'challuser': chall_user, 'challenge': ChallengeGame},
            context_instance=RequestContext(request))
开发者ID:AndreiRO,项目名称:wouso,代码行数:14,代码来源:views.py


示例3: launch

def launch(request, to_id):
    user_to = get_object_or_404(Player, pk=to_id)

    user_to = user_to.get_extension(ChallengeUser)

    user_from = request.user.get_profile().get_extension(ChallengeUser)

    if ChallengeGame.disabled():
        return do_result(request, error='Provocarile sunt dezactivate')

    if (not user_to.is_eligible()) or (not user_from.is_eligible()):
        return do_result(request, error='Ne pare rau, doar studentii de anul I pot provoca/fi provocati')

    if not user_from.can_launch():
        return do_result(request, _('You cannot launch another challenge today.'))

    if not user_from.has_enough_points():
        return do_result(request, _('You need at least 30 points to launch a challenge'))

    if user_from.can_challenge(user_to):
        try:
            chall = Challenge.create(user_from=user_from, user_to=user_to)
        except ChallengeException as e:
            # Some error occurred during question fetch. Clean up, and display error
            return do_result(request, e.message)
        return do_result(request, message=_('Successfully challenged'))
    else:
        return do_result(request, _('This user cannot be challenged.'))
开发者ID:anaion,项目名称:wouso,代码行数:28,代码来源:views.py


示例4: index

def index(request):
    """ Shows all challenges related to the current user """
    profile = request.user.get_profile()
    chall_user = profile.get_extension(ChallengeUser)

    challs = ChallengeGame.get_active(chall_user)
    played = ChallengeGame.get_played(chall_user)[:10]

    if not chall_user.is_eligible():
        return do_result(request, error="Your race can't play. Go home")

    return render_to_response(
        "challenge/index.html",
        {"challenges": challs, "played": played, "challuser": chall_user, "challenge": ChallengeGame},
        context_instance=RequestContext(request),
    )
开发者ID:tiriplicamihai,项目名称:wouso,代码行数:16,代码来源:views.py


示例5: launch

def launch(request, to_id):
    user_to = get_object_or_404(Player, pk=to_id)

    user_to = user_to.get_extension(ChallengeUser)

    user_from = request.user.get_profile().get_extension(ChallengeUser)

    if ChallengeGame.disabled():
        return do_result(request, error='Provocarile sunt dezactivate')

    if (not user_to.is_eligible()) or (not user_from.is_eligible()):
        return do_result(request, error=_('Sorry, challenge failed.'))

    if not user_from.can_launch():
        return do_result(request, _('You cannot launch another challenge today.'))

    if not user_from.has_enough_points():
        return do_result(request, _('You need at least 30 points to launch a challenge'))

    if user_from.can_challenge(user_to):
        try:
            chall = Challenge.create(user_from=user_from, user_to=user_to)
        except ChallengeException as e:
            # Some error occurred during question fetch. Clean up, and display error
            return do_result(request, e.message)
        #Checking if user_to is stored in session
        PREFIX = "_user:"
        action_msg = "multiple-login"
        if (PREFIX + user_to.user.username) in request.session:
            from wouso.core.signals import addActivity
            addActivity.send(sender=None, user_to=user_to, user_from=user_from, action=action_msg,
                             game=None, public=False)
        return do_result(request, message=_('Successfully challenged'))
    else:
        return do_result(request, _('This user cannot be challenged.'))
开发者ID:ionel-popescu93,项目名称:wouso,代码行数:35,代码来源:views.py


示例6: read

 def read(self, request):
     player = request.user.get_profile()
     challuser = player.get_extension(ChallengeUser)
     return [dict(status=c.status, date=c.date, id=c.id,
                  user_from=unicode(c.user_from.user),
                  user_from_id=c.user_from.user.id,
                  user_to=unicode(c.user_to.user),
                  user_to_id=c.user_to.user.id) for c in ChallengeGame.get_active(challuser)]
开发者ID:MathPlayer,项目名称:wouso,代码行数:8,代码来源:api.py


示例7: accept

def accept(request, id):
    if ChallengeGame.disabled():
        return do_result(request, error="Provocarile sunt dezactivate")

    chall = get_object_or_404(Challenge, pk=id)

    user_to = request.user.get_profile().get_extension(ChallengeUser)
    if (chall.user_to.user == user_to and chall.is_launched()) or request.user.is_superuser:
        chall.accept()
        return HttpResponseRedirect(reverse("wouso.games.challenge.views.index"))
    return do_result(request, _("Challenge cannot be accepted."))
开发者ID:tiriplicamihai,项目名称:wouso,代码行数:11,代码来源:views.py


示例8: sidebar_widget

def sidebar_widget(context):
    user = context.get('user', None)
    if not user or not user.is_authenticated():
        return ''
    chall_user = user.get_profile().get_extension(ChallengeUser)
    challs = ChallengeGame.get_active(chall_user)
    challs = [c for c in challs if c.status == 'A']
    # reduce noise, thanks
    if not challs:
        return ''
    return render_to_string('challenge/sidebar.html', {'challenges': challs,
                            'challenge': ChallengeGame,  'chall_user': chall_user, 'id': 'challenge'})
开发者ID:AndreiRO,项目名称:wouso,代码行数:12,代码来源:views.py


示例9: sidebar_widget

def sidebar_widget(request):
    profile = request.user.get_profile()
    if not profile:
        return ''
    chall_user = profile.get_extension(ChallengeUser)
    challs = ChallengeGame.get_active(chall_user)
    challs = [c for c in challs if c.status == 'A']
    # reduce noise, thanks
    if not challs:
        return ''

    return render_to_string('challenge/sidebar.html', {'challenges': challs, 'challenge': ChallengeGame,  'chall_user': chall_user})
开发者ID:anaion,项目名称:wouso,代码行数:12,代码来源:views.py


示例10: sidebar_widget

def sidebar_widget(request):
    if not request.user.is_authenticated():
        return ""
    chall_user = request.user.get_profile().get_extension(ChallengeUser)
    challs = ChallengeGame.get_active(chall_user)
    challs = [c for c in challs if c.status == "A"]

    # reduce noise, thanks
    if not challs:
        return ""

    return render_to_string(
        "challenge/sidebar.html", {"challenges": challs, "challenge": ChallengeGame, "chall_user": chall_user}
    )
开发者ID:tiriplicamihai,项目名称:wouso,代码行数:14,代码来源:views.py


示例11: header_link

def header_link(context):
    user = context.get("user", None)
    if not user or not user.is_authenticated():
        return dict(text=_("Challenges"))

    if ChallengeGame.disabled():
        return ""

    profile = user.get_profile()
    if profile:
        chall_user = profile.get_extension(ChallengeUser)
        challs = ChallengeGame.get_active(chall_user)
        # remove launched challenges by the user
        challs = [c for c in challs if not (c.status == "L" and c.user_from.user == chall_user)]
        # remove refused challenges
        challs = [c for c in challs if not c.status == "R"]

        count = len(challs)
    else:
        count = 0
    url = reverse("wouso.games.challenge.views.index")

    return dict(link=url, count=count, text=_("Challenges"))
开发者ID:TeodorMihai,项目名称:wouso,代码行数:23,代码来源:views.py


示例12: accept

def accept(request, id):
    if ChallengeGame.disabled():
        messages.error(request, _("Challenges are disabled"))
        return redirect("challenge_index_view")

    chall = get_object_or_404(Challenge, pk=id)

    user_to = request.user.get_profile().get_extension(ChallengeUser)
    if (chall.user_to.user == user_to and chall.is_launched()) or request.user.is_superuser:
        chall.accept()
        return redirect("challenge_index_view")

    messages.error(request, _("Challenge cannot be accepted."))
    return redirect("challenge_index_view")
开发者ID:TeodorMihai,项目名称:wouso,代码行数:14,代码来源:views.py


示例13: accept

def accept(request, id):
    if ChallengeGame.disabled():
        messages.error(request, _('Provocarile sunt dezactivate'))
        return redirect('challenge_index_view')

    chall = get_object_or_404(Challenge, pk=id)

    user_to = request.user.get_profile().get_extension(ChallengeUser)
    if (chall.user_to.user == user_to and chall.is_launched()) or \
        request.user.is_superuser:
            chall.accept()
            return redirect('challenge_index_view')

    messages.error(request, _('Challenge cannot be accepted.'))
    return redirect('challenge_index_view')
开发者ID:AndreiRO,项目名称:wouso,代码行数:15,代码来源:views.py


示例14: sidebar_widget

def sidebar_widget(context):
    user = context.get("user", None)
    if not user or not user.is_authenticated():
        return ""

    chall_user = user.get_profile().get_extension(ChallengeUser)
    challs = ChallengeGame.get_active(chall_user)
    challs = [c for c in challs if c.status == "A"]
    # reduce noise, thanks
    if not challs:
        return ""
    return render_to_string(
        "challenge/sidebar.html",
        {"challenges": challs, "challenge": ChallengeGame, "chall_user": chall_user, "id": "challenge"},
    )
开发者ID:TeodorMihai,项目名称:wouso,代码行数:15,代码来源:views.py


示例15: header_link

def header_link(request):
    profile = request.user.get_profile()
    if profile:
        chall_user = profile.get_extension(ChallengeUser)
        challs = ChallengeGame.get_active(chall_user)
        # remove launched challenges by the user
        challs = [c for c in challs if not (c.status == 'L' and c.user_from.user == chall_user)]
        # remove refused challenges
        challs = [c for c in challs if not c.status == 'R']

        count = len(challs)
    else:
        count = 0
    url = reverse('wouso.games.challenge.views.index')

    return dict(link=url, count=count, text=_('Challenges'))
开发者ID:anaion,项目名称:wouso,代码行数:16,代码来源:views.py


示例16: launch

def launch(request, to_id):
    lock = challengeLock.lock()
    logging.info("Locked.")

    flush_transaction()
    user_to = get_object_or_404(Player, pk=to_id)
    user_to = user_to.get_extension(ChallengeUser)
    user_from = request.user.get_profile().get_extension(ChallengeUser)


    if ChallengeGame.disabled():
        messages.error(request, _('Provocarile sunt dezactivate'))
        logging.info("Ready to unlock (disabled).")
        lock.unlock()
        return redirect('challenge_index_view')

    if (not user_to.is_eligible()) or (not user_from.is_eligible()):
        messages.error(request, _('Sorry, challenge failed.'))
        logging.info("Ready to unlock (is eligible).")
        lock.unlock()
        return redirect('challenge_index_view')

    if not user_from.can_launch():
        messages.error(request, _('You cannot launch another challenge today.'))
        logging.info("Ready to unlock (cannot launch today).")
        lock.unlock()
        return redirect('challenge_index_view')

    if not user_from.in_same_division(user_to):
        messages.error(request, _('You are not in the same division'))
        logging.info("Ready to unlock (not in same divission).")
        lock.unlock()
        return redirect('challenge_index_view')

    if not user_from.has_enough_points():
        messages.error(request, _('You need at least 30 points to launch a challenge'))
        logging.info("Ready to unlock (not enough points).")
        lock.unlock()
        return redirect('challenge_index_view')

    if user_from.can_challenge(user_to):
        try:
            chall = Challenge.create(user_from=user_from, user_to=user_to)
            logging.info("Created challenge: %s" %(chall))
        except ChallengeException as e:
            # Some error occurred during question fetch. Clean up, and display error
            messages.error(request, e.message)
            lock.unlock()
            return redirect('challenge_index_view')
        #Checking if user_to is stored in session
        PREFIX = "_user:"
        action_msg = "multiple-login"
        if (PREFIX + user_to.user.username) in request.session:
            from wouso.core.signals import addActivity
            addActivity.send(sender=None, user_to=user_to, user_from=user_from, action=action_msg,
                             game=None, public=False)
        messages.success(request, _('Successfully challenged'))
        logging.info("Ready to unlock (save).")
        lock.unlock()
        return redirect('challenge_index_view')
    else:
        messages.error(request, _('This user cannot be challenged.'))
        logging.info("Ready to unlock (no user challenge).")
        lock.unlock()
        return redirect('challenge_index_view')
开发者ID:AndreiRO,项目名称:wouso,代码行数:65,代码来源:views.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.Channel类代码示例发布时间:2022-05-27
下一篇:
Python models.Category类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap