Beispiel #1
0
def view(request, action):
    """Returns the activity info"""

    social_email = None
    if action.member:
        social_email = action.member.social_email

    form = ActivityCodeForm(
            initial={"social_email": social_email, },
            request=request)

    if not action.event.is_event_completed():
        form.form_title = "Sign up for this event"
    else:
        form.form_title = "Get your points"

    return form
Beispiel #2
0
def complete(request, event):
    """complete the event and try to claim point."""

    user = request.user

    if request.method == "POST":
        form = ActivityCodeForm(request.POST, request=request, action=event)

        if form.is_valid():
            # Approve the activity (confirmation code is validated in
            # forms.ActivityTextForm.clean())
            code = ConfirmationCode.objects.get(code=form.cleaned_data["response"].lower())
            code.is_active = False
            code.user = user
            code.save()

            try:
                action_member = ActionMember.objects.get(user=user, action=event)
            except ObjectDoesNotExist:
                action_member = ActionMember(user=user, action=event)

            action_member.approval_status = "approved"
            value = event.point_value

            action_member.social_email = form.cleaned_data["social_email"].lower()
            try:
                action_member.save()
            except IntegrityError:
                messages.error = 'Sorry, but it appears that you have already added this activity.'
                return HttpResponseRedirect(
                    reverse("activity_task", args=(event.type, event.slug,)))

            response = HttpResponseRedirect(
                reverse("activity_task", args=(event.type, event.slug,)))
            if value:
                notification = "You just earned " + str(value) + " points."
                response.set_cookie("task_notify", notification)

            return response

        # invalid form
        # rebuild the form
        form.form_title = "Get your points"
        return render_to_response("task.html", {
            "action": event,
            "form": form,
            "completed_count": 0,
            "team_members": None,
            "display_form": True,
            "reminders": None,
            }, context_instance=RequestContext(request))

    return HttpResponseRedirect(reverse("activity_task", args=(event.type, event.slug,)))