diff --git a/chicago/models.py b/chicago/models.py index f13adae..37b7a12 100644 --- a/chicago/models.py +++ b/chicago/models.py @@ -4,6 +4,7 @@ import pytz from councilmatic_core.models import Bill, Event, Organization, Person +from chicago.utils import get_alder_extras from dateutil.relativedelta import relativedelta from django.conf import settings from django.db import models @@ -225,24 +226,28 @@ def legislation_count(self): sponsorships__person=self, sponsorships__primary=True ).count() - @property - def election_status(self): - for p in settings.ALDER_EXTRAS: - if ( - self.slug.startswith(p) - and "election-status" in settings.ALDER_EXTRAS[p] - ): - return settings.ALDER_EXTRAS[p]["election-status"] + def extra_props(self, key): + extra = get_alder_extras(self.slug) + if extra and key in extra: + return extra[key] return "" @property def caucus(self): - for p in settings.ALDER_EXTRAS: - if self.slug.startswith(p) and "caucus" in settings.ALDER_EXTRAS[p]: - return settings.ALDER_EXTRAS[p]["caucus"] + return self.extra_props("caucus") - return "" + @property + def candidate_id(self): + return self.extra_props("candidate_id") + + @property + def manual_headshot(self): + image_path = self.extra_props("image") + if image_path: + return f"/static/images/manual-headshots/{image_path}" # noqa + + return "/static/images/headshot_placeholder.png" @property def term_active(self): diff --git a/chicago/settings.py b/chicago/settings.py index 4b7d246..1596711 100644 --- a/chicago/settings.py +++ b/chicago/settings.py @@ -30,7 +30,7 @@ sentry_sdk.init( dsn=os.environ["SENTRY_DSN"], integrations=[DjangoIntegration()], - release=f"{os.environ['HEROKU_RELEASE_VERSION']}-{os.environ['HEROKU_APP_NAME']}", + release=f"{os.environ['HEROKU_RELEASE_VERSION']}-{os.environ['HEROKU_APP_NAME']}", # noqa enable_tracing=True, traces_sample_rate=0.05, ) @@ -326,210 +326,6 @@ "valencia-anna-m-257a68ccbc17": "City Clerk", } -ALDER_EXTRAS = { - "abarca-anabel": {"image": "abarca-anabel.jpg"}, - "arena-john": {"image": "arena-john.jpg"}, - "austin-carrie-m": { - "image": "austin-carrie-m.jpg", - "election-status": "Indicted, Retiring", - "caucus": "Black Caucus", - }, - "beale-anthony": {"image": "beale-anthony.jpg", "caucus": "Black Caucus"}, - "brookins-jr-howard": { - "image": "brookins-jr-howard.jpg", - "caucus": "Black Caucus", - "election-status": "Retiring", - }, - "burke-edward-m": { - "image": "burke-edward-m.jpg", - "election-status": "Indicted, Retiring", - }, - "burnett-jr-walter": {"image": "burnett-jr-walter.jpg", "caucus": "Black Caucus"}, - "burns-william-d": {"image": "burns-william-d.jpg"}, - "cappleman-james": { - "image": "cappleman-james.jpg", - "election-status": "Retiring", - "caucus": "LGBT Caucus", - }, - "cardenas-george-a": {"image": "cardenas-george-a.jpg", "caucus": "Latino Caucus"}, - "cardona-jr-felix": { - "image": "cardona-jr-felix.jpg", - "caucus": "Latino Caucus", - }, - "cochran-willie": {"image": "cochran-willie.jpg"}, - "coleman-stephanie-d": { - "image": "coleman-stephanie-d.jpg", - "caucus": "Black Caucus", - }, - "curtis-derrick-g": {"image": "curtis-derrick-g.jpg", "caucus": "Black Caucus"}, - "dowell-pat": {"image": "dowell-pat.jpg", "caucus": "Black Caucus"}, - "emanuel-rahm": {"image": "emanuel-rahm.jpg"}, - "ervin-jason-c": {"image": "ervin-jason-c.jpg", "caucus": "Black Caucus"}, - "foulkes-toni": {"image": "foulkes-toni.jpg"}, - "gardiner-james-m": {"image": "gardiner-james-m.jpg"}, - "hadden-maria-e": { - "image": "hadden-maria-e.jpg", - "caucus": "Black Caucus, Progressive Caucus, LGBT Caucus", - }, - "hairston-leslie-a": { - "image": "hairston-leslie-a.jpg", - "election-status": "Retiring", - "caucus": "Black Caucus, Progressive Caucus", - }, - "harris-michelle-a": {"image": "harris-michelle-a.jpg", "caucus": "Black Caucus"}, - "hopkins-brian": {"image": "hopkins-brian.jpg"}, - "king-sophia": { - "image": "king-sophia.jpg", - "election-status": "Running for Mayor, not seeking re-election", - "caucus": "Black Caucus, Progressive Caucus", - }, - "knudsen-timothy-r": {"image": "knudsen-timothy-r.jpg", "caucus": "LGBT Caucus"}, - "la-spata-daniel": { - "image": "la-spata-daniel.jpg", - "caucus": "Democratic Socialist, Latino Caucus, Progressive Caucus", - }, - "laurino-margaret": {"image": "laurino-margaret.jpg"}, - "lee-nicole-t": {"image": "lee-nicole-t.jpg"}, - "lopez-raymond-a": {"image": "lopez-raymond-a.jpg", "caucus": "LGBT Caucus"}, - "lightfoot-lori-e": {"image": "lightfoot-lori-e.jpg"}, - "maldonado-roberto": { - "image": "maldonado-roberto.jpg", - "election-status": "Retiring", - "caucus": "Latino Caucus", - }, - "martin-matthew-j": { - "image": "martin-matthew-j.jpg", - "caucus": "Black Caucus, Progressive Caucus", - }, - "mell-deborah": {"image": "mell-deborah.jpg"}, - "mendoza-susana-a": {"image": "mendoza-susana-a.jpg"}, - "mitchell-gregory-i": {"image": "mitchell-gregory-i.jpg", "caucus": "Black Caucus"}, - "mitts-emma": {"image": "mitts-emma.jpg", "caucus": "Black Caucus"}, - "moore-david-h": { - "image": "moore-david-h.jpg", - "caucus": "Black Caucus", - }, - "moore-joseph": {"image": "moore-joseph.jpg"}, - "moreno-proco-joe": {"image": "moreno-proco-joe.jpg"}, - "munoz-ricardo": {"image": "munoz-ricardo.jpg"}, - "napolitano-anthony-v": {"image": "napolitano-anthony-v.jpg"}, - "nugent-samantha": {"image": "nugent-samantha.jpg"}, - "oconnor-patrick": {"image": "oconnor-patrick.jpg"}, - "oshea-matthew-j": {"image": "oshea-matthew-j.jpg"}, - "osterman-harry": {"image": "osterman-harry.jpg", "election-status": "Retiring"}, - "pawar-ameya": {"image": "pawar-ameya.jpg"}, - "quinn-marty": {"image": "quinn-marty.jpg"}, - "ramirez-rosa-carlos": { - "image": "ramirez-rosa-carlos.jpg", - "caucus": "Democratic Socialist, Latino Caucus, Progressive Caucus, LGBT Caucus", # noqa - }, - "reboyras-ariel": { - "image": "reboyras-ariel.jpg", - "caucus": "Latino Caucus", - "election-status": "Retiring", - }, - "reilly-brendan": {"image": "reilly-brendan.jpg"}, - "rodriguez-michael-d": { - "image": "rodriguez-michael-d.jpg", - "caucus": "Latino Caucus, Progressive Caucus", - }, - "rodriguez-sanchez-rossana": { - "image": "rodriguez-sanchez-rossana.jpg", - "caucus": "Democratic Socialist, Latino Caucus, Progressive Caucus", - }, - "sadlowski-garza-susan": { - "image": "sadlowski-garza-susan.jpg", - "election-status": "Retiring", - "caucus": "Latino Caucus, Progressive Caucus", - }, - "santiago-milagros-s": {"image": "santiago-milagros-s.jpg"}, - "sawyer-roderick-t": { - "image": "sawyer-roderick-t.jpg", - "election-status": "Running for Mayor, not seeking re-election", - "caucus": "Black Caucus, Progressive Caucus", - }, - "scott-jr-michael": {"image": "scott-jr-michael.jpg", "caucus": "Black Caucus"}, - "scott-monique-l": {"image": "scott-monique-l.jpg", "caucus": "Black Caucus"}, - "sigcho-lopez-byron": { - "image": "sigcho-lopez-byron.jpg", - "caucus": "Democratic Socialist, Latino Caucus, Progressive Caucus", - }, - "silverstein-debra-l": {"image": "silverstein-debra-l.jpg"}, - "smith-michele": {"image": "smith-michele.jpg", "election-status": "Retiring"}, - "solis-daniel": {"image": "solis-daniel.jpg"}, - "sposato-nicholas": {"image": "sposato-nicholas.png"}, - "tabares-silvana": {"image": "tabares-silvana.jpg", "caucus": "Latino Caucus"}, - "taliaferro-chris": { - "image": "taliaferro-chris.jpg", - "caucus": "Black Caucus", - }, - "taylor-jeanette-b": { - "image": "taylor-jeanette-b.jpg", - "caucus": "Black Caucus, Democratic Socialist, Progressive Caucus", - }, - "thompson-patrick-d": {"image": "thompson-patrick-d.jpg"}, - "tunney-thomas": { - "image": "tunney-thomas.jpg", - "election-status": "Retiring", - "caucus": "LGBT Caucus", - }, - "valencia-anna-m": {"image": "valencia-anna-m.jpg"}, - "vasquez-jr-andre": { - "image": "vasquez-jr-andre.jpg", - "caucus": "Latino Caucus, Progressive Caucus", - }, - "villegas-gilbert": {"image": "villegas-gilbert.jpg", "caucus": "Latino Caucus"}, - "waguespack-scott": { - "image": "waguespack-scott.jpg", - "caucus": "", - }, - "zalewski-michael-r": {"image": "zalewski-michael-r.jpg"}, - "yancy-desmon-c": { - "image": "yancy-desmon-c.jpg", - "caucus": "Black Caucus, Progressive Caucus", - }, - "robinson-lamont": { - "image": "robinson-lamont.jpg", - "caucus": "Black Caucus", - }, - "ramirez-julia-m": { - "image": "ramirez-julia-m.jpg", - "caucus": "Latino Caucus, Progressive Caucus", - }, - "mosley-ronnie-l": { - "image": "mosley-ronnie-l.jpg", - "caucus": "Black Caucus", - }, - "manaa-hoppenworth-leni": {"image": "manaa-hoppenworth-leni.jpg"}, - "lawson-bennett-r": {"image": "lawson-bennett-r.jpg"}, - "hall-william-e": { - "image": "hall-william-e.jpg", - "caucus": "Black Caucus", - }, - "gutierrez-jeylu-b": { - "image": "gutierrez-jeylu-b.jpg", - "caucus": "Latino Caucus, Progressive Caucus", - }, - "fuentes-jessica": { - "image": "fuentes-jessica.jpg", - "caucus": "Latino Caucus, Progressive Caucus", - }, - "cruz-ruth": { - "image": "cruz-ruth.jpg", - "caucus": "Latino Caucus, Progressive Caucus", - }, - "conway-william": {"image": "conway-william.jpg"}, - "clay-angela": { - "image": "clay-angela.jpg", - "caucus": "Progressive Caucus", - }, - "chico-peter": { - "image": "chico-peter.jpg", - "caucus": "Latino Caucus", - }, - "johnson-brandon": {"image": "johnson-brandon.jpg"}, -} - TOPIC_HIERARCHY = [ { "name": "Citywide matters", diff --git a/chicago/templates/compare_council_members.html b/chicago/templates/compare_council_members.html index 59c3dab..6599a6f 100644 --- a/chicago/templates/compare_council_members.html +++ b/chicago/templates/compare_council_members.html @@ -32,7 +32,7 @@

Compare Alders

- {{person.name}} + {{person.name}}
diff --git a/chicago/templates/event.html b/chicago/templates/event.html index b959fa3..9aa04d3 100644 --- a/chicago/templates/event.html +++ b/chicago/templates/event.html @@ -103,7 +103,7 @@

Alder Attendance: {{attendance_present}} Present, {{attendance_absent}} Abse
- {{p.attendee.name}} + {{p.attendee.name}}
{{p.attendee.name}} diff --git a/chicago/templates/legislation.html b/chicago/templates/legislation.html index 8417f68..0144276 100644 --- a/chicago/templates/legislation.html +++ b/chicago/templates/legislation.html @@ -71,7 +71,7 @@

Sponsors

- {{s.person.name}} + {{s.person.name}}
@@ -88,7 +88,7 @@

Sponsors

- {{s.person.name}} + {{s.person.name}}
diff --git a/chicago/templates/partials/committee_person_table.html b/chicago/templates/partials/committee_person_table.html index 8b51705..24e490c 100644 --- a/chicago/templates/partials/committee_person_table.html +++ b/chicago/templates/partials/committee_person_table.html @@ -16,7 +16,7 @@
- {{membership.person.name}} + {{membership.person.name}}
@@ -34,7 +34,7 @@
- {{membership.person.name}} + {{membership.person.name}}
@@ -52,7 +52,7 @@
- {{membership.person.name}} + {{membership.person.name}}
diff --git a/chicago/templates/partials/council_member_table.html b/chicago/templates/partials/council_member_table.html index f047f08..60b184e 100644 --- a/chicago/templates/partials/council_member_table.html +++ b/chicago/templates/partials/council_member_table.html @@ -15,7 +15,7 @@ {% if post.current_member %}
- {{post.current_member.person.name}} + {{post.current_member.person.name}}
{% endif %} diff --git a/chicago/templates/person.html b/chicago/templates/person.html index 913172f..adf814c 100644 --- a/chicago/templates/person.html +++ b/chicago/templates/person.html @@ -21,7 +21,7 @@

- {{person.name}} + {{person.name}} {% if person.term_active %} {% if tenure_start %} @@ -113,15 +113,17 @@

Contact info

{% endif %} -
  • - - - - Campaign - Donations - - -
  • + {% if person.candidate_id %} +
  • + + + + Campaign + Donations + + +
  • + {% endif %} {% if request.GET.view == 'bills' or request.GET.view == None %} @@ -206,7 +208,7 @@

    {{person.name}} has {{ attendance_percent }} attendance

    {% endif %} - {% if request.GET.view == 'donations' %} + {% if request.GET.view == 'donations' and map_geojson %}

    Campaign Donations

    @@ -258,7 +260,7 @@

    Tools

    "@context": "http://schema.org", "@type": "Person", "email": "{{person.email}}", - "image": "{{ person|get_person_headshot }}", + "image": "{{ person.manual_headshot }}", {% if person.current_council_seat %} "jobTitle": "{{ person.current_council_seat }} Representative", {% endif %} @@ -328,53 +330,55 @@

    Tools

    {% endif %} - - + + {% endif %} {% endblock %} diff --git a/chicago/templatetags/extras.py b/chicago/templatetags/extras.py index 93a19c8..5cc01fe 100644 --- a/chicago/templatetags/extras.py +++ b/chicago/templatetags/extras.py @@ -151,16 +151,6 @@ def remove_question(text): return text.rstrip("?") -@register.filter -def get_person_headshot(person): - for p in settings.ALDER_EXTRAS: - if person: - if person.slug.startswith(p): - return f"/static/images/manual-headshots/{settings.ALDER_EXTRAS[p]['image']}" # noqa - - return "/static/images/headshot_placeholder.png" - - @register.filter def get_legistar_link(object): try: diff --git a/chicago/utils.py b/chicago/utils.py index f54e135..47baa8a 100644 --- a/chicago/utils.py +++ b/chicago/utils.py @@ -1,7 +1,10 @@ +import os import datetime import pytz +from csv import DictReader from django.conf import settings +from django.core.cache import cache from haystack.utils.highlighting import Highlighter @@ -40,3 +43,28 @@ def to_datetime(date, local=False): else: return dt + + +def get_alder_extras(key): + if cache.get("alder_extras"): + extras = cache.get("alder_extras") + else: + extras = {} + alder_extras_file = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "..", + "data", + "final", + "alder_extras.csv", + ) + alder_extras_reader = DictReader(open(alder_extras_file)) + for row in alder_extras_reader: + extras[row["_key"]] = row + + cache.set("alder_extras", extras) + + for p in extras: + if key.startswith(p): + return extras[p] + + return None diff --git a/data/final/alder_extras.csv b/data/final/alder_extras.csv new file mode 100644 index 0000000..fe729f3 --- /dev/null +++ b/data/final/alder_extras.csv @@ -0,0 +1,87 @@ +_key,image,caucus,election-status,candidate_id +abarca-anabel,abarca-anabel.jpg,,, +arena-john,arena-john.jpg,,, +austin-carrie-m,austin-carrie-m.jpg,Black Caucus,"Indicted, Retiring", +beale-anthony,beale-anthony.jpg,Black Caucus,,14117 +brookins-jr-howard,brookins-jr-howard.jpg,Black Caucus,Retiring, +burke-edward-m,burke-edward-m.jpg,,"Indicted, Retiring", +burnett-jr-walter,burnett-jr-walter.jpg,Black Caucus,,8848 +burns-william-d,burns-william-d.jpg,,, +cappleman-james,cappleman-james.jpg,LGBT Caucus,Retiring, +cardenas-george-a,cardenas-george-a.jpg,Latino Caucus,, +cardona-jr-felix,cardona-jr-felix.jpg,Latino Caucus,,42117 +chico-peter,chico-peter.jpg,Latino Caucus,,46536 +clay-angela,clay-angela.jpg,Progressive Caucus,,42479 +cochran-willie,cochran-willie.jpg,,, +coleman-stephanie-d,coleman-stephanie-d.jpg,Black Caucus,,29788 +conway-william,conway-william.jpg,,,46354 +cruz-ruth,cruz-ruth.jpg,"Latino Caucus, Progressive Caucus",,46442 +curtis-derrick-g,curtis-derrick-g.jpg,Black Caucus,,28608 +dowell-pat,dowell-pat.jpg,Black Caucus,,16892 +emanuel-rahm,emanuel-rahm.jpg,,, +ervin-jason-c,ervin-jason-c.jpg,Black Caucus,,25244 +foulkes-toni,foulkes-toni.jpg,,, +fuentes-jessica,fuentes-jessica.jpg,"Latino Caucus, Progressive Caucus",,46544 +gardiner-james-m,gardiner-james-m.jpg,,,42272 +gutierrez-jeylu-b,gutierrez-jeylu-b.jpg,"Latino Caucus, Progressive Caucus",,46461 +hadden-maria-e,hadden-maria-e.jpg,"Black Caucus, Progressive Caucus, LGBT Caucus",,40674 +hairston-leslie-a,hairston-leslie-a.jpg,"Black Caucus, Progressive Caucus",Retiring, +hall-william-e,hall-william-e.jpg,Black Caucus,,46708 +harris-michelle-a,harris-michelle-a.jpg,Black Caucus,,21169 +hopkins-brian,hopkins-brian.jpg,,,28160 +johnson-brandon,johnson-brandon.jpg,,, +king-sophia,king-sophia.jpg,"Black Caucus, Progressive Caucus","Running for Mayor, not seeking re-election", +knudsen-timothy-r,knudsen-timothy-r.jpg,LGBT Caucus,,46327 +la-spata-daniel,la-spata-daniel.jpg,"Democratic Socialist, Latino Caucus, Progressive Caucus",,42075 +laurino-margaret,laurino-margaret.jpg,,, +lawson-bennett-r,lawson-bennett-r.jpg,,,46428 +lee-nicole-t,lee-nicole-t.jpg,,,46132 +lightfoot-lori-e,lightfoot-lori-e.jpg,,, +lopez-raymond-a,lopez-raymond-a.jpg,LGBT Caucus,,43238 +maldonado-roberto,maldonado-roberto.jpg,Latino Caucus,Retiring, +manaa-hoppenworth-leni,manaa-hoppenworth-leni.jpg,,,46335 +martin-matthew-j,martin-matthew-j.jpg,"Black Caucus, Progressive Caucus",,40859 +mell-deborah,mell-deborah.jpg,,, +mendoza-susana-a,mendoza-susana-a.jpg,,, +mitchell-gregory-i,mitchell-gregory-i.jpg,Black Caucus,,24984 +mitts-emma,mitts-emma.jpg,Black Caucus,,15421 +moore-david-h,moore-david-h.jpg,Black Caucus,,25264 +moore-joseph,moore-joseph.jpg,,, +moreno-proco-joe,moreno-proco-joe.jpg,,, +mosley-ronnie-l,mosley-ronnie-l.jpg,Black Caucus,,46526 +munoz-ricardo,munoz-ricardo.jpg,,, +napolitano-anthony-v,napolitano-anthony-v.jpg,,,28461 +nugent-samantha,nugent-samantha.jpg,,,42035 +oconnor-patrick,oconnor-patrick.jpg,,, +oshea-matthew-j,oshea-matthew-j.jpg,,,25077 +osterman-harry,osterman-harry.jpg,,Retiring, +pawar-ameya,pawar-ameya.jpg,,, +quinn-marty,quinn-marty.jpg,,,25487 +ramirez-julia-m,ramirez-julia-m.jpg,"Latino Caucus, Progressive Caucus",,46528 +ramirez-rosa-carlos,ramirez-rosa-carlos.jpg,"Democratic Socialist, Latino Caucus, Progressive Caucus, LGBT Caucus",,28456 +reboyras-ariel,reboyras-ariel.jpg,Latino Caucus,Retiring, +reilly-brendan,reilly-brendan.jpg,,,20516 +robinson-lamont,robinson-lamont.jpg,Black Caucus,,46617 +rodriguez-michael-d,rodriguez-michael-d.jpg,"Latino Caucus, Progressive Caucus",,34334 +rodriguez-sanchez-rossana,rodriguez-sanchez-rossana.jpg,"Democratic Socialist, Latino Caucus, Progressive Caucus",,42072 +sadlowski-garza-susan,sadlowski-garza-susan.jpg,"Latino Caucus, Progressive Caucus",Retiring, +santiago-milagros-s,santiago-milagros-s.jpg,,, +sawyer-roderick-t,sawyer-roderick-t.jpg,"Black Caucus, Progressive Caucus","Running for Mayor, not seeking re-election", +scott-jr-michael,scott-jr-michael.jpg,Black Caucus,, +scott-monique-l,scott-monique-l.jpg,Black Caucus,,46300 +sigcho-lopez-byron,sigcho-lopez-byron.jpg,"Democratic Socialist, Latino Caucus, Progressive Caucus",,28403 +silverstein-debra-l,silverstein-debra-l.jpg,,,25135 +smith-michele,smith-michele.jpg,,Retiring, +solis-daniel,solis-daniel.jpg,,, +sposato-nicholas,sposato-nicholas.png,,,21027 +tabares-silvana,tabares-silvana.jpg,Latino Caucus,,42092 +taliaferro-chris,taliaferro-chris.jpg,Black Caucus,,28392 +taylor-jeanette-b,taylor-jeanette-b.jpg,"Black Caucus, Democratic Socialist, Progressive Caucus",,40850 +thompson-patrick-d,thompson-patrick-d.jpg,,, +tunney-thomas,tunney-thomas.jpg,LGBT Caucus,Retiring, +valencia-anna-m,valencia-anna-m.jpg,,, +vasquez-jr-andre,vasquez-jr-andre.jpg,"Latino Caucus, Progressive Caucus",,41995 +villegas-gilbert,villegas-gilbert.jpg,Latino Caucus,,28459 +waguespack-scott,waguespack-scott.jpg,,,21073 +yancy-desmon-c,yancy-desmon-c.jpg,"Black Caucus, Progressive Caucus",,46626 +zalewski-michael-r,zalewski-michael-r.jpg,,,