Ejemplo n.º 1
0
    def test_get_volunteer_report(self):

        # register volunteer for 2 shifts, log hours for one
        register(self.v1.id, self.s1.id)
        register(self.v1.id, self.s3.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)

        volunteer_shift_list_1 = get_volunteer_shifts(self.v1.id, self.e1.name,
                                                      self.j1.name,
                                                      "2012-10-22",
                                                      "2012-10-30")
        report_1 = generate_report(volunteer_shift_list_1)

        volunteer_shift_list_2 = get_volunteer_shifts(self.v1.id, self.e1.name,
                                                      self.j2.name, "2012-9-1",
                                                      "2012-10-26")
        report_2 = generate_report(volunteer_shift_list_2)

        # verify that report for logged shift appears
        self.assertEqual(len(report_1), 1)
        self.assertEqual(len(report_2), 0)
        self.assertEqual(self.e1.name, report_1[0]["event_name"])
        self.assertEqual(self.j1.name, report_1[0]["job_name"])
Ejemplo n.º 2
0
    def test_generate_report(self):
        """ Uses shifts s1, s2 and volunteer v1
        Tests test_generate_report(volunteer_shift_list) """

        # register will return an exception on error
        # (such as when invalid parameters are passed)
        # if an exception does get raised, this test will automatically fail
        start_time = datetime.time(hour=9, minute=0)
        end_time = datetime.time(hour=10, minute=0)
        register(self.v1.id, self.s1.id)
        add_shift_hours(self.v1.id, self.s1.id, start_time, end_time)
        volunteer_shift_1 = VolunteerShift.objects.get(volunteer_id=self.v1.id,
                                                       shift_id=self.s1.id)
        self.assertIsNotNone(volunteer_shift_1)

        register(self.v1.id, self.s2.id)
        add_shift_hours(self.v1.id, self.s2.id, start_time, end_time)
        volunteer_shift_2 = VolunteerShift.objects.get(volunteer_id=self.v1.id,
                                                       shift_id=self.s2.id)
        self.assertIsNotNone(volunteer_shift_2)

        volunteer_shift_list = [volunteer_shift_1, volunteer_shift_2]

        reports = generate_report(volunteer_shift_list)
        self.assertEqual(len(reports), 2)
        self.assertIsNotNone(reports)
Ejemplo n.º 3
0
    def test_generate_report(self):
        """ Uses shifts s1, s2 and volunteer v1
        Tests test_generate_report(volunteer_shift_list) """

        # register will return an exception on error
        # (such as when invalid parameters are passed)
        # if an exception does get raised, this test will automatically fail
        register(self.v1.id, self.s1.id)
        volunteer_shift_1 = VolunteerShift.objects.get(
                                volunteer_id=self.v1.id,
                                shift_id=self.s1.id
                                )
        self.assertIsNotNone(volunteer_shift_1)

        register(self.v1.id, self.s2.id)
        volunteer_shift_2 = VolunteerShift.objects.get(
                                    volunteer_id=self.v1.id,
                                    shift_id=self.s2.id
                                    )
        self.assertIsNotNone(volunteer_shift_2)

        volunteer_shift_list = [
                                volunteer_shift_1,
                                volunteer_shift_2
                                ]

        reports = generate_report(volunteer_shift_list)
        self.assertEqual(len(reports), 2)
        self.assertIsNotNone(reports)
Ejemplo n.º 4
0
Archivo: views.py Proyecto: systers/vms
 def post(self, request, *args, **kwargs):
     volunteer_id = self.kwargs['volunteer_id']
     volunteer = get_volunteer_by_id(volunteer_id)
     event_list = get_signed_up_events_for_volunteer(volunteer_id)
     job_list = get_signed_up_jobs_for_volunteer(volunteer_id)
     event_name = self.request.POST['event_name']
     job_name = self.request.POST['job_name']
     start_date = self.request.POST['start_date']
     end_date = self.request.POST['end_date']
     volunteer_shift_list = get_volunteer_shifts(volunteer_id, event_name, job_name,
                                        start_date, end_date)
     if volunteer_shift_list:
         report_list = generate_report(volunteer_shift_list)
         total_hours = calculate_total_report_hours(report_list)
         report = Report.objects.create(total_hrs=total_hours, volunteer=volunteer)
         report.volunteer_shifts.add(*volunteer_shift_list)
         report.save()
         return render(request, 'volunteer/report.html', {
                       'report_list': report_list,
                       'total_hours': total_hours,
                       'notification': True,
                       'job_list': job_list,
                       'event_list': event_list,
                       'selected_event': event_name,
                       'selected_job': job_name
                       })
     else:
         return render(request, 'volunteer/report.html', {
                       'job_list': job_list,
                       'event_list': event_list,
                       'notification': True,
                       })
Ejemplo n.º 5
0
    def test_get_volunteer_report(self):

        # register volunteer for 2 shifts, log hours for one
        register(self.v1.id, self.s1.id)
        register(self.v1.id, self.s3.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)

        volunteer_shift_list_1 = get_volunteer_shifts(self.v1.id, self.e1.name, self.j1.name,
                                        "2012-10-22", "2012-10-30")
        report_1 = generate_report(volunteer_shift_list_1)

        volunteer_shift_list_2 = get_volunteer_shifts(self.v1.id, self.e1.name, self.j2.name,
                                        "2012-9-1", "2012-10-26")
        report_2 = generate_report(volunteer_shift_list_2)

        # verify that report for logged shift appears
        self.assertEqual(len(report_1), 1)
        self.assertEqual(len(report_2), 0)
        self.assertEqual(self.e1.name, report_1[0]["event_name"])
        self.assertEqual(self.j1.name, report_1[0]["job_name"])
Ejemplo n.º 6
0
Archivo: views.py Proyecto: systers/vms
def show_report(request, report_id):
   """
   displays the report

   :param report_id: The id of pending report
   :return: report of the volunteer
   """
   report = get_report_by_id(report_id)
   volunteer_shift_list = report.volunteer_shifts.all()
   report_list = generate_report(volunteer_shift_list)
   total_hours = report.total_hrs
   return render(request, 'administrator/view_report.html', {
                 'report_list': report_list,
                  'total_hours': total_hours,
                  'report': report,
                 })
Ejemplo n.º 7
0
def show_report(request, report_id):
    """
   displays the report

   :param report_id: The id of pending report
   :return: report of the volunteer
   """
    report = get_report_by_id(report_id)
    volunteer_shift_list = report.volunteer_shifts.all()
    report_list = generate_report(volunteer_shift_list)
    total_hours = report.total_hrs
    return render(request, 'administrator/view_report.html', {
        'report_list': report_list,
        'total_hours': total_hours,
        'report': report,
    })
Ejemplo n.º 8
0
def approve(request, report_id):
    """
    approves the pending reports

    :param report_id: The id of pending report
    :return: redirect to list of pending reports
    """
    report = get_report_by_id(report_id)
    report.confirm_status = 1
    report.save()
    admin = Administrator.objects.get(user=request.user)
    volunteer_shift_list = report.volunteer_shifts.all()
    report_list = generate_report(volunteer_shift_list)
    volunteer = report.volunteer
    post_pdf = render_to_pdf(
        'administrator/pdf.html',
        {
            'report': report,
            'admin': admin,
            'report_list': report_list,
        },
    )
    message = render_to_string(
        'administrator/confirm_report.html',
        {
            'volunteer': volunteer,
            'admin': admin,
        }
    )
    msg = EmailMessage(
        "Report Approved", message,
        "*****@*****.**", [report.volunteer.email]
    )
    msg.attach('file.pdf', post_pdf, 'application/pdf')
    msg.send()
    return HttpResponseRedirect('/administrator/report')
Ejemplo n.º 9
0
 def post(self, request, *args, **kwargs):
     volunteer_id = self.kwargs['volunteer_id']
     volunteer = get_volunteer_by_id(volunteer_id)
     event_list = get_signed_up_events_for_volunteer(volunteer_id)
     job_list = get_signed_up_jobs_for_volunteer(volunteer_id)
     event_name = self.request.POST['event_name']
     job_name = self.request.POST['job_name']
     start_date = self.request.POST['start_date']
     end_date = self.request.POST['end_date']
     volunteer_shift_list = get_volunteer_shifts(volunteer_id, event_name,
                                                 job_name, start_date,
                                                 end_date)
     if volunteer_shift_list:
         report_list = generate_report(volunteer_shift_list)
         total_hours = calculate_total_report_hours(report_list)
         report = Report.objects.create(total_hrs=total_hours,
                                        volunteer=volunteer)
         report.volunteer_shifts.add(*volunteer_shift_list)
         report.save()
         return render(
             request, 'volunteer/report.html', {
                 'report_list': report_list,
                 'total_hours': total_hours,
                 'notification': True,
                 'job_list': job_list,
                 'event_list': event_list,
                 'selected_event': event_name,
                 'selected_job': job_name
             })
     else:
         return render(
             request, 'volunteer/report.html', {
                 'job_list': job_list,
                 'event_list': event_list,
                 'notification': True,
             })
Ejemplo n.º 10
0
    def test_generate_report(self):
        """ Tests test_generate_report(volunteer_shift_list) """
        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,
        )

        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()

        shift_list = [s1, s2, s3]

        self.assertIsNotNone(shift_list)
        self.assertNotEqual(shift_list, False)
        self.assertEqual(len(shift_list), 3)
        self.assertIn(s1, shift_list)
        self.assertIn(s2, shift_list)
        self.assertIn(s3, shift_list)

        # register will return an exception on error
        # (such as when invalid parameters are passed)
        # if an exception does get raised, this test will automatically fail
        register(v1.id, s1.id)
        volunteer_shift_1 = VolunteerShift.objects.get(volunteer_id=v1.id, shift_id=s1.id)
        self.assertIsNotNone(volunteer_shift_1)

        register(v1.id, s2.id)
        volunteer_shift_2 = VolunteerShift.objects.get(volunteer_id=v1.id, shift_id=s2.id)
        self.assertIsNotNone(volunteer_shift_2)

        register(v1.id, s3.id)
        volunteer_shift_3 = VolunteerShift.objects.get(volunteer_id=v1.id, shift_id=s3.id)
        self.assertIsNotNone(volunteer_shift_3)

        volunteer_shift_list = [volunteer_shift_1, volunteer_shift_2, volunteer_shift_3]

        self.assertIsNotNone(generate_report(volunteer_shift_list))