def test_get_volunteer_shift_by_id(self):
        """ Uses shifts s1,s2,s3 and volunteers v1,v2"""

        # test cases where signed up
        register(self.v1.id, self.s1.id)
        register(self.v1.id, self.s2.id)
        register(self.v1.id, self.s3.id)

        register(self.v2.id, self.s1.id)
        register(self.v2.id, self.s2.id)
        register(self.v2.id, self.s3.id)

        self.assertEqual(
                        get_volunteer_shift_by_id(self.v1.id, self.s1.id),
                        VolunteerShift.objects.get(
                                                    volunteer_id=self.v1.id,
                                                    shift_id=self.s1.id
                                                    ))
        self.assertEqual(
                        get_volunteer_shift_by_id(self.v1.id, self.s2.id),
                        VolunteerShift.objects.get(
                            volunteer_id=self.v1.id,
                            shift_id=self.s2.id
                            )
                        )
        self.assertEqual(
                        get_volunteer_shift_by_id(self.v1.id, self.s3.id),
                        VolunteerShift.objects.get(
                            volunteer_id=self.v1.id,
                            shift_id=self.s3.id
                            )
                        )

        # self.assertEqual(get_volunteer_shift_by_id(v2.id, s1.id),
        # VolunteerShift.objects.get(volunteer_id=v2.id, shift_id=s1.id))
        # why does this throw DoesNotExist?
        self.assertEqual(
                        get_volunteer_shift_by_id(self.v2.id, self.s2.id),
                        VolunteerShift.objects.get(
                            volunteer_id=self.v2.id,
                            shift_id=self.s2.id
                            )
                        )
        self.assertEqual(
                        get_volunteer_shift_by_id(self.v2.id, self.s3.id),
                        VolunteerShift.objects.get(
                            volunteer_id=self.v2.id,
                            shift_id=self.s3.id
                            )
                        )
示例#2
0
文件: views.py 项目: systers/vms
 def get_context_data(self, **kwargs):
     context = super(EditHoursManagerView, self).get_context_data(**kwargs)
     volunteer_id = self.kwargs['volunteer_id']
     shift_id = self.kwargs['shift_id']
     context['volunteer_shift'] = get_volunteer_shift_by_id(
         volunteer_id, shift_id)
     context['shift'] = get_shift_by_id(shift_id)
     return context
示例#3
0
文件: views.py 项目: Monal5031/vms
 def get_context_data(self, **kwargs):
     context = super(EditHoursManagerView, self).get_context_data(**kwargs)
     volunteer_id = self.kwargs['volunteer_id']
     shift_id = self.kwargs['shift_id']
     context['volunteer_shift'] = \
         get_volunteer_shift_by_id(volunteer_id, shift_id)
     context['shift'] = get_shift_by_id(shift_id)
     return context
示例#4
0
    def test_get_volunteer_shift_by_id(self):
        """ Uses shifts s1,s2,s3 and volunteers v1,v2"""

        # test cases where signed up
        register(self.v1.id, self.s1.id)
        register(self.v1.id, self.s2.id)
        register(self.v1.id, self.s3.id)

        register(self.v2.id, self.s1.id)
        register(self.v2.id, self.s2.id)
        register(self.v2.id, self.s3.id)

        self.assertEqual(
            get_volunteer_shift_by_id(self.v1.id, self.s1.id),
            VolunteerShift.objects.get(volunteer_id=self.v1.id,
                                       shift_id=self.s1.id))
        self.assertEqual(
            get_volunteer_shift_by_id(self.v1.id, self.s2.id),
            VolunteerShift.objects.get(volunteer_id=self.v1.id,
                                       shift_id=self.s2.id))
        self.assertEqual(
            get_volunteer_shift_by_id(self.v1.id, self.s3.id),
            VolunteerShift.objects.get(volunteer_id=self.v1.id,
                                       shift_id=self.s3.id))

        # self.assertEqual(get_volunteer_shift_by_id(v2.id, s1.id),
        # VolunteerShift.objects.get(volunteer_id=v2.id, shift_id=s1.id))
        # why does this throw DoesNotExist?
        self.assertEqual(
            get_volunteer_shift_by_id(self.v2.id, self.s2.id),
            VolunteerShift.objects.get(volunteer_id=self.v2.id,
                                       shift_id=self.s2.id))
        self.assertEqual(
            get_volunteer_shift_by_id(self.v2.id, self.s3.id),
            VolunteerShift.objects.get(volunteer_id=self.v2.id,
                                       shift_id=self.s3.id))
示例#5
0
文件: views.py 项目: systers/vms
    def form_valid(self, form):
        volunteer_id = self.kwargs['volunteer_id']
        shift_id = self.kwargs['shift_id']
        shift = get_shift_by_id(shift_id)
        volunteer_shift = get_volunteer_shift_by_id(volunteer_id, shift_id)
        start_time = form.cleaned_data['start_time']
        end_time = form.cleaned_data['end_time']
        shift_start_time = shift.start_time
        shift_end_time = shift.end_time
        try:
            if (end_time > start_time):
                if (start_time >= shift_start_time
                        and end_time <= shift_end_time):
                    edit_shift_hours(volunteer_id, shift_id, start_time,
                                     end_time)
                    return HttpResponseRedirect(
                        reverse(
                            'shift:manage_volunteer_shifts',
                            args=(volunteer_id, )))
                else:
                    messages.add_message(
                        self.request, messages.INFO,
                        'Logged hours should be between shift hours')
                    return render(
                        self.request, 'shift/edit_hours_manager.html', {
                            'form': form,
                            'shift_id': shift_id,
                            'volunteer_id': volunteer_id,
                            'shift': shift,
                            'volunteer_shift': volunteer_shift,
                        })

            else:
                messages.add_message(
                    self.request, messages.INFO,
                    'End time should be greater than start time')
                return render(
                    self.request, 'shift/edit_hours_manager.html', {
                        'form': form,
                        'shift_id': shift_id,
                        'volunteer_id': volunteer_id,
                        'shift': shift,
                        'volunteer_shift': volunteer_shift,
                    })

        except:
            raise Http404
示例#6
0
文件: views.py 项目: Monal5031/vms
    def form_valid(self, form):
        volunteer_id = self.kwargs['volunteer_id']
        shift_id = self.kwargs['shift_id']
        shift = get_shift_by_id(shift_id)
        volunteer_shift = get_volunteer_shift_by_id(volunteer_id, shift_id)
        start_time = form.cleaned_data['start_time']
        end_time = form.cleaned_data['end_time']
        shift_start_time = shift.start_time
        shift_end_time = shift.end_time
        try:
            if end_time > start_time:
                if (start_time >= shift_start_time
                        and end_time <= shift_end_time):
                    edit_shift_hours(volunteer_id, shift_id, start_time,
                                     end_time)
                    return HttpResponseRedirect(
                        reverse('shift:manage_volunteer_shifts',
                                args=(volunteer_id, )))
                else:
                    messages.add_message(
                        self.request, messages.INFO,
                        'Logged hours should be between shift hours')
                    return render(
                        self.request, 'shift/edit_hours_manager.html', {
                            'form': form,
                            'shift_id': shift_id,
                            'volunteer_id': volunteer_id,
                            'shift': shift,
                            'volunteer_shift': volunteer_shift,
                        })

            else:
                messages.add_message(
                    self.request, messages.INFO,
                    'End time should be greater than start time')
                return render(
                    self.request, 'shift/edit_hours_manager.html', {
                        'form': form,
                        'shift_id': shift_id,
                        'volunteer_id': volunteer_id,
                        'shift': shift,
                        'volunteer_shift': volunteer_shift,
                    })

        except:
            raise Http404
示例#7
0
文件: views.py 项目: systers/vms
    def form_valid(self, form):
        volunteer_id = self.kwargs['volunteer_id']
        shift_id = self.kwargs['shift_id']
        shift = get_shift_by_id(shift_id)
        volunteer_shift = get_volunteer_shift_by_id(volunteer_id, shift_id)
        volunteer = get_volunteer_by_id(volunteer_id)
        start_time = form.cleaned_data['start_time']
        end_time = form.cleaned_data['end_time']
        shift_start_time = shift.start_time
        shift_end_time = shift.end_time
        event = shift.job.event
        site = get_current_site(self.request)
        try:
            if (end_time > start_time):
                if (start_time >= shift_start_time
                        and end_time <= shift_end_time):
                    request =  form.save(commit=False)
                    request.volunteer_shift = volunteer_shift
                    request.save()
                    message = render_to_string('shift/request_admin.html',
                                              {'volunteer': volunteer,
                                               'new_start_time': start_time,
                                               'new_end_time': end_time,
                                               'original_start_time': shift_start_time,
                                               'original_end_time': shift_end_time,
                                               'event': event,
                                               'edit_request': request,
                                               'shift_id': shift_id,
                                               'domain': site.domain,
                                               })
                    try:
                        send_mail("Edit request", message, "*****@*****.**", ["*****@*****.**"])
                    except:
                        raise Exception("There was an error in sending the email.")
                    volunteer_shift.edit_requested = True
                    volunteer_shift.save()
                    return HttpResponseRedirect(
                        reverse('shift:view_hours', args=(volunteer_id, )))
                else:
                    messages.add_message(
                        self.request, messages.INFO,
                        'Logged hours should be between shift hours')
                    return render(
                        self.request, 'shift/edit_hours.html', {
                            'form': form,
                            'shift_id': shift_id,
                            'volunteer_id': volunteer_id,
                            'shift': shift,
                            'volunteer_shift': volunteer_shift,
                        })

            else:
                messages.add_message(
                    self.request, messages.INFO,
                    'End time should be greater than start time')
                return render(
                    self.request, 'shift/edit_hours.html', {
                        'form': form,
                        'shift_id': shift_id,
                        'volunteer_id': volunteer_id,
                        'shift': shift,
                        'volunteer_shift': volunteer_shift,
                    })
        except:
            raise Http404
示例#8
0
文件: views.py 项目: Monal5031/vms
    def form_valid(self, form):
        volunteer_id = self.kwargs['volunteer_id']
        shift_id = self.kwargs['shift_id']
        shift = get_shift_by_id(shift_id)
        volunteer_shift = get_volunteer_shift_by_id(volunteer_id, shift_id)
        volunteer = get_volunteer_by_id(volunteer_id)
        start_time = form.cleaned_data['start_time']
        end_time = form.cleaned_data['end_time']
        shift_start_time = shift.start_time
        shift_end_time = shift.end_time
        event = shift.job.event
        site = get_current_site(self.request)
        try:
            if end_time > start_time:
                if (start_time >= shift_start_time
                        and end_time <= shift_end_time):
                    request = form.save(commit=False)
                    request.volunteer_shift = volunteer_shift
                    request.save()
                    message = render_to_string(
                        'shift/request_admin.html', {
                            'volunteer': volunteer,
                            'new_start_time': start_time,
                            'new_end_time': end_time,
                            'original_start_time': shift_start_time,
                            'original_end_time': shift_end_time,
                            'event': event,
                            'edit_request': request,
                            'shift_id': shift_id,
                            'domain': site.domain,
                        })
                    try:
                        send_mail("Edit request", message,
                                  "*****@*****.**",
                                  ["*****@*****.**"])
                    except Exception:
                        raise Exception(
                            "There was an error in sending the email.")
                    volunteer_shift.edit_requested = True
                    volunteer_shift.save()
                    return HttpResponseRedirect(
                        reverse('shift:view_hours', args=(volunteer_id, )))
                else:
                    messages.add_message(
                        self.request, messages.INFO,
                        'Logged hours should be between shift hours')
                    return render(
                        self.request, 'shift/edit_hours.html', {
                            'form': form,
                            'shift_id': shift_id,
                            'volunteer_id': volunteer_id,
                            'shift': shift,
                            'volunteer_shift': volunteer_shift,
                        })

            else:
                messages.add_message(
                    self.request, messages.INFO,
                    'End time should be greater than start time')
                return render(
                    self.request, 'shift/edit_hours.html', {
                        'form': form,
                        'shift_id': shift_id,
                        'volunteer_id': volunteer_id,
                        'shift': shift,
                        'volunteer_shift': volunteer_shift,
                    })
        except Exception:
            raise Http404
示例#9
0
文件: tests.py 项目: ahmedsabie/vms
    def test_get_volunteer_shift_by_id(self):

        u1 = User.objects.create_user("Yoshi")
        u2 = User.objects.create_user("John")

        v1 = Volunteer(
            first_name="Yoshi",
            last_name="Turtle",
            address="Mario Land",
            city="Nintendo Land",
            state="Nintendo State",
            country="Nintendo Nation",
            phone_number="2374983247",
            email="*****@*****.**",
            user=u1,
        )

        v2 = Volunteer(
            first_name="John",
            last_name="Doe",
            address="7 Alpine Street",
            city="Maplegrove",
            state="Wyoming",
            country="USA",
            phone_number="23454545",
            email="*****@*****.**",
            user=u2,
        )

        v1.save()
        v2.save()

        e1 = Event(name="Open Source Event", start_date="2012-10-22", end_date="2012-10-23")

        e1.save()

        j1 = Job(
            name="Software Developer",
            start_date="2012-10-22",
            end_date="2012-10-23",
            description="A software job",
            event=e1,
        )

        j2 = Job(
            name="Systems Administrator",
            start_date="2012-9-1",
            end_date="2012-10-26",
            description="A systems administrator job",
            event=e1,
        )

        j1.save()
        j2.save()

        s1 = Shift(date="2012-10-23", start_time="9:00", end_time="3:00", max_volunteers=1, job=j1)

        s2 = Shift(date="2012-10-23", start_time="10:00", end_time="4:00", max_volunteers=2, job=j1)

        s3 = Shift(date="2012-10-23", start_time="12:00", end_time="6:00", max_volunteers=4, job=j2)

        s1.save()
        s2.save()
        s3.save()

        # test cases where signed up
        register(v1.id, s1.id)
        register(v1.id, s2.id)
        register(v1.id, s3.id)

        register(v2.id, s1.id)
        register(v2.id, s2.id)
        register(v2.id, s3.id)

        self.assertEqual(
            get_volunteer_shift_by_id(v1.id, s1.id), VolunteerShift.objects.get(volunteer_id=v1.id, shift_id=s1.id)
        )
        self.assertEqual(
            get_volunteer_shift_by_id(v1.id, s2.id), VolunteerShift.objects.get(volunteer_id=v1.id, shift_id=s2.id)
        )
        self.assertEqual(
            get_volunteer_shift_by_id(v1.id, s3.id), VolunteerShift.objects.get(volunteer_id=v1.id, shift_id=s3.id)
        )

        # self.assertEqual(get_volunteer_shift_by_id(v2.id, s1.id),
        # VolunteerShift.objects.get(volunteer_id=v2.id, shift_id=s1.id))
        # why does this throw DoesNotExist?
        self.assertEqual(
            get_volunteer_shift_by_id(v2.id, s2.id), VolunteerShift.objects.get(volunteer_id=v2.id, shift_id=s2.id)
        )
        self.assertEqual(
            get_volunteer_shift_by_id(v2.id, s3.id), VolunteerShift.objects.get(volunteer_id=v2.id, shift_id=s3.id)
        )