Пример #1
0
def add(request, activity):
    """Creates a request for points for an activity."""

    user = request.user
    draft = activity.draft

    if request.method == "POST":
        try:
            action_member = TesterActionSubmittion.objects.get(user=user, action=activity)
        except ObjectDoesNotExist:
            action_member = TesterActionSubmittion(user=user, action=activity, draft=draft,
                                         submission_date=datetime.datetime.today())

        action_member.approval_status = "approved"
        try:
            action_member.save()
        except IntegrityError:
            messages.error = 'Sorry, but it appears that you have already added this activity.'
            return HttpResponseRedirect(
                reverse("tester_view_action", args=(activity.type, activity.slug,)))

        response = HttpResponseRedirect(
            reverse("tester_view_action", args=(activity.type, activity.slug,)))

        return response

    return HttpResponseRedirect(reverse("tester_view_action", args=(activity.type, activity.slug,)))
Пример #2
0
def signup(request, event):
    """Commit the current user to the activity."""
    user = request.user
    draft = event.draft

    action_member = TesterActionSubmittion(user=user, action=event, draft=draft)
    action_member.save()

    response = HttpResponseRedirect(
        reverse("tester_view_action", args=(event.type, event.slug,)))
    value = score_mgr.signup_points()
    notification = "You just earned " + str(value) + " points."
    response.set_cookie("task_notify", notification)
    return response
Пример #3
0
def signup(request, event):
    """Commit the current user to the activity."""
    user = request.user
    draft = event.draft

    action_member = TesterActionSubmittion(user=user,
                                           action=event,
                                           draft=draft)
    action_member.save()

    response = HttpResponseRedirect(
        reverse("tester_view_action", args=(
            event.type,
            event.slug,
        )))
    value = score_mgr.signup_points()
    notification = "You just earned " + str(value) + " points."
    response.set_cookie("task_notify", notification)
    return response
Пример #4
0
def add(request, activity):
    """Creates a request for points for an activity."""

    user = request.user
    draft = activity.draft

    if request.method == "POST":
        try:
            action_member = TesterActionSubmittion.objects.get(user=user,
                                                               action=activity)
        except ObjectDoesNotExist:
            action_member = TesterActionSubmittion(
                user=user,
                action=activity,
                draft=draft,
                submission_date=datetime.datetime.today())

        action_member.approval_status = "approved"
        try:
            action_member.save()
        except IntegrityError:
            messages.error = 'Sorry, but it appears that you have already added this activity.'
            return HttpResponseRedirect(
                reverse("tester_view_action",
                        args=(
                            activity.type,
                            activity.slug,
                        )))

        response = HttpResponseRedirect(
            reverse("tester_view_action",
                    args=(
                        activity.type,
                        activity.slug,
                    )))

        return response

    return HttpResponseRedirect(
        reverse("tester_view_action", args=(
            activity.type,
            activity.slug,
        )))
Пример #5
0
def add(request, commitment):
    """Commit the current user to the commitment."""
    user = request.user
    draft = commitment.draft
    value = None

    if request.method == "GET":  # redirect to task page, only allow POST
        return  HttpResponseRedirect(
            reverse("tester_view_action", args=(commitment.type, commitment.slug,)))

    form = TestCommitmentCommentForm(request.POST, user=request.user.username)
    if not form.is_valid():
        # invalid form
        request.session['form'] = form
        return  HttpResponseRedirect(
            reverse("tester_view_action",
                    args=(commitment.type, commitment.slug,)) + "?display_form=True")

    # now we have a valid form
    if play_tester.can_complete_commitment(user, commitment):
        try:
            member = user.actionmember_set.get(action=commitment, award_date=None)
        except ObjectDoesNotExist:
            # ignore the race condition
            return HttpResponseRedirect(
                reverse("tester_view_action", args=(commitment.type, commitment.slug,)))

        #commitment end, award full point
        member.award_date = datetime.datetime.today()
        member.approval_status = "approved"

        if form.cleaned_data["social_email"]:
            member.social_email = form.cleaned_data["social_email"].lower()
        member.save()
        value = commitment.point_value

    elif play_tester.can_add_commitment(user):
        # User can commit to this commitment. allow to commit to completed commitment again
        # as long as the pending does not reach max
        member = TesterActionSubmittion(user=user, action=commitment, draft=draft)

        if form:
            member.social_email = form.cleaned_data["social_email"].lower()

        try:
            member.save()
            value = score_mgr.signup_points()

        except IntegrityError:
            messages.error = 'Sorry, but it appears that you are already participating in ' \
                             'this commitment.'
            return HttpResponseRedirect(
                reverse("tester_view_action", args=(commitment.type, commitment.slug,)))

    else:  # user can not add more than 5 commitment
        return  HttpResponseRedirect(
            reverse("tester_view_action", args=(commitment.type, commitment.slug,)))

    response = HttpResponseRedirect(
        reverse("tester_view_action", args=(commitment.type, commitment.slug,)))
    notification = "You just earned " + str(value) + " points."
    response.set_cookie("task_notify", notification)
    return response
Пример #6
0
def add(request, commitment):
    """Commit the current user to the commitment."""
    user = request.user
    draft = commitment.draft
    value = None

    if request.method == "GET":  # redirect to task page, only allow POST
        return HttpResponseRedirect(
            reverse("tester_view_action",
                    args=(
                        commitment.type,
                        commitment.slug,
                    )))

    form = TestCommitmentCommentForm(request.POST, user=request.user.username)
    if not form.is_valid():
        # invalid form
        request.session['form'] = form
        return HttpResponseRedirect(
            reverse("tester_view_action",
                    args=(
                        commitment.type,
                        commitment.slug,
                    )) + "?display_form=True")

    # now we have a valid form
    if play_tester.can_complete_commitment(user, commitment):
        try:
            member = user.actionmember_set.get(action=commitment,
                                               award_date=None)
        except ObjectDoesNotExist:
            # ignore the race condition
            return HttpResponseRedirect(
                reverse("tester_view_action",
                        args=(
                            commitment.type,
                            commitment.slug,
                        )))

        #commitment end, award full point
        member.award_date = datetime.datetime.today()
        member.approval_status = "approved"

        if form.cleaned_data["social_email"]:
            member.social_email = form.cleaned_data["social_email"].lower()
        member.save()
        value = commitment.point_value

    elif play_tester.can_add_commitment(user):
        # User can commit to this commitment. allow to commit to completed commitment again
        # as long as the pending does not reach max
        member = TesterActionSubmittion(user=user,
                                        action=commitment,
                                        draft=draft)

        if form:
            member.social_email = form.cleaned_data["social_email"].lower()

        try:
            member.save()
            value = score_mgr.signup_points()

        except IntegrityError:
            messages.error = 'Sorry, but it appears that you are already participating in ' \
                             'this commitment.'
            return HttpResponseRedirect(
                reverse("tester_view_action",
                        args=(
                            commitment.type,
                            commitment.slug,
                        )))

    else:  # user can not add more than 5 commitment
        return HttpResponseRedirect(
            reverse("tester_view_action",
                    args=(
                        commitment.type,
                        commitment.slug,
                    )))

    response = HttpResponseRedirect(
        reverse("tester_view_action",
                args=(
                    commitment.type,
                    commitment.slug,
                )))
    notification = "You just earned " + str(value) + " points."
    response.set_cookie("task_notify", notification)
    return response