Esempio n. 1
0
    def testViewCodesAndRsvps(self):
        """test view code and rsvp."""
        activity = test_utils.create_event()

        ConfirmationCode.generate_codes_for_activity(activity, 5)

        response = self.client.get(
            reverse('activity_view_codes', args=(activity.type, activity.slug)))
        self.failUnlessEqual(response.status_code, 404)
        response = self.client.get(
            reverse('activity_view_rsvps', args=(activity.type, activity.slug)))
        self.assertEqual(response.status_code, 404)

        self.user.is_staff = True
        self.user.save()

        response = self.client.get(
            reverse('activity_view_codes', args=(activity.type, activity.slug)))
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'view_codes.html')

        response = self.client.get(
            reverse('activity_view_rsvps', args=(activity.type, activity.slug)))
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'rsvps.html')
Esempio n. 2
0
    def testViewCodesAndRsvps(self):
        """test view code and rsvp."""
        activity = test_utils.create_event()

        ConfirmationCode.generate_codes_for_activity(activity, 5)

        response = self.client.get(
            reverse('activity_view_codes', args=(activity.type, activity.id)))
        self.failUnlessEqual(response.status_code, 404)
        response = self.client.get(
            reverse('activity_view_rsvps', args=(activity.type, activity.id)))
        self.assertEqual(response.status_code, 404)

        self.user.is_staff = True
        self.user.save()

        response = self.client.get(
            reverse('activity_view_codes', args=(activity.type, activity.id)))
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'admin/view_codes.html')

        response = self.client.get(
            reverse('activity_view_rsvps', args=(activity.type, activity.id)))
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'admin/rsvps.html')
Esempio n. 3
0
    def testConfirmationCode(self):
        """
        Tests the submission of a confirmation code.
        """
        activity = test_utils.create_event()
        activity.event_date = datetime.datetime.today() - datetime.timedelta(
            days=1, seconds=30)
        activity.save()

        ConfirmationCode.generate_codes_for_activity(activity, 10)
        code = ConfirmationCode.objects.filter(action=activity)[0]

        response = self.client.post(reverse("activity_add_task",
                                            args=("event", "test-event")), {
                                                "response": code.code,
                                                "code": 1,
                                            },
                                    follow=True)

        self.failUnlessEqual(response.status_code, 200)
        self.assertEqual(
            ConfirmationCode.objects.filter(action=activity,
                                            is_active=False).count(), 1)
        code = ConfirmationCode.objects.filter(action=activity)[0]
        self.assertTrue(activity.action_ptr in self.user.action_set.filter(
            actionmember__award_date__isnull=False))

        # Try submitting the code again and check if we have an error message.
        code = ConfirmationCode.objects.filter(action=activity)[1]
        response = self.client.post(reverse("activity_add_task",
                                            args=("event", "test-event")), {
                                                "response": code.code,
                                                "code": 1,
                                            },
                                    follow=True)
        self.assertContains(
            response, "You have already redeemed a code for this action.")

        # Try creating a new activity with codes and see if we can submit a code for one activity
        # for another.
        code = ConfirmationCode.objects.filter(action=activity)[2]
        activity = test_utils.create_event(slug="test-event2")
        activity.event_date = datetime.datetime.today() - datetime.timedelta(
            days=1, seconds=30)
        activity.save()
        ConfirmationCode.generate_codes_for_activity(activity, 1)

        response = self.client.post(reverse("activity_add_task",
                                            args=("event", "test-event2")), {
                                                "response": code.code,
                                                "code": 1,
                                            },
                                    follow=True)
        self.assertContains(
            response, "This confirmation code is not valid for this action.")
Esempio n. 4
0
    def save(self, *args, **kwargs):
        event = super(EventAdminForm, self).save(*args, **kwargs)
        if event.is_excursion:
            event.type = "excursion"
        else:
            event.type = "event"
        event.save()

        cache_mgr.clear()

        # Generate confirmation codes if needed.
        if self.cleaned_data.get("num_codes") > 0:
            ConfirmationCode.generate_codes_for_activity(event,
                self.cleaned_data.get("num_codes"))

        return event
Esempio n. 5
0
    def testConfirmationCode(self):
        """
        Tests the submission of a confirmation code.
        """
        activity = test_utils.create_event()
        activity.event_date = datetime.datetime.today() - datetime.timedelta(days=1, seconds=30)
        activity.save()

        ConfirmationCode.generate_codes_for_activity(activity, 10)
        code = ConfirmationCode.objects.filter(action=activity)[0]

        response = self.client.post(reverse("activity_add_task", args=("event", "test-event")), {
            "response": code.code,
            "code": 1,
            }, follow=True)

        self.failUnlessEqual(response.status_code, 200)
        self.assertEqual(ConfirmationCode.objects.filter(
            action=activity, is_active=False).count(), 1)
        code = ConfirmationCode.objects.filter(action=activity)[0]
        self.assertTrue(
            activity.action_ptr in self.user.action_set.filter(
                actionmember__award_date__isnull=False))

        # Try submitting the code again and check if we have an error message.
        code = ConfirmationCode.objects.filter(action=activity)[1]
        response = self.client.post(reverse("activity_add_task", args=("event", "test-event")), {
            "response": code.code,
            "code": 1,
            }, follow=True)
        print response
        self.assertContains(response, "You have already redeemed a code for this action.")

        # Try creating a new activity with codes and see if we can submit a code for one activity
        # for another.
        code = ConfirmationCode.objects.filter(action=activity)[2]
        activity = test_utils.create_event(slug="test-event2")
        activity.event_date = datetime.datetime.today() - datetime.timedelta(days=1, seconds=30)
        activity.save()
        ConfirmationCode.generate_codes_for_activity(activity, 1)

        response = self.client.post(reverse("activity_add_task", args=("event", "test-event2")),
                {
                "response": code.code,
                "code": 1,
                }, follow=True)
        self.assertContains(response, "This confirmation code is not valid for this action.")
Esempio n. 6
0
def generate_codes(request):
    """Handles the generate_codes_form from and creates the BonusPoints."""

    if request.method == "POST":
        form = GenerateCodeForm(request.POST)
        if form.is_valid():
            num = form.cleaned_data['num_codes']
            event_id = form.cleaned_data['event_id']
            event = get_object_or_404(Event, pk=event_id)
            ConfirmationCode.generate_codes_for_activity(event, num)
            url = "/admin/smartgrid/confirmationcode/?action__exact=%d" % event.id
            response = HttpResponseRedirect(url)
            return response
    else:
        event_id = _get_event_id_from_request(request)
        form = GenerateCodeForm(initial={"event_id": event_id})
        return render_to_response("admin/generate_code.html", {
            "form": form,
        }, context_instance=RequestContext(request))