コード例 #1
0
ファイル: services.py プロジェクト: ahmedsabie/vms
def get_administrator_report(
                            first_name,
                            last_name,
                            organization,
                            event_name,
                            job_name,
                            start_date,
                            end_date
                            ):

    volunteer_shift_list = get_all_volunteer_shifts_with_hours()

    if first_name:
        volunteer_shift_list = volunteer_shift_list.filter(
            volunteer__first_name__icontains=first_name
            )
    if last_name:
        volunteer_shift_list = volunteer_shift_list.filter(
            volunteer__last_name__icontains=last_name
            )
    if organization:
        organization_obj = get_organization_by_name(organization)
        organization_list = get_organizations_ordered_by_name()
        if organization_obj in organization_list:
            # organization associated with a volunteer can be null
            # therefore exclude from the search query volunteers
            # with no associated organization
            # then filter by organization_name
            volunteer_shift_list = volunteer_shift_list.exclude(
                volunteer__organization__isnull=True).filter(
                volunteer__organization__name__icontains=organization
                )
        else:
            # unlisted_organization associated
            # with a volunteer can be left blank
            # therefore exclude from the search query volunteers
            # with a blank unlisted_organization
            # then filter by the unlisted organization name
            volunteer_shift_list = volunteer_shift_list.exclude(
                volunteer__unlisted_organization__exact='').filter(
                volunteer__unlisted_organization__icontains=organization
                )
    if event_name:
        volunteer_shift_list = volunteer_shift_list.filter(
            shift__job__event__name__icontains=event_name
            )
    if job_name:
        volunteer_shift_list = volunteer_shift_list.filter(
            shift__job__name__icontains=job_name
            )
    if (start_date and end_date):
        volunteer_shift_list = volunteer_shift_list.filter(
            shift__date__gte=start_date,
            shift__date__lte=end_date
            )

    report_list = generate_report(volunteer_shift_list)
    return report_list
コード例 #2
0
ファイル: services.py プロジェクト: pradeepgangwar/vms
def search_volunteers(first_name, last_name, city, state, country,
                      organization):
    """Volunteers search
    None, one, or more parameters may be sent:
    first_name, last_name, city, state, country, organization

    If no search parameters are given, it returns all volunteers

    Examples:
    search_volunteers(None, None, None, None, None, None)
    will return all volunteers
    search_volunteers("Yoshi", None, None, None, None, None)
    will return all volunteers with the first name "Yoshi"
    search_volunteers(None, "Doe", None, None, None, None)
    will return all volunteers with the last name "Doe"
    """

    # if no search parameters are given, it returns all volunteers
    search_query = Volunteer.objects.all()

    # build query based on parameters provided
    if first_name:
        search_query = search_query.filter(first_name__icontains=first_name)
    if last_name:
        search_query = search_query.filter(last_name__icontains=last_name)
    if city:
        search_query = search_query.filter(city__icontains=city)
    if state:
        search_query = search_query.filter(state__icontains=state)
    if country:
        search_query = search_query.filter(country__icontains=country)
    if organization:
        organization_obj = get_organization_by_name(organization)
        organization_list = get_organizations_ordered_by_name()
        if organization_obj in organization_list:
            # organization associated with a volunteer can be null
            # therefore exclude from the search
            # query volunteers with no associated organization
            # then filter by organization_name
            search_query = search_query.exclude(
                organization__isnull=True).filter(
                    organization__name__icontains=organization)
        else:
            # unlisted_organization associated
            # with a volunteer can be left blank
            # therefore exclude from the search query volunteers
            # with a blank unlisted_organization
            # then filter by the unlisted organization name
            search_query = search_query.exclude(
                unlisted_organization__exact='').filter(
                    unlisted_organization__icontains=organization)

    return search_query
コード例 #3
0
def get_administrator_report(first_name, last_name, organization, event_name,
                             job_name, start_date, end_date):

    volunteer_shift_list = get_all_volunteer_shifts_with_hours()

    if first_name:
        volunteer_shift_list = volunteer_shift_list.filter(
            volunteer__first_name__icontains=first_name)
    if last_name:
        volunteer_shift_list = volunteer_shift_list.filter(
            volunteer__last_name__icontains=last_name)
    if organization:
        organization_obj = get_organization_by_name(organization)
        organization_list = get_organizations_ordered_by_name()
        if organization_obj in organization_list:
            # organization associated with a volunteer can be null
            # therefore exclude from the search query volunteers
            # with no associated organization
            # then filter by organization_name
            volunteer_shift_list = volunteer_shift_list.exclude(
                volunteer__organization__isnull=True).filter(
                    volunteer__organization__name__icontains=organization)
        else:
            # unlisted_organization associated
            # with a volunteer can be left blank
            # therefore exclude from the search query volunteers
            # with a blank unlisted_organization
            # then filter by the unlisted organization name
            volunteer_shift_list = volunteer_shift_list.exclude(
                volunteer__unlisted_organization__exact='').filter(
                    volunteer__unlisted_organization__icontains=organization)
    if event_name:
        volunteer_shift_list = volunteer_shift_list.filter(
            shift__job__event__name__icontains=event_name)
    if job_name:
        volunteer_shift_list = volunteer_shift_list.filter(
            shift__job__name__icontains=job_name)
    if (start_date and end_date):
        volunteer_shift_list = volunteer_shift_list.filter(
            shift__date__gte=start_date, shift__date__lte=end_date)

    report_list = generate_report(volunteer_shift_list)
    return report_list
コード例 #4
0
ファイル: services.py プロジェクト: ahmedsabie/vms
def search_volunteers(
                        first_name,
                        last_name,
                        city,
                        state,
                        country,
                        organization
                        ):
    """Volunteers search
    None, one, or more parameters may be sent:
    first_name, last_name, city, state, country, organization

    If no search parameters are given, it returns all volunteers

    Examples:
    search_volunteers(None, None, None, None, None, None)
    will return all volunteers
    search_volunteers("Yoshi", None, None, None, None, None)
    will return all volunteers with the first name "Yoshi"
    search_volunteers(None, "Doe", None, None, None, None)
    will return all volunteers with the last name "Doe"
    """

    # if no search parameters are given, it returns all volunteers
    search_query = Volunteer.objects.all()

    # build query based on parameters provided
    if first_name:
        search_query = search_query.filter(first_name__icontains=first_name)
    if last_name:
        search_query = search_query.filter(last_name__icontains=last_name)
    if city:
        search_query = search_query.filter(city__icontains=city)
    if state:
        search_query = search_query.filter(state__icontains=state)
    if country:
        search_query = search_query.filter(country__icontains=country)
    if organization:
        organization_obj = get_organization_by_name(organization)
        organization_list = get_organizations_ordered_by_name()
        if organization_obj in organization_list:
            # organization associated with a volunteer can be null
            # therefore exclude from the search
            # query volunteers with no associated organization
            # then filter by organization_name
            search_query = search_query.exclude(
                    organization__isnull=True
                    ).filter(
                    organization__name__icontains=organization
                    )
        else:
            # unlisted_organization associated
            # with a volunteer can be left blank
            # therefore exclude from the search query volunteers
            # with a blank unlisted_organization
            # then filter by the unlisted organization name
            search_query = search_query.exclude(
                unlisted_organization__exact=''
                ).filter(
                unlisted_organization__icontains=organization
                )

    return search_query
コード例 #5
0
    def test_get_organization_by_name(self):

        # test typical cases
        self.assertIsNotNone(get_organization_by_name(self.o1.name))
        self.assertIsNotNone(get_organization_by_name(self.o2.name))
        self.assertIsNotNone(get_organization_by_name(self.o3.name))

        self.assertEqual(get_organization_by_name(self.o1.name), self.o1)
        self.assertEqual(get_organization_by_name(self.o2.name), self.o2)
        self.assertEqual(get_organization_by_name(self.o3.name), self.o3)

        self.assertIsNone(get_organization_by_name("Apple"))
        self.assertIsNone(get_organization_by_name("IBM"))
        self.assertIsNone(get_organization_by_name("Cisco"))

        self.assertNotEqual(get_organization_by_name("Apple"), self.o1)
        self.assertNotEqual(get_organization_by_name("IBM"), self.o1)
        self.assertNotEqual(get_organization_by_name("Cisco"), self.o1)

        self.assertNotEqual(get_organization_by_name("Apple"), self.o2)
        self.assertNotEqual(get_organization_by_name("IBM"), self.o2)
        self.assertNotEqual(get_organization_by_name("Cisco"), self.o2)

        self.assertNotEqual(get_organization_by_name("Apple"), self.o3)
        self.assertNotEqual(get_organization_by_name("IBM"), self.o3)
        self.assertNotEqual(get_organization_by_name("Cisco"), self.o3)
コード例 #6
0
ファイル: test_services.py プロジェクト: systers/vms
    def test_get_organization_by_name(self):

        # test typical cases
        self.assertIsNotNone(get_organization_by_name(self.o1.name))
        self.assertIsNotNone(get_organization_by_name(self.o2.name))
        self.assertIsNotNone(get_organization_by_name(self.o3.name))

        self.assertEqual(get_organization_by_name(self.o1.name), self.o1)
        self.assertEqual(get_organization_by_name(self.o2.name), self.o2)
        self.assertEqual(get_organization_by_name(self.o3.name), self.o3)

        self.assertIsNone(get_organization_by_name("Apple"))
        self.assertIsNone(get_organization_by_name("IBM"))
        self.assertIsNone(get_organization_by_name("Cisco"))

        self.assertNotEqual(get_organization_by_name("Apple"), self.o1)
        self.assertNotEqual(get_organization_by_name("IBM"), self.o1)
        self.assertNotEqual(get_organization_by_name("Cisco"), self.o1)

        self.assertNotEqual(get_organization_by_name("Apple"), self.o2)
        self.assertNotEqual(get_organization_by_name("IBM"), self.o2)
        self.assertNotEqual(get_organization_by_name("Cisco"), self.o2)

        self.assertNotEqual(get_organization_by_name("Apple"), self.o3)
        self.assertNotEqual(get_organization_by_name("IBM"), self.o3)
        self.assertNotEqual(get_organization_by_name("Cisco"), self.o3)