def form_valid(self, form): job_id = self.kwargs['job_id'] event_id = self.request.POST.get('event_id') job = get_job_by_id(job_id) event = get_event_by_id(event_id) start_date_event = event.start_date end_date_event = event.end_date start_date_job = form.cleaned_data.get('start_date') end_date_job = form.cleaned_data.get('end_date') event_list = get_events_ordered_by_name() job_edit = check_edit_job(job_id, start_date_job, end_date_job) if not job_edit['result']: return render(self.request, 'job/edit_error.html', {'count': job_edit['invalid_count']}) if (start_date_job >= start_date_event and end_date_job <= end_date_event): job_to_edit = form.save(commit=False) if event: job_to_edit.event = event else: raise Http404 job_to_edit.save() return HttpResponseRedirect(reverse('job:list')) else: messages.add_message(self.request, messages.INFO, 'Job dates should lie within Event dates') return render(self.request, 'job/edit.html', { 'form': form, 'event_list': event_list, 'job': job })
def form_valid(self, form): job_id = self.kwargs['job_id'] job = get_job_by_id(job_id) start_date_job = job.start_date end_date_job = job.end_date shift_date = form.cleaned_data['date'] shift_start_time = form.cleaned_data['start_time'] shift_end_time = form.cleaned_data['end_time'] if (start_date_job <= shift_date <= end_date_job and shift_end_time > shift_start_time): shift = form.save(commit=False) shift.job = job shift.save() return HttpResponseRedirect( reverse('shift:list_shifts', args=(job_id, ))) else: if shift_date < start_date_job or shift_date > end_date_job: messages.add_message(self.request, messages.INFO, 'Shift date should lie within Job dates') if shift_end_time <= shift_start_time: messages.add_message( self.request, messages.INFO, 'Shift end time should be greater than start time') return render(self.request, 'shift/create.html', { 'form': form, 'job_id': job_id, 'job': job })
def form_valid(self, form): job_id = self.kwargs['job_id'] job = get_job_by_id(job_id) start_date_job = job.start_date end_date_job = job.end_date shift_date = form.cleaned_data['date'] shift_start_time = form.cleaned_data['start_time'] shift_end_time = form.cleaned_data['end_time'] if (shift_date >= start_date_job and shift_date <= end_date_job and shift_end_time > shift_start_time): shift = form.save(commit=False) shift.job = job shift.save() return HttpResponseRedirect( reverse('shift:list_shifts', args=(job_id, ))) else: if (shift_date < start_date_job or shift_date > end_date_job): messages.add_message(self.request, messages.INFO, 'Shift date should lie within Job dates') if shift_end_time <= shift_start_time: messages.add_message( self.request, messages.INFO, 'Shift end time should be greater than start time') return render(self.request, 'shift/create.html', { 'form': form, 'job_id': job_id, 'job': job })
def form_valid(self, form): job_id = self.kwargs['job_id'] event_id = self.request.POST.get('event_id') job = get_job_by_id(job_id) event = get_event_by_id(event_id) start_date_event = event.start_date end_date_event = event.end_date start_date_job = form.cleaned_data.get('start_date') end_date_job = form.cleaned_data.get('end_date') event_list = get_events_ordered_by_name() job_edit = check_edit_job(job_id, start_date_job, end_date_job) if not job_edit['result']: return render(self.request, 'job/edit_error.html', { 'count': job_edit['invalid_count'] }) if (start_date_job >= start_date_event and end_date_job <= end_date_event): job_to_edit = form.save(commit=False) if event: job_to_edit.event = event else: raise Http404 job_to_edit.save() return HttpResponseRedirect(reverse('job:list')) else: messages.add_message(self.request, messages.INFO, 'Job dates should lie within Event dates') return render(self.request, 'job/edit.html', { 'form': form, 'event_list': event_list, 'job': job })
def test_get_job_by_id(self): """ Uses jobs j1,j2,j3 """ # test typical cases self.assertIsNotNone(get_job_by_id(self.j1.id)) self.assertIsNotNone(get_job_by_id(self.j2.id)) self.assertIsNotNone(get_job_by_id(self.j3.id)) self.assertEqual(get_job_by_id(self.j1.id), self.j1) self.assertEqual(get_job_by_id(self.j2.id), self.j2) self.assertEqual(get_job_by_id(self.j3.id), self.j3) # test non-existant cases self.assertIsNone(get_job_by_id(100)) self.assertIsNone(get_job_by_id(200))
def test_get_job_by_id(self): """ Uses jobs j1,j2,j3 """ # test typical cases self.assertIsNotNone(get_job_by_id(self.j1.id)) self.assertIsNotNone(get_job_by_id(self.j2.id)) self.assertIsNotNone(get_job_by_id(self.j3.id)) self.assertEqual(get_job_by_id(self.j1.id), self.j1) self.assertEqual(get_job_by_id(self.j2.id), self.j2) self.assertEqual(get_job_by_id(self.j3.id), self.j3) # test non-existant cases self.assertIsNone(get_job_by_id(100)) self.assertIsNone(get_job_by_id(200))
def get_context_data(self, **kwargs): context = super(ShiftCreateView, self).get_context_data(**kwargs) job_id = self.kwargs['job_id'] context['job_id'] = job_id job = get_job_by_id(job_id) event = job.event context['job'] = job context['event'] = job.event context['country'] = event.country context['state'] = event.state context['city'] = event.city context['address'] = event.address context['venue'] = event.venue return context
def get_context_data(self, **kwargs): context = super(ShiftCreateView, self).get_context_data(**kwargs) job_id = self.kwargs['job_id'] context['job_id'] = job_id job = get_job_by_id(job_id) event = job.event context['job'] = job context['event'] = job.event context['country'] = event.country context['state'] = event.state context['city'] = event.city context['address'] = event.address context['venue'] = event.venue return context
def list_shifts_sign_up(request, job_id, volunteer_id): if job_id: job = get_job_by_id(job_id) if job: shift_list = [] shift_list_all = get_shifts_with_open_slots_for_volunteer( job_id, volunteer_id) for shift in shift_list_all: sdate = shift["date"] today = date.today() if sdate >= today: shift_list.append(shift) return render(request, 'shift/list_shifts_sign_up.html', { 'shift_list': shift_list, 'job': job, 'volunteer_id': volunteer_id }) else: raise Http404 else: raise Http404
def list_shifts_sign_up(request, job_id, volunteer_id): if job_id: job = get_job_by_id(job_id) if job: shift_list = [] shift_list_all = \ get_shifts_with_open_slots_for_volunteer(job_id, volunteer_id) for shift in shift_list_all: sdate = shift["date"] today = date.today() if sdate >= today: shift_list.append(shift) return render(request, 'shift/list_shifts_sign_up.html', { 'shift_list': shift_list, 'job': job, 'volunteer_id': volunteer_id }) else: raise Http404 else: raise Http404
def test_get_job_by_id(self): e1 = Event( name="Software Conference", start_date="2012-10-22", end_date="2012-10-25" ) 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 ) j3 = Job( name="Project Manager", start_date="2012-1-2", end_date="2012-2-2", description="A management job", event=e1 ) j1.save() j2.save() j3.save() # test typical cases self.assertIsNotNone(get_job_by_id(j1.id)) self.assertIsNotNone(get_job_by_id(j2.id)) self.assertIsNotNone(get_job_by_id(j3.id)) self.assertEqual(get_job_by_id(j1.id), j1) self.assertEqual(get_job_by_id(j2.id), j2) self.assertEqual(get_job_by_id(j3.id), j3) # test non-existant cases self.assertIsNone(get_job_by_id(100)) self.assertIsNone(get_job_by_id(200)) self.assertIsNone(get_job_by_id(300)) self.assertIsNone(get_job_by_id(400)) self.assertNotEqual(get_job_by_id(100), j1) self.assertNotEqual(get_job_by_id(100), j2) self.assertNotEqual(get_job_by_id(100), j3) self.assertNotEqual(get_job_by_id(200), j1) self.assertNotEqual(get_job_by_id(200), j2) self.assertNotEqual(get_job_by_id(200), j3) self.assertNotEqual(get_job_by_id(300), j1) self.assertNotEqual(get_job_by_id(300), j2) self.assertNotEqual(get_job_by_id(300), j3)