Beispiel #1
0
def partner_library(request):
    company = get_company_or_404(request)

    if request.is_ajax():
        partners = filter_partners(request, True)
        paginator = add_pagination(request, partners)
        ctx = {
            'partners': paginator,
            'on_page': 'partner_library'
        }
        response = HttpResponse()
        html = render_to_response('mypartners/includes/partner_column.html',
                                  ctx, RequestContext(request))
        response.content = html.content
        return response

    partners = filter_partners(request, True)
    paginator = add_pagination(request, partners)

    ctx = {
        'company': company,
        'view_name': 'PRM',
        'partners': paginator
    }

    return render_to_response('mypartners/partner_library.html', ctx,
                              RequestContext(request))
Beispiel #2
0
def prm(request):
    """
    Partner Relationship Manager

    """
    company = get_company_or_404(request)

    partners = filter_partners(request)
    paginator = add_pagination(request, partners) if partners else None

    if request.is_ajax():
        ctx = {"partners": paginator, "on_page": "prm", "ajax": "true"}
        response = HttpResponse()
        html = render_to_response("mypartners/includes/partner_column.html", ctx, RequestContext(request))
        response.content = html.content
        return response

    ctx = {
        "has_partners": True if paginator else False,
        "partners": paginator,
        "company": company,
        "user": request.user,
        "partner_ct": ContentType.objects.get_for_model(Partner).id,
        "view_name": "PRM",
    }

    return render_to_response("mypartners/prm.html", ctx, RequestContext(request))
Beispiel #3
0
def prm(request):
    """
    Partner Relationship Manager

    """
    company = get_company_or_404(request)

    partners = filter_partners(request)
    paginator = add_pagination(request, partners) if partners else None

    if request.is_ajax():
        ctx = {
            'partners': paginator,
            'on_page': 'prm',
            'ajax': 'true',
        }
        response = HttpResponse()
        html = render_to_response('mypartners/includes/partner_column.html',
                                  ctx, RequestContext(request))
        response.content = html.content
        return response

    ctx = {
        'has_partners': True if paginator else False,
        'partners': paginator,
        'company': company,
        'user': request.user,
        'partner_ct': ContentType.objects.get_for_model(Partner).id,
        'view_name': 'PRM',
    }

    return render_to_response('mypartners/prm.html', ctx,
                              RequestContext(request))
Beispiel #4
0
def partner_library(request):
    company = get_company_or_404(request)

    if request.is_ajax():
        partners = filter_partners(request, True)
        paginator = add_pagination(request, partners)
        ctx = {"partners": paginator, "on_page": "partner_library"}
        response = HttpResponse()
        html = render_to_response("mypartners/includes/partner_column.html", ctx, RequestContext(request))
        response.content = html.content
        return response

    partners = filter_partners(request, True)
    paginator = add_pagination(request, partners)

    ctx = {"company": company, "view_name": "PRM", "partners": paginator}

    return render_to_response("mypartners/partner_library.html", ctx, RequestContext(request))
Beispiel #5
0
    def test_all_ofccp_partners_available(self):
        """
        When a company doesn't have any OFCCP partners, they should all be
        available to choose from in the partner library search.
        """
        partner_count = self.partner_library.count()
        request = self.request_factory.get(
            'prm/view/partner-library/', dict(company=self.company.id))
        request.user = self.staff_user

        partners = helpers.filter_partners(request, partner_library=True)

        self.assertEqual(len(partners), partner_count)
Beispiel #6
0
    def test_all_ofccp_partners_available(self):
        """
        When a company doesn't have any OFCCP partners, they should all be
        available to choose from in the partner library search.
        """
        partner_count = self.partner_library.count()
        request = self.request_factory.get(
            'prm/view/partner-library/', dict(company=self.company.id))
        request.user = self.staff_user

        partners = helpers.filter_partners(request, partner_library=True)

        self.assertEqual(len(partners), partner_count)
Beispiel #7
0
    def test_city_filter(self):
        """
        Filter by city.
        """

        request = self.request_factory.get(
            'prm/view/partner-library/', dict(
                company=self.company.id,
                city='Pittsburgh'))
        request.user = self.staff_user

        partners = helpers.filter_partners(request, partner_library=True)
        self.assertTrue(partners)

        for partner in partners:
            self.assertEqual(partner.city, 'Pittsburgh')
Beispiel #8
0
    def test_state_filter(self):
        """
        Filter by state.
        """

        request = self.request_factory.get(
            'prm/view/partner-library/', dict(
                company=self.company.id,
                state='PA'))
        request.user = self.staff_user

        partners = helpers.filter_partners(request, partner_library=True)
        self.assertTrue(partners)

        for partner in partners:
            self.assertEqual(partner.st, 'PA')
Beispiel #9
0
    def test_city_filter(self):
        """
        Filter by city.
        """

        request = self.request_factory.get(
            'prm/view/partner-library/', dict(
                company=self.company.id,
                city='Pittsburgh'))
        request.user = self.staff_user

        partners = helpers.filter_partners(request, partner_library=True)
        self.assertTrue(partners)

        for partner in partners:
            self.assertEqual(partner.city, 'Pittsburgh')
Beispiel #10
0
    def test_state_filter(self):
        """
        Filter by state.
        """

        request = self.request_factory.get(
            'prm/view/partner-library/', dict(
                company=self.company.id,
                state='PA'))
        request.user = self.staff_user

        partners = helpers.filter_partners(request, partner_library=True)
        self.assertTrue(partners)

        for partner in partners:
            self.assertEqual(partner.st, 'PA')
Beispiel #11
0
    def test_ofccp_duplicates_ignored(self):
        """
        When a company has already added OFCCP partners, those partners should
        not be displayed in the filter search results.
        """

        # create a new partner
        library_id = random.randint(1, self.partner_library.count())
        request = self.request_factory.get(
            'prm/view/partner-library/add', dict(
                company=self.company.id, library_id=library_id))
        request.user = self.staff_user
        partner = helpers.new_partner_from_library(request)

        # get a list of OFCCP partners
        request = self.request_factory.get(
            'prm/view/partner-library', dict(company=self.company.id))
        request.user = self.staff_user
        library = helpers.filter_partners(request, partner_library=True)

        self.assertFalse(partner.library.id in [p.id for p in library])
Beispiel #12
0
    def test_ofccp_duplicates_ignored(self):
        """
        When a company has already added OFCCP partners, those partners should
        not be displayed in the filter search results.
        """

        # create a new partner
        library_id = random.randint(1, self.partner_library.count())
        request = self.request_factory.get(
            'prm/view/partner-library/add', dict(
                company=self.company.id, library_id=library_id))
        request.user = self.staff_user
        partner = helpers.new_partner_from_library(request)

        # get a list of OFCCP partners
        request = self.request_factory.get(
            'prm/view/partner-library', dict(company=self.company.id))
        request.user = self.staff_user
        library = helpers.filter_partners(request, partner_library=True)

        self.assertFalse(partner.library.id in [p.id for p in library])
Beispiel #13
0
    def test_date_filters(self):
        """
        Filter by activity start and end date.

        """
        end_date = datetime.now().date()

        # randomly create partners and assign them contact records ranging from
        # 60 days ago to now.
        partners = [PartnerFactory(owner=self.company) for i in range(3)]
        partners.append(self.partner)

        # we want the contact records to exist before the tests, hence the
        # second for loop
        for days in [60, 30, 1, 0]:
            ContactRecordFactory(partner=random.choice(partners),
                                 date_time=end_date - timedelta(days))

        for days in [60, 30, 1, 0]:
            start_date = (datetime.now() - timedelta(days)).date()

            request = self.request_factory.get(
                'prm/view/partner-library', dict(
                    company=self.company.id,
                    start_date=start_date.strftime("%m/%d/%Y"),
                    end_date=end_date.strftime("%m/%d/%Y")))
            request.user = self.staff_user

            partners = helpers.filter_partners(request)

            for partner in partners:
                date_times = [c.date_time.date()
                              for c in partner.contactrecord_set.all()]

                # ensure that for each partner, at least one contact record is
                # within range
                if partner.contactrecord_set.all():
                    self.assertTrue(filter(
                        lambda x: start_date <= x <= end_date , date_times))
Beispiel #14
0
    def test_keyword_filter(self):
        """
        When a user tries to filter using keywords, the partner name, partner
        URI, and contact name should be searched.
        """

        request = self.request_factory.get(
            'prm/view/partner-library/', dict(
                company=self.company.id,
                keywords='center, .org'))
        request.user = self.staff_user

        partners = helpers.filter_partners(request, partner_library=True)
        self.assertTrue(partners)

        for partner in partners:
            searchable_fields = " ".join(
                [partner.name, partner.uri, partner.contact_name,
                 partner.email]).lower()

            self.assertIn('center', searchable_fields)
            self.assertIn('.org', searchable_fields)
Beispiel #15
0
    def test_date_filters(self):
        """
        Filter by activity start and end date.

        """
        end_date = datetime.now().date()

        # randomly create partners and assign them contact records ranging from
        # 60 days ago to now.
        partners = [PartnerFactory(owner=self.company) for i in range(3)]
        partners.append(self.partner)

        # we want the contact records to exist before the tests, hence the
        # second for loop
        for days in [60, 30, 1, 0]:
            ContactRecordFactory(partner=random.choice(partners),
                                 date_time=end_date - timedelta(days))

        for days in [60, 30, 1, 0]:
            start_date = (datetime.now() - timedelta(days)).date()

            request = self.request_factory.get(
                'prm/view/partner-library', dict(
                    company=self.company.id,
                    start_date=start_date.strftime("%m/%d/%Y"),
                    end_date=end_date.strftime("%m/%d/%Y")))
            request.user = self.staff_user

            partners = helpers.filter_partners(request)

            for partner in partners:
                date_times = [c.date_time.date()
                              for c in partner.contactrecord_set.all()]

                # ensure that for each partner, at least one contact record is
                # within range
                if partner.contactrecord_set.all():
                    self.assertTrue(filter(
                        lambda x: start_date <= x <= end_date , date_times))
Beispiel #16
0
    def test_keyword_filter(self):
        """
        When a user tries to filter using keywords, the partner name, partner
        URI, and contact name should be searched.
        """

        request = self.request_factory.get(
            'prm/view/partner-library/', dict(
                company=self.company.id,
                keywords='center, .org'))
        request.user = self.staff_user

        partners = helpers.filter_partners(request, partner_library=True)
        self.assertTrue(partners)

        for partner in partners:
            searchable_fields = " ".join(
                [partner.name, partner.uri, partner.contact_name,
                 partner.email]).lower()

            self.assertIn('center', searchable_fields)
            self.assertIn('.org', searchable_fields)