def list_events(request): """ list of filtered events :return: search_result_list: filtered events based on name, start date, end date, state, city, country, job :return: SearchEventForm """ search_result_list = get_events_ordered_by_name() if request.method == 'POST': form = SearchEventForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] start_date = form.cleaned_data['start_date'] end_date = form.cleaned_data['end_date'] city = form.cleaned_data['city'] state = form.cleaned_data['state'] country = form.cleaned_data['country'] job = form.cleaned_data['job'] search_result_list = search_events( name, start_date, end_date, city, state, country, job) else: form = SearchEventForm() return render( request, 'event/list.html', { 'form': form, 'search_result_list': search_result_list })
def form_valid(self, form): event_id = self.request.POST.get('event_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') job_name = form.cleaned_data.get('name') flag = Job.objects.filter(event=event, name=job_name).exists() event_list = get_events_ordered_by_name() if (start_date_job >= start_date_event and end_date_job <= end_date_event and not flag): job = form.save(commit=False) if event: job.event = event else: raise Http404 job.save() return HttpResponseRedirect(reverse('job:list')) else: raise_err = 'Job dates should lie within Event dates' if flag: raise_err = 'Job with the same name already exists' messages.add_message(self.request, messages.INFO, raise_err) return render(self.request, 'job/create.html', { 'form': form, 'event_list': event_list, 'last_event': event })
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 })
class ShowReportListView(LoginRequiredMixin, AdministratorLoginRequiredMixin, ListView): """ Generate the report using ListView """ template_name = "administrator/report.html" organization_list = get_organizations_ordered_by_name() event_list = get_events_ordered_by_name() job_list = get_jobs_ordered_by_title() def post(self, request, *args, **kwargs): report_list = get_administrator_report( self.request.POST['first_name'], self.request.POST['last_name'], self.request.POST['organization'], self.request.POST['event_name'], self.request.POST['job_name'], self.request.POST['start_date'], self.request.POST['end_date'], ) organization = self.request.POST['organization'] event_name = self.request.POST['event_name'] total_hours = calculate_total_report_hours(report_list) return render( request, 'administrator/report.html', { 'report_list': report_list, 'total_hours': total_hours, 'notification': True, 'organization_list': self.organization_list, 'selected_organization': organization, 'event_list': self.event_list, 'selected_event': event_name, 'job_list': self.job_list })
def list_events(request): """ list of filtered events :return: search_result_list: filtered events based on name, start date, end date, state, city, country, job :return: SearchEventForm """ search_result_list = get_events_ordered_by_name() today = datetime.date.today() if request.method == 'POST': form = SearchEventForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] start_date = form.cleaned_data['start_date'] end_date = form.cleaned_data['end_date'] city = form.cleaned_data['city'] state = form.cleaned_data['state'] country = form.cleaned_data['country'] job = form.cleaned_data['job'] search_result_list = search_events(name, start_date, end_date, city, state, country, job) else: form = SearchEventForm() return render(request, 'event/list.html', { 'form': form, 'search_result_list': search_result_list, 'today': today })
def form_valid(self, form): event_id = self.request.POST.get('event_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') job_name = form.cleaned_data.get('name') flag = Job.objects.filter(event=event, name=job_name).exists() event_list = get_events_ordered_by_name() if (start_date_job >= start_date_event and end_date_job <= end_date_event and not flag): job = form.save(commit=False) if event: job.event = event else: raise Http404 job.save() return HttpResponseRedirect(reverse('job:list')) else: raise_err = 'Job dates should lie within Event dates' if flag: raise_err = 'Job with the same name already exists' messages.add_message(self.request, messages.INFO, raise_err) return render( self.request, 'job/create.html', {'form': form, 'event_list': event_list, 'last_event': event} )
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_events_ordered_by_name(self): """ Test get_events_ordered_by_name() """ e1 = Event( name="Open Source Event", start_date="2012-10-22", end_date="2012-10-23" ) e2 = Event( name="Python Event", start_date="2013-11-12", end_date="2013-11-13" ) e3 = Event( name="Django Event", start_date="2015-07-07", end_date="2015-07-08" ) e4 = Event( name="Systers Event", start_date="2015-07-07", end_date="2015-07-08" ) e5 = Event( name="Anita Borg Event", start_date="2015-07-07", end_date="2015-07-08" ) e1.save() e2.save() e3.save() e4.save() e5.save() # test typical cases event_list = get_events_ordered_by_name() self.assertIsNotNone(event_list) self.assertIn(e1, event_list) self.assertIn(e2, event_list) self.assertIn(e3, event_list) self.assertIn(e4, event_list) self.assertIn(e5, event_list) self.assertEqual(len(event_list), 5) # test order self.assertEqual(event_list[0], e5) self.assertEqual(event_list[1], e3) self.assertEqual(event_list[2], e1) self.assertEqual(event_list[3], e2) self.assertEqual(event_list[4], e4)
class ShowFormView(AdministratorLoginRequiredMixin, FormView): """ Displays the form """ model = Administrator form_class = ReportForm template_name = "administrator/report.html" event_list = get_events_ordered_by_name() job_list = get_jobs_ordered_by_title() organization_list = get_organizations_ordered_by_name() def get(self, request, *args, **kwargs): return render( request, 'administrator/report.html', { 'event_list': self.event_list, 'organization_list': self.organization_list, 'job_list': self.job_list })
def test_get_events_ordered_by_name(self): """ Test get_events_ordered_by_name() """ # test typical cases event_list = get_events_ordered_by_name() self.assertIsNotNone(event_list) self.assertIn(self.e1, event_list) self.assertIn(self.e2, event_list) self.assertIn(self.e3, event_list) self.assertIn(self.e4, event_list) self.assertIn(self.e5, event_list) self.assertEqual(len(event_list), 5) # test order self.assertEqual(event_list[0], self.e5) self.assertEqual(event_list[1], self.e3) self.assertEqual(event_list[2], self.e1) self.assertEqual(event_list[3], self.e2) self.assertEqual(event_list[4], self.e4)
def test_get_events_ordered_by_name(self): """ Test get_events_ordered_by_name() """ # test typical cases event_list = get_events_ordered_by_name() self.assertIsNotNone(event_list) self.assertIn(self.e1, event_list) self.assertIn(self.e2, event_list) self.assertIn(self.e3, event_list) self.assertIn(self.e4, event_list) self.assertIn(self.e5, event_list) self.assertEqual(len(event_list), 5) # test order self.assertEqual(event_list[0], self.e5) self.assertEqual(event_list[1], self.e3) self.assertEqual(event_list[2], self.e1) self.assertEqual(event_list[3], self.e2) self.assertEqual(event_list[4], self.e4)
def list_sign_up(request, volunteer_id): if request.method == 'POST': form = SearchEventForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] start_date = form.cleaned_data['start_date'] end_date = form.cleaned_data['end_date'] city = form.cleaned_data['city'] state = form.cleaned_data['state'] country = form.cleaned_data['country'] search_result_list = search_events(name, start_date, end_date, city, state, country, '') else: form = SearchEventForm() search_result_list = get_events_ordered_by_name() event_list = remove_empty_events_for_volunteer(search_result_list, volunteer_id) return render( request, 'event/list_sign_up.html', { 'form': form, 'event_list': event_list, 'volunteer_id': volunteer_id, })
def list_sign_up(request, volunteer_id): if request.method == 'POST': form = SearchEventForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] start_date = form.cleaned_data['start_date'] end_date = form.cleaned_data['end_date'] city = form.cleaned_data['city'] state = form.cleaned_data['state'] country = form.cleaned_data['country'] search_result_list = search_events(name, start_date, end_date, city, state, country, '') else: form = SearchEventForm() search_result_list = get_events_ordered_by_name() event_list = remove_empty_events_for_volunteer(search_result_list, volunteer_id) return render(request, 'event/list_sign_up.html', { 'form': form, 'event_list': event_list, 'volunteer_id': volunteer_id, })
def list_sign_up(request, volunteer_id): if request.method == 'POST': form = EventDateForm(request.POST) if form.is_valid(): start_date = form.cleaned_data['start_date'] end_date = form.cleaned_data['end_date'] event_list = get_events_by_date(start_date, end_date) event_list = remove_empty_events_for_volunteer( event_list, volunteer_id) return render( request, 'event/list_sign_up.html', { 'form': form, 'event_list': event_list, 'volunteer_id': volunteer_id }) else: event_list = get_events_ordered_by_name() event_list = remove_empty_events_for_volunteer(event_list, volunteer_id) return render(request, 'event/list_sign_up.html', { 'event_list': event_list, 'volunteer_id': volunteer_id })
def get_context_data(self, **kwargs): context = super(CreateJobView, self).get_context_data(**kwargs) context['event_list'] = get_events_ordered_by_name() return context
def get_context_data(self, **kwargs): context = super(CreateJobView, self).get_context_data(**kwargs) context['event_list'] = get_events_ordered_by_name() return context