datamade / django-councilmatic

:heartpulse: Django app providing core functions for *.councilmatic.org
http://councilmatic.org
MIT License
26 stars 16 forks source link

Refresh bill *versions*, as well as bill documents #268

Closed hancush closed 3 years ago

hancush commented 4 years ago

Description

This PR reorganizes the refresh_pic management command and adds a method to retrieve bill versions, as well as bill documents, for cache refresh. This handles a bug where updating the bill itself did not trigger a cache refresh, since that resource is stored as a BillVersion, not a BillDocument. More: https://github.com/datamade/la-metro-councilmatic/issues/621

Testing instructions

>>> import datetime

>>> from django.conf import settings
>>> from opencivicdata.legislative.models import *
>>> from pytz import timezone

>>> from lametro.models import LAMetroBill

>>> app_timezone = pytz.timezone(settings.TIME_ZONE)
>>> june_17 = app_timezone.localize(datetime.datetime(2020, 6, 17))
>>> bills_on_upcoming_agendas = EventRelatedEntity.objects.filter(bill__isnull=False, agenda_item__event__start_date__gt=june_17).filter(bill__identifier='2020-0414')
>>> bills_on_upcoming_agendas
<QuerySet [<EventRelatedEntity: 2020-0414 related to Agenda item 21 for Executive Management Committee (2020-06-18T18:30:00+00:00)>, <EventRelatedEntity: 2020-0414 related to Agenda item 40 for Regular Board Meeting (2020-06-25T17:00:00+00:00)>]>

>>> upcoming = bills_on_upcoming_agendas.values_list('bill_id')
>>> BillVersionLink.objects.filter(version__bill__id__in=upcoming)
<QuerySet [<BillVersionLink: https://metro.legistar.com/ViewReport.ashx?M=R&N=TextL5&GID=557&ID=6856&GUID=LATEST&Title=Board+Report for  version of 2020-0414 in Los Angeles County Metropolitan Transportation Authority >]>
hancush commented 3 years ago

@jeancochrane Thank you for your review – this is ready for your eyeballs once more!