Ejemplo n.º 1
0
    def test_cant_claim_task_beyond_alotted_slots(self):
        event = Event.objects.all()[0]

        some_task = Task()
        some_task.for_event = event
        some_task.for_committee = Committee.objects.filter(
                                            name="Events Committee").all()[0]
        some_task.task_type = TaskType.objects.filter(
                                            short_description="Tabling").all()[0]
        some_task.start_time = datetime.datetime(2009,4,18,9)
        some_task.duration_minutes = 60
        some_task.num_volunteers = 1
        some_task.save()

        plainuser = User.objects.filter(username='******').all()[0]
        temp_volunteer = Volunteer()
        temp_volunteer.user = plainuser
        temp_volunteer.save()

        asn = TaskAssignment()
        asn.task = some_task
        asn.points = 1
        asn.volunteer = temp_volunteer
        asn.save()

        # should not be able to save
        resp = self.client.get('/chirp/tasks/claim/%s.json' % some_task.id)
        json = simplejson.loads(resp.content)
        eq_(json['success'], False)
        eq_(json['error'],
            "All volunteers needed for this task have been filled "
            "(Tabling on Sat Apr 18th from 9:00 a.m. - 10:00 a.m.)")
Ejemplo n.º 2
0
    def test_hide_expired_events(self):
        old_event = Event()
        old_event.name = "Pitchfork 2008"
        old_event.duration_days = 3
        # make it just expire by a day:
        old_event.start_date = datetime.datetime.now() - timedelta(days=4)
        old_event.save()

        some_task = Task()
        some_task.for_event = old_event
        some_task.for_committee = Committee.objects.filter(
                                            name="Events Committee").all()[0]
        some_task.task_type = TaskType.objects.filter(
                                            short_description="Tabling").all()[0]
        some_task.start_time = datetime.datetime.now() - timedelta(days=30)
        some_task.duration_minutes = 60
        some_task.num_volunteers = 1
        some_task.save()

        plainuser = User.objects.filter(username='******').all()[0]
        temp_volunteer = Volunteer()
        temp_volunteer.user = plainuser
        temp_volunteer.save()

        asn = TaskAssignment()
        asn.task = some_task
        asn.points = 1
        asn.volunteer = temp_volunteer
        asn.save()

        resp = self.client.get('/chirp/tasks/claim/')
        context = resp.context[0]

        eq_(sorted(e.name for e in context['events']),
            ['CHIRP Record Fair & Other Delights'])
def claim_task(request, task_id):
    try:
        task = get_object_or_404(Task, id=task_id)
        # note that due to how sqlite begins transactions in deferred
        # mode by default (can we fix this?) there is a slight chance
        # that two people can claim a task at once.  In case that happens,
        # there is a bit of added protection here so more people can't claim it.
        if len(task.claimed_by) >= task.num_volunteers_needed:
            return {"success": False, "error": "All volunteers needed for this task have been filled (%s)" % task}
        current_user = auth.get_user(request)
        try:
            volunteer = Volunteer.objects.get(user=current_user)
        except Volunteer.DoesNotExist, exc:
            raise ValueError(
                "%s (%s) is not a volunteer.  An admin needs to create a volunteer "
                "record and link it to this user." % (current_user, current_user.get_full_name())
            )
        if current_user in task.claimed_by:
            return {"success": False, "error": "You have already claimed this task (%s)" % (task.__unicode__())}
        assignment = TaskAssignment()
        assignment.task = task
        assignment.volunteer = volunteer
        if task.potential_points:
            assignment.points = task.potential_points
        else:
            assignment.points = Decimal("1")
        assignment.save()

        template_vars = {"event": task.for_event, "task": task}
        message = loader.render_to_string("claim_task_email.txt", template_vars)
        msg = EmailMessage(subject="You have volunteered for a CHIRP task.", body=message, to=[current_user.email])
        msg.send(fail_silently=False)
Ejemplo n.º 4
0
def claim_task(request, task_id):
    try:
        task = get_object_or_404(Task, id=task_id)
        # note that due to how sqlite begins transactions in deferred
        # mode by default (can we fix this?) there is a slight chance
        # that two people can claim a task at once.  In case that happens,
        # there is a bit of added protection here so more people can't claim it.
        if len(task.claimed_by) >= task.num_volunteers_needed:
            return {
                'success':
                False,
                'error':
                "All volunteers needed for this task have been filled (%s)" %
                task
            }
        current_user = auth.get_user(request)
        try:
            volunteer = Volunteer.objects.get(user=current_user)
        except Volunteer.DoesNotExist, exc:
            raise ValueError(
                "%s (%s) is not a volunteer.  An admin needs to create a volunteer "
                "record and link it to this user." %
                (current_user, current_user.get_full_name()))
        if current_user in task.claimed_by:
            return {
                'success':
                False,
                'error':
                "You have already claimed this task (%s)" %
                (task.__unicode__())
            }
        assignment = TaskAssignment()
        assignment.task = task
        assignment.volunteer = volunteer
        if task.potential_points:
            assignment.points = task.potential_points
        else:
            assignment.points = Decimal('1')
        assignment.save()

        template_vars = {'event': task.for_event, 'task': task}
        message = loader.render_to_string('claim_task_email.txt',
                                          template_vars)
        msg = EmailMessage(subject='You have volunteered for a CHIRP task.',
                           body=message,
                           to=[current_user.email])
        msg.send(fail_silently=False)