Skip to content

Commit

Permalink
Merge pull request #581 from fecgov/release/sprint-33
Browse files Browse the repository at this point in the history
Release/sprint 33
  • Loading branch information
dheitzer authored Nov 16, 2023
2 parents b599a42 + 3551de8 commit a5543f2
Show file tree
Hide file tree
Showing 48 changed files with 1,668 additions and 97 deletions.
17 changes: 9 additions & 8 deletions .safety.dependency.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
# Example:
# 40104 2022-01-15
#
52945 2023-12-01 # django
53315 2023-12-01 # django
59293 2023-12-01 # django
55264 2023-12-01 # django
60350 2023-12-01 # django
60841 2023-12-01 # django
60789 2023-12-01 # django
60956 2023-12-01 # django
52945 2024-01-01 # django
53315 2024-01-01 # django
59293 2024-01-01 # django
55264 2024-01-01 # django
60350 2024-01-01 # django
60841 2024-01-01 # django
60789 2024-01-01 # django
60956 2024-01-01 # django
61586 2024-01-01 # django
29 changes: 16 additions & 13 deletions django-backend/fecfiler/contacts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,18 @@ def candidate_lookup(self, request):
return HttpResponseBadRequest()

max_fecfile_results, max_fec_results = self.get_max_results(request)

params = urlencode({"q": q, "api_key": FEC_API_KEY})
office = request.GET.get("office", "")
params = {"q": q, "api_key": FEC_API_KEY}
if office:
params["office"] = office
params = urlencode(params)
json_results = requests.get(
FEC_API_CANDIDATE_LOOKUP_ENDPOINT, params=params
).json()

tokens = list(filter(None, re.split("[^\\w+]", q)))
term = (".*" + ".* .*".join(tokens) + ".*").lower()
fecfile_candidates = list(
query_set = (
self.get_queryset()
.annotate(
full_name_fwd=Lower(NAME_CLAUSE),
Expand All @@ -102,17 +105,20 @@ def candidate_lookup(self, request):
.values()
.order_by("-candidate_id")
)
if office:
query_set = query_set.filter(candidate_office=office)
fecfile_candidates = list(query_set)
fec_api_candidates = json_results.get("results", [])
fec_api_candidates = [
fac
for fac in fec_api_candidates
if not any(fac["id"] == ffc["candidate_id"] for ffc in fecfile_candidates)
if not any(
fac["candidate_id"] == ffc["candidate_id"] for ffc in fecfile_candidates
)
]
fec_api_candidates = fec_api_candidates[:max_fec_results]
fecfile_candidates = fecfile_candidates[:max_fecfile_results]
return_value = {
"fec_api_candidates": fec_api_candidates,
"fecfile_candidates": fecfile_candidates,
"fec_api_candidates": fec_api_candidates[:max_fec_results],
"fecfile_candidates": fecfile_candidates[:max_fecfile_results],
}

return JsonResponse(return_value)
Expand Down Expand Up @@ -240,9 +246,7 @@ def get_max_results(self, request):


class DeletedContactsViewSet(
CommitteeOwnedViewSet,
mixins.ListModelMixin,
GenericViewSet,
CommitteeOwnedViewSet, mixins.ListModelMixin, GenericViewSet,
):
serializer_class = ContactSerializer

Expand Down Expand Up @@ -273,8 +277,7 @@ def restore(self, request):
contacts = self.queryset.filter(id__in=ids_to_restore)
if len(ids_to_restore) != contacts.count():
return Response(
"Contact Ids are invalid",
status=status.HTTP_400_BAD_REQUEST,
"Contact Ids are invalid", status=status.HTTP_400_BAD_REQUEST,
)
for contact in contacts:
contact.deleted = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,5 +484,59 @@
"custodian_zip": "37208",
"custodian_name_title": "President",
"custodian_phone": "8175212197"
},
{
"committee_id": "C00100933",
"name": "Sarah for Congress",
"committee_type_full": "House",
"street_1": "1050 First Street, NE ",
"city": "Washington",
"state": "District of Columbia",
"zip": "20002",
"email": "[email protected]",
"treasurer_name_1": "Ryan",
"treasurer_name_2": "Lanz",
"treasurer_street_1": "1 Apple Park Way",
"treasurer_city": "Cupertino",
"treasurer_state": "CA",
"treasurer_zip": "95014",
"treasurer_phone": "8175212197",
"custodian_name_full": "Clark, Paul",
"custodian_name_1": "Paul",
"custodian_name_2": "Clark",
"custodian_street_1": "1 Apple Park Way",
"custodian_city": "Cupertino",
"custodian_state": "CA",
"custodian_zip": "95014",
"custodian_name_title": "Custodian of record",
"filing_frequency": "A",
"committee_type": "H"
},
{
"committee_id": "C00100941",
"name": "Michael for Congress",
"committee_type_full": "House",
"street_1": "1050 First Street, NE ",
"city": "Washington",
"state": "District of Columbia",
"zip": "20002",
"email": "[email protected]",
"treasurer_name_1": "Ryan",
"treasurer_name_2": "Lanz",
"treasurer_street_1": "1 Apple Park Way",
"treasurer_city": "Cupertino",
"treasurer_state": "CA",
"treasurer_zip": "95014",
"treasurer_phone": "8175212197",
"custodian_name_full": "Colucci, Marlene",
"custodian_name_1": "Marlene",
"custodian_name_2": "Colucci",
"custodian_street_1": "1 Apple Park Way",
"custodian_city": "Cupertino",
"custodian_state": "CA",
"custodian_zip": "95014",
"custodian_name_title": "Custodian of record",
"filing_frequency": "A",
"committee_type": "H"
}
]
71 changes: 40 additions & 31 deletions django-backend/fecfiler/reports/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,29 +95,35 @@ def pull_forward_loans(self):
)

for loan in loans_to_pull_forward:
# Save children as they are lost from the loan object
# when the loan is saved
loan_children = copy.deepcopy(loan.children)

loan.schedule_c_id = self.save_copy(loan.schedule_c)
loan.memo_text_id = self.save_copy(loan.memo_text)
loan.report_id = self.id
loan.report = self
# The loan_id should point to the original loan transaction
# even if the loan is pulled forward multiple times.
loan.loan_id = loan.loan_id if loan.loan_id else loan.id
self.save_copy(loan)
for child in loan_children:
# If child is a guarantor transaction, copy it
# and link it to the new loan
if child.schedule_c2_id:
child.schedule_c2_id = self.save_copy(child.schedule_c2)
child.memo_text_id = self.save_copy(child.memo_text)
child.report_id = self.id
child.report = self
child.parent_transaction_id = loan.id
child.parent_transaction = loan
self.save_copy(child)
self.pull_forward_loan(loan)

def pull_forward_loan(self, loan):
# Save children as they are lost from the loan object
# when the loan is saved
loan_children = copy.deepcopy(loan.children)

loan.schedule_c_id = self.save_copy(loan.schedule_c)
loan.memo_text_id = self.save_copy(loan.memo_text)
loan.report_id = self.id
loan.report = self
# The loan_id should point to the original loan transaction
# even if the loan is pulled forward multiple times.
loan.loan_id = loan.loan_id if loan.loan_id else loan.id
self.save_copy(loan)
for child in loan_children:
# If child is a guarantor transaction, copy it
# and link it to the new loan
if child.schedule_c2_id:
self.pull_forward_loan_guarantor(child, loan)

def pull_forward_loan_guarantor(self, loan_guarantor, loan):
loan_guarantor.schedule_c2_id = self.save_copy(loan_guarantor.schedule_c2)
loan_guarantor.memo_text_id = self.save_copy(loan_guarantor.memo_text)
loan_guarantor.report_id = self.id
loan_guarantor.report = self
loan_guarantor.parent_transaction_id = loan.id
loan_guarantor.parent_transaction = loan
self.save_copy(loan_guarantor)

def pull_forward_debts(self):
previous_report = self.get_previous_report()
Expand All @@ -130,14 +136,17 @@ def pull_forward_debts(self):
)

for debt in debts_to_pull_forward:
debt.schedule_d.incurred_amount = Decimal(0)
debt.schedule_d_id = self.save_copy(debt.schedule_d)
debt.report_id = self.id
debt.report = self
# The debt_id should point to the original debt transaction
# even if the debt is pulled forward multiple times.
debt.debt_id = debt.debt_id if debt.debt_id else debt.id
self.save_copy(debt)
self.pull_forward_debt(debt)

def pull_forward_debt(self, debt):
debt.schedule_d.incurred_amount = Decimal(0)
debt.schedule_d_id = self.save_copy(debt.schedule_d)
debt.report_id = self.id
debt.report = self
# The debt_id should point to the original debt transaction
# even if the debt is pulled forward multiple times.
debt.debt_id = debt.debt_id if debt.debt_id else debt.id
self.save_copy(debt)

def get_previous_report(self):
return (
Expand Down
2 changes: 1 addition & 1 deletion django-backend/fecfiler/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,4 @@
FEC_API_COMMITTEE_LOOKUP_IDS_OVERRIDE = env.get_credential(
"FEC_API_COMMITTEE_LOOKUP_IDS_OVERRIDE"
)
FEC_API_CANDIDATE_LOOKUP_ENDPOINT = str(FEC_API) + "names/candidates/"
FEC_API_CANDIDATE_LOOKUP_ENDPOINT = str(FEC_API) + "candidates/"
Loading

0 comments on commit a5543f2

Please sign in to comment.