def form_valid(self, form): edit_request_id = self.kwargs['edit_request_id'] edit_request = EditRequest.objects.get(pk=edit_request_id) volunteer_id = self.kwargs['volunteer_id'] volunteer = get_volunteer_by_id(volunteer_id) shift_id = self.kwargs['shift_id'] shift = get_shift_by_id(shift_id) event = shift.job.event 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) vol_email = volunteer.email message = render_to_string( 'shift/request_status.html', { 'volunteer_first_name': volunteer.first_name, 'event': event }) try: send_mail("Log Hours Edited", message, "*****@*****.**", [vol_email]) except Exception: raise Exception("There was an error in sending mail.") 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, 'edit_request_id': edit_request_id, }) 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, 'edit_request_id': edit_request_id, }) except Exception: raise Http404
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
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
def test_edit_shift_hours(self): """ Uses shift s1 and volunteer v1 """ register(self.v1.id, self.s1.id) self.assertIsNotNone( VolunteerShift.objects.get(volunteer_id=self.v1.id, shift_id=self.s1.id)) start_time = datetime.time(hour=9, minute=0) end_time = datetime.time(hour=10, minute=0) add_shift_hours(self.v1.id, self.s1.id, start_time, end_time) start_time = datetime.time(hour=10, minute=0) end_time = datetime.time(hour=11, minute=0) edit_shift_hours(self.v1.id, self.s1.id, start_time, end_time) volunteer_shift = VolunteerShift.objects.get(volunteer_id=self.v1.id, shift_id=self.s1.id) self.assertIsNotNone(volunteer_shift.start_time) self.assertIsNotNone(volunteer_shift.end_time) self.assertEqual(volunteer_shift.start_time, start_time) self.assertEqual(volunteer_shift.end_time, end_time) start_time = datetime.time(hour=1, minute=0) end_time = datetime.time(hour=4, minute=0) edit_shift_hours(self.v1.id, self.s1.id, start_time, end_time) volunteer_shift = VolunteerShift.objects.get(volunteer_id=self.v1.id, shift_id=self.s1.id) self.assertIsNotNone(volunteer_shift.start_time) self.assertIsNotNone(volunteer_shift.end_time) self.assertEqual(volunteer_shift.start_time, start_time) self.assertEqual(volunteer_shift.end_time, end_time) start_time = datetime.time(hour=4, minute=15) end_time = datetime.time(hour=12, minute=35) edit_shift_hours(self.v1.id, self.s1.id, start_time, end_time) volunteer_shift = VolunteerShift.objects.get(volunteer_id=self.v1.id, shift_id=self.s1.id) self.assertIsNotNone(volunteer_shift.start_time) self.assertIsNotNone(volunteer_shift.end_time) self.assertEqual(volunteer_shift.start_time, start_time) self.assertEqual(volunteer_shift.end_time, end_time) start_time = datetime.time(hour=2, minute=5) end_time = datetime.time(hour=4, minute=15) edit_shift_hours(self.v1.id, self.s1.id, start_time, end_time) volunteer_shift = VolunteerShift.objects.get(volunteer_id=self.v1.id, shift_id=self.s1.id) self.assertIsNotNone(volunteer_shift.start_time) self.assertIsNotNone(volunteer_shift.end_time) self.assertEqual(volunteer_shift.start_time, start_time) self.assertEqual(volunteer_shift.end_time, end_time) start_time = datetime.time(hour=5, minute=0) end_time = datetime.time(hour=5, minute=30) edit_shift_hours(self.v1.id, self.s1.id, start_time, end_time) volunteer_shift = VolunteerShift.objects.get(volunteer_id=self.v1.id, shift_id=self.s1.id) self.assertIsNotNone(volunteer_shift.start_time) self.assertIsNotNone(volunteer_shift.end_time) self.assertEqual(volunteer_shift.start_time, start_time) self.assertEqual(volunteer_shift.end_time, end_time)
def form_valid(self, form): edit_request_id = self.kwargs['edit_request_id'] edit_request = EditRequest.objects.get(pk=edit_request_id) volunteer_id = self.kwargs['volunteer_id'] volunteer = get_volunteer_by_id(volunteer_id) shift_id = self.kwargs['shift_id'] shift = get_shift_by_id(shift_id) event = shift.job.event 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) vol_email = volunteer.email message = render_to_string('shift/request_status.html', {'volunteer_first_name': volunteer.first_name, 'event': event }) try: send_mail("Log Hours Edited", message, "*****@*****.**", [vol_email]) except: raise Exception("There was an error in sending mail.") 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, 'edit_request_id': edit_request_id, }) 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, 'edit_request_id': edit_request_id, }) except: raise Http404
def test_edit_shift_hours(self): """ Uses shift s1 and volunteer v1 """ register(self.v1.id, self.s1.id) self.assertIsNotNone(VolunteerShift.objects.get( volunteer_id=self.v1.id, shift_id=self.s1.id )) start_time = datetime.time(hour=9, minute=0) end_time = datetime.time(hour=10, minute=0) add_shift_hours(self.v1.id, self.s1.id, start_time, end_time) start_time = datetime.time(hour=10, minute=0) end_time = datetime.time(hour=11, minute=0) edit_shift_hours(self.v1.id, self.s1.id, start_time, end_time) volunteer_shift = VolunteerShift.objects.get( volunteer_id=self.v1.id, shift_id=self.s1.id ) self.assertIsNotNone(volunteer_shift.start_time) self.assertIsNotNone(volunteer_shift.end_time) self.assertEqual(volunteer_shift.start_time, start_time) self.assertEqual(volunteer_shift.end_time, end_time) start_time = datetime.time(hour=1, minute=0) end_time = datetime.time(hour=4, minute=0) edit_shift_hours(self.v1.id, self.s1.id, start_time, end_time) volunteer_shift = VolunteerShift.objects.get( volunteer_id=self.v1.id, shift_id=self.s1.id ) self.assertIsNotNone(volunteer_shift.start_time) self.assertIsNotNone(volunteer_shift.end_time) self.assertEqual(volunteer_shift.start_time, start_time) self.assertEqual(volunteer_shift.end_time, end_time) start_time = datetime.time(hour=4, minute=15) end_time = datetime.time(hour=12, minute=35) edit_shift_hours(self.v1.id, self.s1.id, start_time, end_time) volunteer_shift = VolunteerShift.objects.get( volunteer_id=self.v1.id, shift_id=self.s1.id ) self.assertIsNotNone(volunteer_shift.start_time) self.assertIsNotNone(volunteer_shift.end_time) self.assertEqual(volunteer_shift.start_time, start_time) self.assertEqual(volunteer_shift.end_time, end_time) start_time = datetime.time(hour=2, minute=5) end_time = datetime.time(hour=4, minute=15) edit_shift_hours(self.v1.id, self.s1.id, start_time, end_time) volunteer_shift = VolunteerShift.objects.get( volunteer_id=self.v1.id, shift_id=self.s1.id ) self.assertIsNotNone(volunteer_shift.start_time) self.assertIsNotNone(volunteer_shift.end_time) self.assertEqual(volunteer_shift.start_time, start_time) self.assertEqual(volunteer_shift.end_time, end_time) start_time = datetime.time(hour=5, minute=0) end_time = datetime.time(hour=5, minute=30) edit_shift_hours(self.v1.id, self.s1.id, start_time, end_time) volunteer_shift = VolunteerShift.objects.get( volunteer_id=self.v1.id, shift_id=self.s1.id ) self.assertIsNotNone(volunteer_shift.start_time) self.assertIsNotNone(volunteer_shift.end_time) self.assertEqual(volunteer_shift.start_time, start_time) self.assertEqual(volunteer_shift.end_time, end_time)
def test_edit_shift_hours(self): u1 = User.objects.create_user("Yoshi") 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, ) v1.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, ) j1.save() s1 = Shift(date="2012-10-23", start_time="1:00", end_time="12:00", max_volunteers=1, job=j1) s1.save() register(v1.id, s1.id) self.assertIsNotNone(VolunteerShift.objects.get(volunteer_id=v1.id, shift_id=s1.id)) start_time = datetime.time(hour=9, minute=0) end_time = datetime.time(hour=10, minute=0) add_shift_hours(v1.id, s1.id, start_time, end_time) start_time = datetime.time(hour=10, minute=0) end_time = datetime.time(hour=11, minute=0) edit_shift_hours(v1.id, s1.id, start_time, end_time) volunteer_shift = VolunteerShift.objects.get(volunteer_id=v1.id, shift_id=s1.id) self.assertIsNotNone(volunteer_shift.start_time) self.assertIsNotNone(volunteer_shift.end_time) self.assertEqual(volunteer_shift.start_time, start_time) self.assertEqual(volunteer_shift.end_time, end_time) start_time = datetime.time(hour=1, minute=0) end_time = datetime.time(hour=4, minute=0) edit_shift_hours(v1.id, s1.id, start_time, end_time) volunteer_shift = VolunteerShift.objects.get(volunteer_id=v1.id, shift_id=s1.id) self.assertIsNotNone(volunteer_shift.start_time) self.assertIsNotNone(volunteer_shift.end_time) self.assertEqual(volunteer_shift.start_time, start_time) self.assertEqual(volunteer_shift.end_time, end_time) start_time = datetime.time(hour=4, minute=15) end_time = datetime.time(hour=12, minute=35) edit_shift_hours(v1.id, s1.id, start_time, end_time) volunteer_shift = VolunteerShift.objects.get(volunteer_id=v1.id, shift_id=s1.id) self.assertIsNotNone(volunteer_shift.start_time) self.assertIsNotNone(volunteer_shift.end_time) self.assertEqual(volunteer_shift.start_time, start_time) self.assertEqual(volunteer_shift.end_time, end_time) start_time = datetime.time(hour=2, minute=5) end_time = datetime.time(hour=4, minute=15) edit_shift_hours(v1.id, s1.id, start_time, end_time) volunteer_shift = VolunteerShift.objects.get(volunteer_id=v1.id, shift_id=s1.id) self.assertIsNotNone(volunteer_shift.start_time) self.assertIsNotNone(volunteer_shift.end_time) self.assertEqual(volunteer_shift.start_time, start_time) self.assertEqual(volunteer_shift.end_time, end_time) start_time = datetime.time(hour=5, minute=0) end_time = datetime.time(hour=5, minute=30) edit_shift_hours(v1.id, s1.id, start_time, end_time) volunteer_shift = VolunteerShift.objects.get(volunteer_id=v1.id, shift_id=s1.id) self.assertIsNotNone(volunteer_shift.start_time) self.assertIsNotNone(volunteer_shift.end_time) self.assertEqual(volunteer_shift.start_time, start_time) self.assertEqual(volunteer_shift.end_time, end_time)