예제 #1
0
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'))
예제 #2
0
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},
            context_instance=RequestContext(request))
예제 #3
0
파일: views.py 프로젝트: anaion/wouso
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))
예제 #4
0
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))
예제 #5
0
파일: views.py 프로젝트: anaion/wouso
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.'))
예제 #6
0
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:"******"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.'))
예제 #7
0
파일: views.py 프로젝트: anaion/wouso
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.'))
예제 #8
0
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)
        #Checking if user_to is stored in session
        PREFIX = "_user:"******"multiple-login"
        if (PREFIX + user_to.user.username) in request.session:
            from wouso.interface.activity.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.'))
예제 #9
0
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),
    )
예제 #10
0
파일: api.py 프로젝트: MathPlayer/wouso
 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)]
예제 #11
0
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."))
예제 #12
0
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'})
예제 #13
0
파일: views.py 프로젝트: anaion/wouso
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})
예제 #14
0
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.'))
예제 #15
0
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_string('challenge/sidebar.html', {'challenges': challs, 'chall_user': chall_user})
예제 #16
0
 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)
     ]
예제 #17
0
파일: views.py 프로젝트: TeodorMihai/wouso
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")
예제 #18
0
파일: views.py 프로젝트: TeodorMihai/wouso
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"))
예제 #19
0
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}
    )
예제 #20
0
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')
예제 #21
0
파일: views.py 프로젝트: TeodorMihai/wouso
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"},
    )
예제 #22
0
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
    })
예제 #23
0
파일: views.py 프로젝트: anaion/wouso
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'))
예제 #24
0
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'))
예제 #25
0
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:"******"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')