Skip to content

Commit

Permalink
Basic sponsor display is live. Issue #252 (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
aih committed Mar 24, 2021
1 parent 2e9e9ca commit 957768b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 34 deletions.
19 changes: 18 additions & 1 deletion server_py/flatgov/bills/templatetags/bill_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,21 @@ def billnumber_display(billnumber: str):
def billnumbers_display(billnumbers: list):
if isinstance(billnumbers, str):
billnumbers = billnumbers.split(', ')
return [billnumber_display(billnumber) for billnumber in list(billnumbers)]
return [billnumber_display(billnumber) for billnumber in list(billnumbers)]

@register.filter
@stringfilter
def cosponsor_name_display(name: str) -> str:
"""
Converts "Waters, Maxine" to "Maxine Waters"
TODO: Handle middle names or other variations
Args:
name (str): Last, First
Returns:
[str]: First Last
"""
firstlast = ' '.join(reversed(name.split(', ')))

return firstlast
24 changes: 24 additions & 0 deletions server_py/flatgov/bills/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def get_qs_related_bill(self):

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['cosponsors_dict'] = self.get_cosponsors_dict()
context['cosponsors'] = self.get_cosponsors()
context['statements'] = self.get_related_statements()
context['committees'] = self.get_related_committees()
Expand Down Expand Up @@ -199,6 +200,29 @@ def get_cosponsors(self):
serializer = CosponsorSerializer(
qs, many=True, context={'bill': self.object})
return serializer.data

def get_cosponsors_dict(self):
cosponsors = self.object.cosponsors_dict
print(cosponsors)
cosponsors = sorted(cosponsors, key = lambda i: i.get('name'))

sponsor = self.object.sponsor
sponsor['sponsor'] = True
sponsor_name = sponsor.get('name', '')
print(sponsor_name)
if sponsor_name:
sponsors = []
try:
sponsors = list(filter(lambda cosponsor: cosponsor.get('name', '') == sponsor_name, cosponsors))
except Exception as err:
pass
if sponsors:
print(sponsors[0])
cosponsors.remove(sponsors[0])
cosponsors.insert(0, sponsors[0])
else:
cosponsors.insert(0, sponsor)
return cosponsors


class BillToBillView(DetailView):
Expand Down
45 changes: 12 additions & 33 deletions server_py/flatgov/templates/bills/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ <h5><b>Prognosis:</b></h5>
</div>
<div class="col-md-6">
<div class="committee-jurisdiction light-gray-body p-4 h-100">
<h4 class="text-center"><b>Committees and Sponsors</b></h4>
<h4 class="text-center"><b>Committees and Cosponsors</b></h4>
<br>
<div class="d-flex justify-content-between">
<h5 style="float: left;"><b>Committees of Jurisdiction:</b></h5>
Expand All @@ -60,48 +60,27 @@ <h5 style="float: left;"><b>Committees of Jurisdiction:</b></h5>
</div>

<div class="mt-5">
<table class="table mt-3">
<table class="table mt-3" id="cosponsors-table">
<thead>
<tr>
<th scope="col">Sponsor</th>
<th scope="col">Co-sponsor</th>
<th scope="col">On Assigned Committee(s)</th>
<th scope="col">Party</th>
<th scope="col">Party</th>
<th scope="col">Position</th>
</tr>
</thead>
<tbody>
<tr>
<td>Raúl Grijalva</td>
<td>No</td>
<td>D</td>
<td>No</td>
</tr>
<tr>
<td>Rodney Davis</td>
<td>House Administration</td>
<td>R</td>
<td>Ranking Member</td>
</tr>
<tr>
<td>Jim Cooper</td>
<td>House Oversight</td>
<td>D</td>
<td>No</td>
</tr>
<tr>
<td>Virginia Foxx</td>
<td>House Oversight</td>
<td>R</td>
<td>No</td>
</tr>
<tbody> {% for cosponsor in cosponsors_dict|slice:":5" %}
<tr>
<td>Virginia Foxx</td>
<td>House Oversight</td>
<td>R</td>
<td>No</td>
<td>{{ cosponsor.title }}. {{ cosponsor.name|cosponsor_name_display }} {% if cosponsor.original_cosponsor %}<sup>*</sup>{% endif %}{% if cosponsor.sponsor %}<sup>&dagger;</sup>{% endif %}</td>
<td></td>
<td></td>
<td></td>
</tr>
{% endfor %}
</tbody>
</table>
<div><sup>+</sup>&nbsp; Sponsor</div>
<div><sup>*</sup>&nbsp; Original Cosponsor</div>
</div>
<div class="text-center mt-5">
<a
Expand Down

0 comments on commit 957768b

Please sign in to comment.