-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix generating Powerpoint report header #431
Changes from 3 commits
5a6e731
6c42942
085884a
9b3af9b
e67671c
b859afc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,7 +65,7 @@ def get_stations_in_admin_area(tally_id, admin_level, admin_area): | |
|
||
|
||
def get_result_forms_for_station_in_admin_area( | ||
tally_id, admin_level, admin_area, station | ||
tally_id, admin_level, admin_area, station, station_obj | ||
): | ||
""" | ||
get distinct result forms for a given station | ||
|
@@ -84,12 +84,12 @@ def get_result_forms_for_station_in_admin_area( | |
tally__id=tally_id, | ||
**area_filter_map, | ||
center__stations__id=station.get('id'), | ||
station_number=station.get('number'), | ||
station_number=station_obj.station_number, | ||
).values_list('form_state', flat=True).distinct() | ||
|
||
|
||
def get_station_votes_in_admin_area( | ||
tally_id, admin_level, admin_area, station | ||
tally_id, admin_level, admin_area, station, station_obj | ||
): | ||
""" | ||
Gets the station votes grouped by races for the given station. | ||
|
@@ -108,7 +108,7 @@ def get_station_votes_in_admin_area( | |
result_form__tally__id=tally_id, | ||
**area_filter_map, | ||
result_form__center__stations__id=station.get('id'), | ||
result_form__station_number=station.get('number'), | ||
result_form__station_number=station_obj.station_number, | ||
result_form__ballot__electrol_race_id__in=station.get('races'), | ||
entry_version=EntryVersion.FINAL, | ||
active=True, | ||
|
@@ -148,6 +148,13 @@ def get_initial_queryset(self): | |
|
||
ret_value = [] | ||
|
||
tally_stations_qs = Station.objects.filter(tally_id=tally_id) | ||
stations_by_id =\ | ||
{ | ||
station.id:\ | ||
station for station in tally_stations_qs | ||
} | ||
|
||
# Calculate voters in counted stations and turnout percentage | ||
for area in admin_areas_qs: | ||
response = {} | ||
|
@@ -168,28 +175,30 @@ def get_initial_queryset(self): | |
race=F('center__resultform__ballot__electrol_race_id') | ||
).values('id').annotate( | ||
races=ArrayAgg('race', distinct=True), | ||
number=F('station_number'), | ||
num_registrants=F('registrants') | ||
) | ||
voters = 0 | ||
stations_processed = 0 | ||
registrants_in_processed_stations = 0 | ||
for station in station_ids_by_race: | ||
station_obj = stations_by_id.get(station.get('id')) | ||
# Calculate stations processed and total registrants | ||
form_states = get_result_forms_for_station_in_admin_area( | ||
tally_id, | ||
admin_level, area_code, station | ||
admin_level, | ||
area_code, | ||
station, | ||
station_obj | ||
) | ||
|
||
if form_states.count() == 1 and \ | ||
form_states[0] == FormState.ARCHIVED: | ||
stations_processed += 1 | ||
registrants_in_processed_stations += \ | ||
station.get('num_registrants') | ||
station_obj.registrants | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could raise There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, so I have made sure we reuse the tally stations queryset used when creating stations_by_id that's used when defining station_obj. This will ensure we never encounter such an error |
||
|
||
# Calculate voters voted in processed stations | ||
votes = get_station_votes_in_admin_area( | ||
tally_id, admin_level, area_code, station | ||
tally_id, admin_level, area_code, station, station_obj | ||
) | ||
|
||
if votes.count() != 0: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same Could raise
AttributeError
ifstation.get('id')
returns NoneThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The above response also applies here