Exemple #1
0
 def test_get_related_lenders(self):
     testAgency = Agency.objects.get(pk=9)
     LenderHierarchy.objects.create(agency=testAgency, respondent_id='1234', organization_id=9999)
     LenderHierarchy.objects.create(agency=testAgency, respondent_id='5678', organization_id=9999)
     LenderHierarchy.objects.create(agency=testAgency, respondent_id='5678', organization_id=1111)
     lenders = lender_hierarchy_utils.get_related_lenders('91234')
     self.assertEquals(len(lenders[0]), 2)
Exemple #2
0
def loan_originations(request):
    """Get loan originations for a given lender, county combination. This
    ignores year for the moment."""
    lender_id = request.GET.get('lender')
    action_taken_param = request.GET.get('action_taken')
    lender_hierarchy = request.GET.get('lh')
    geoids = get_censustract_geoids(request)
    action_taken = action_taken_param.split(',')
    if lender_hierarchy == 'true':
        lenders = get_related_lenders(lender_id)
        if len(lenders[0]) == 0:
            return HttpResponseRequest("No other lenders found in hierarchy. Invalid lender")
        if geoids and lenders and action_taken:
            query = HMDARecord.objects.filter(
                # actions 7-8 are preapprovals to ignore
                property_type__in=[1,2], owner_occupancy=1, lien_status=1,
                lender__in=lenders[0], action_taken__in=action_taken
            ).filter(geoid_id__in=geoids).values(
                'geoid', 'geoid__census2010households__total'
            ).annotate(volume=Count('geoid'))
            return query
    elif lender_hierarchy == 'false' and geoids and lender_id and action_taken:
        query = HMDARecord.objects.filter(
            # actions 7-8 are preapprovals to ignore
            property_type__in=[1,2], owner_occupancy=1, lien_status=1,
            lender=lender_id, action_taken__in=action_taken
        ).filter(geoid_id__in=geoids).values(
            'geoid', 'geoid__census2010households__total'
        ).annotate(volume=Count('geoid'))
        return query
    else:
        return HttpResponseBadRequest("Missing one of lender, action_taken and county or geoid.")
Exemple #3
0
 def test_get_related_lenders(self):
     testAgency = Agency.objects.get(pk=9)
     LenderHierarchy.objects.create(agency=testAgency,
                                    respondent_id='1234',
                                    organization_id=9999)
     LenderHierarchy.objects.create(agency=testAgency,
                                    respondent_id='5678',
                                    organization_id=9999)
     LenderHierarchy.objects.create(agency=testAgency,
                                    respondent_id='5678',
                                    organization_id=1111)
     lenders = lender_hierarchy_utils.get_related_lenders('91234')
     self.assertEquals(len(lenders[0]), 2)
Exemple #4
0
def loan_originations(request):
    """Get loan originations for a given lender, county combination. This
    ignores year for the moment."""
    lender_id = request.GET.get('lender')
    action_taken_param = request.GET.get('action_taken')
    lender_hierarchy = request.GET.get('lh')
    geoids = get_censustract_geoids(request)
    action_taken = action_taken_param.split(',')
    if lender_hierarchy == 'true':
        lenders = get_related_lenders(lender_id)
        if len(lenders[0]) == 0:
            return HttpResponseRequest(
                "No other lenders found in hierarchy. Invalid lender")
        if geoids and lenders and action_taken:
            query = HMDARecord.objects.filter(
                # actions 7-8 are preapprovals to ignore
                property_type__in=[1, 2],
                owner_occupancy=1,
                lien_status=1,
                lender__in=lenders[0],
                action_taken__in=action_taken).filter(
                    geoid_id__in=geoids).values(
                        'geoid',
                        'geoid__census2010households__total').annotate(
                            volume=Count('geoid'))
            return query
    elif lender_hierarchy == 'false' and geoids and lender_id and action_taken:
        query = HMDARecord.objects.filter(
            # actions 7-8 are preapprovals to ignore
            property_type__in=[1, 2],
            owner_occupancy=1,
            lien_status=1,
            lender=lender_id,
            action_taken__in=action_taken).filter(geoid_id__in=geoids).values(
                'geoid', 'geoid__census2010households__total').annotate(
                    volume=Count('geoid'))
        return query
    else:
        return HttpResponseBadRequest(
            "Missing one of lender, action_taken and county or geoid.")