diff --git a/mapusaurus/hmda/views.py b/mapusaurus/hmda/views.py index 3d9e47c4..a9657a3d 100644 --- a/mapusaurus/hmda/views.py +++ b/mapusaurus/hmda/views.py @@ -19,17 +19,16 @@ def loan_originations(request): action_taken_param = request.GET.get('action_taken') lender_hierarchy = request.GET.get('lh') peers = request.GET.get('peers') + year = request.GET.get('year') census_tracts = get_censustract_geos(request) - query = HMDARecord.objects.all() - - #if lender param key is passed in + query = HMDARecord.objects.all() if institution_id: institution_selected = get_object_or_404(Institution, pk=institution_id) if lender_hierarchy == 'true': - hierarchy_list = institution_selected.get_lender_hierarchy(False, False) + hierarchy_list = institution_selected.get_lender_hierarchy(False, False, year) if len(hierarchy_list) > 0: - query = query.filter(institution__in=hierarchy_list) + query = query.filter(institution__in=hierarchy_list) else: query = query.filter(institution=institution_selected) elif peers == 'true' and metro: diff --git a/mapusaurus/mapping/views.py b/mapusaurus/mapping/views.py index 2b432fdc..4dde380f 100644 --- a/mapusaurus/mapping/views.py +++ b/mapusaurus/mapping/views.py @@ -19,7 +19,7 @@ def map(request, template): if lender: context['lender'] = lender - hierarchy_list = lender.get_lender_hierarchy(True, True) + hierarchy_list = lender.get_lender_hierarchy(True, True, year_selected) context['institution_hierarchy'] = hierarchy_list if metro: context['metro'] = metro diff --git a/mapusaurus/respondents/models.py b/mapusaurus/respondents/models.py index 7c68d0c8..5c16ffa6 100644 --- a/mapusaurus/respondents/models.py +++ b/mapusaurus/respondents/models.py @@ -103,11 +103,11 @@ def formatted_name(self): """ Returns a list of related institutions for the selected institution. Allows to exclude selected institution/lender and order by institution's assets """ - def get_lender_hierarchy(self, exclude, order): + def get_lender_hierarchy(self, exclude, order, year): lender_hierarchy = self.lenderhierarchy_set.first() if lender_hierarchy: org_id = lender_hierarchy.organization_id - hierarchy_list = LenderHierarchy.objects.filter(organization_id=org_id).select_related('institution') + hierarchy_list = LenderHierarchy.objects.filter(organization_id=org_id).select_related('institution').filter(institution__year=year) if exclude: hierarchy_list = hierarchy_list.exclude(institution=self) if order: diff --git a/mapusaurus/respondents/tests.py b/mapusaurus/respondents/tests.py index 3d349a29..6709392c 100644 --- a/mapusaurus/respondents/tests.py +++ b/mapusaurus/respondents/tests.py @@ -74,28 +74,28 @@ class LenderHierarchyTest(TestCase): def test_get_lender_hierarchy(self): """Case: Institution has no hierarchy""" institution = Institution.objects.filter(institution_id="11000000002").first() - hierarchy_list = institution.get_lender_hierarchy(False, False) + hierarchy_list = institution.get_lender_hierarchy(False, False, 2013) self.assertEqual(len(hierarchy_list), 0) """Case: Institution has no hierarchy but itself. Returns itself when exclude=False; Returns empy list when exclude=True """ institution = Institution.objects.filter(institution_id="91000000003").first() - hierarchy_list = institution.get_lender_hierarchy(False, False) + hierarchy_list = institution.get_lender_hierarchy(False, False, 2013) self.assertEqual(len(hierarchy_list), 1) self.assertEqual(hierarchy_list[0].institution_id, "91000000003") - hierarchy_list_exclude = institution.get_lender_hierarchy(True, False) + hierarchy_list_exclude = institution.get_lender_hierarchy(True, False, 2013) self.assertEqual(len(hierarchy_list_exclude), 0) """Case: Institution has valid hierarchy and returns it""" institution = Institution.objects.filter(institution_id="91000000001").first() - hierarchy_list = institution.get_lender_hierarchy(False, False) + hierarchy_list = institution.get_lender_hierarchy(False, False,2013) self.assertEqual(len(hierarchy_list), 3) - hierarchy_list_exclude = institution.get_lender_hierarchy(True, False) + hierarchy_list_exclude = institution.get_lender_hierarchy(True, False, 2013) self.assertEqual(len(hierarchy_list_exclude), 2) - hierarchy_list_order = institution.get_lender_hierarchy(False, True) + hierarchy_list_order = institution.get_lender_hierarchy(False, True, 2013) self.assertEqual(hierarchy_list_order[0].institution_id, "91000000001") - hierarchy_list_exclude_order = institution.get_lender_hierarchy(True, True) + hierarchy_list_exclude_order = institution.get_lender_hierarchy(True, True, 2013) self.assertEqual(hierarchy_list_exclude_order[0].institution_id, "91000000002") self.assertEqual(len(hierarchy_list_exclude_order), 2)