Beispiel #1
0
    def _check(request, *args, **kwargs):
        is_authorized_action = False

        challenge_id = kwargs.get("challenge_id", None)
        if challenge_id:
            challenge = get_object_or_404(Challenge, pk=challenge_id)

        participation_id = kwargs.get("participation_id", None)
        if participation_id:
            participation = get_object_or_404(
                    Participation, pk=participation_id)
            challenge = participation.challenge

        comment_id = kwargs.get("comment_id", None)
        if comment_id:
            comment = get_object_or_404(Comment, pk=comment_id)
            challenge = comment.challenge
            if request.user==comment.user:
                is_authorized_action = True

        if is_challenge_admin(request.user, challenge) or is_authorized_action:
            return func(request, *args, **kwargs)
        else:
            info = _("You don't have permission to perform this action.")
            return render_to_response('account_information.html', 
                    RequestContext(request, {
                            "information": info,
                            }))
Beispiel #2
0
    def _check(request, *args, **kwargs):
        is_authorized_action = False

        challenge_id = kwargs.get("challenge_id", None)
        if challenge_id:
            challenge = get_object_or_404(Challenge, pk=challenge_id)

        participation_id = kwargs.get("participation_id", None)
        if participation_id:
            participation = get_object_or_404(Participation,
                                              pk=participation_id)
            challenge = participation.challenge

        comment_id = kwargs.get("comment_id", None)
        if comment_id:
            comment = get_object_or_404(Comment, pk=comment_id)
            challenge = comment.challenge
            if request.user == comment.user:
                is_authorized_action = True

        if is_challenge_admin(request.user, challenge) or is_authorized_action:
            return func(request, *args, **kwargs)
        else:
            info = _("You don't have permission to perform this action.")
            return render_to_response(
                'account_information.html',
                RequestContext(request, {
                    "information": info,
                }))
Beispiel #3
0
def challenge_detail(request, challenge_id, org_slug=None, chl_slug=None):
    ctx = {}

    user = request.user
    challenge = get_object_or_404(Challenge, pk=challenge_id)
    ctx.update({"challenge": challenge})

    if challenge.is_deleted:
        return render_to_response('challenge_deleted_info.html',
                                  RequestContext(request, {
                                      "challenge": challenge,
                                      "subject": _("%(challenge_name)s was cancelled")
                                                 % {"challenge_name": challenge.name},
                                  }))

    if request.user.is_authenticated():
        ctx.update({"is_admin": is_challenge_admin(user, challenge)})

    # Extract comments
    comments = Comment.objects.all().filter(
        Q(challenge=challenge) & Q(is_deleted=False)
    ).order_by("created_at")
    ctx.update({"comments": comments})

    ctx.update({"PARTICIPATION_STATE": PARTICIPATION_STATE})
    ctx.update({"CHALLENGE_STATUS": CHALLENGE_STATUS})
    ctx.update({"PRIVACY_MODE": PRIVACY_MODE})
    ctx.update({"PARTICIPATION_REMOVE_MODE": PARTICIPATION_REMOVE_MODE})

    return render_to_response('challenge_detail.html',
                              RequestContext(request, ctx))
Beispiel #4
0
def challenge_detail(request, challenge_id, org_slug=None, chl_slug=None):
    ctx = {}

    user = request.user
    challenge = get_object_or_404(Challenge, pk=challenge_id)
    ctx.update({"challenge": challenge})

    if challenge.is_deleted:
        return render_to_response('challenge_deleted_info.html',
                                  RequestContext(request, {
                                      "challenge": challenge,
                                      "subject": _("%(challenge_name)s was cancelled")
                                                 % {"challenge_name": challenge.name},
                                  }))

    # Only authenticated users may signup to challenge
    if request.user.is_authenticated():
        try:
            participation = Participation.objects.all().get(
                Q(user=request.user) & Q(challenge=challenge))
            ctx.update({"participation": participation})

            if (participation.status == PARTICIPATION_STATE.CONFIRMED or
                        participation.status == PARTICIPATION_STATE.WAITING_FOR_CONFIRMATION):
                wform = WithdrawSignupForm(
                    request.POST or None, request.FILES or None,
                    instance=participation)
                ctx.update({"wform": wform})

            if participation.status == PARTICIPATION_STATE.CANCELLED_BY_USER:
                sform = SignupChallengeForm(
                    request.user, challenge,
                    request.POST or None, request.FILES or None,
                    instance=participation)
                ctx.update({"sform": sform})

            if participation.status == PARTICIPATION_STATE.WAITING_FOR_SELFREFLECTION:
                rform = SelfreflectionForm(
                    request.POST or None, request.FILES or None,
                    instance=participation)
                ctx.update({"rform": rform})

                if not participation.is_selfreflection_rejected:
                    pform = WithdrawSignupForm(
                        request.POST or None, request.FILES or None,
                        instance=participation)
                    ctx.update({"pform": pform})
        except:
            sform = SignupChallengeForm(
                request.user, challenge,
                request.POST or None, request.FILES or None)
            ctx.update({"sform": sform})

        # Weird block, but it's the only way to describe the logic with
        # processing of states with forms, such (None, sform, wform, rform)
        if request.method == "POST":
            # User signs up to challenge
            try:
                if sform.is_valid():
                    sform.save()
                    if challenge.application == CHALLENGE_MODE.FREE_FOR_ALL:
                        send_templated_mail(
                            template_name="challenge_successful_signup",
                            from_email=settings.EMAIL_SENDER,
                            recipient_list=[user.email, ],
                            context={
                                "user": user,
                                "challenge": challenge,
                                "challenge_url": challenge.get_full_url(request),
                                "subject": _("Participation Confirmation for %(challenge_name)")
                                        % {"challenge_name": challenge.name},
                            }, )
            except NameError:
                pass

            # User withdraws his application
            try:
                if wform.is_valid():
                    wform.save()
            except NameError:
                pass

            # User leaves his self-reflection
            try:
                if rform.is_valid():
                    rform.save()
            except NameError:
                pass

            # User didn't participate after all
            try:
                if pform.is_valid():
                    pform.save()
            except NameError:
                pass
            return redirect(challenge.get_absolute_url())
        ctx.update({"is_admin": is_challenge_admin(user, challenge)})

    # Extract participations
    confirmed = Participation.objects.all().filter(
        challenge=challenge,
        status__in=[
            PARTICIPATION_STATE.CONFIRMED,
            PARTICIPATION_STATE.WAITING_FOR_SELFREFLECTION,
            PARTICIPATION_STATE.ACKNOWLEDGED,
            PARTICIPATION_STATE.WAITING_FOR_ACKNOWLEDGEMENT
        ]
    )
    ctx.update({"confirmed": confirmed})

    waiting_for_confirmation = Participation.objects.all().filter(
        challenge=challenge,
        status=PARTICIPATION_STATE.WAITING_FOR_CONFIRMATION
    )
    ctx.update({"waiting_for_confirmation": waiting_for_confirmation})

    waiting_for_acknowledgement = Participation.objects.all().filter(
        challenge=challenge,
        status=PARTICIPATION_STATE.WAITING_FOR_ACKNOWLEDGEMENT
    )
    ctx.update({"waiting_for_acknowledgement": waiting_for_acknowledgement})

    # Extract comments
    comments = Comment.objects.all().filter(
        Q(challenge=challenge) & Q(is_deleted=False)
    ).order_by("created_at")
    ctx.update({"comments": comments})

    ctx.update({"PARTICIPATION_STATE": PARTICIPATION_STATE})
    ctx.update({"CHALLENGE_STATUS": CHALLENGE_STATUS})
    ctx.update({"CHALLENGE_MODE": CHALLENGE_MODE})
    ctx.update({"PRIVACY_MODE": PRIVACY_MODE})
    ctx.update({"PARTICIPATION_REMOVE_MODE": PARTICIPATION_REMOVE_MODE})

    return render_to_response('challenge_detail.html',
                              RequestContext(request, ctx))