diff --git a/apps/volunteer/recap.py b/apps/volunteer/recap.py index bfb297f71..c87523fc1 100644 --- a/apps/volunteer/recap.py +++ b/apps/volunteer/recap.py @@ -1,5 +1,3 @@ -from functools import reduce - from flask import flash, redirect, render_template, url_for from flask.typing import ResponseReturnValue from flask_login import current_user @@ -10,17 +8,10 @@ def _recap_for(volunteer: Volunteer) -> ResponseReturnValue: - total_shifts = reduce( - lambda x, y: x + y, [entry.voucher_contribution for entry in current_user.shift_entries] - ) - return render_template( "volunteer/recap.html", volunteer=volunteer, - shift_entries=current_user.shift_entries, - registered_for_build=volunteer.registered_for_buildup, - total_shifts=total_shifts, - qualifies_for_voucher=(total_shifts >= 2), + shift_entries=volunteer.user.shift_entries, ) diff --git a/models/volunteer/volunteer.py b/models/volunteer/volunteer.py index 11b7b3633..decb1a8c0 100644 --- a/models/volunteer/volunteer.py +++ b/models/volunteer/volunteer.py @@ -1,5 +1,7 @@ from collections import defaultdict from datetime import datetime, timedelta +from decimal import Decimal +from functools import reduce from typing import TYPE_CHECKING, TypeVar from flask_login import UserMixin @@ -206,6 +208,16 @@ def permitted_shift_times(self) -> tuple[datetime, datetime]: # Everyone should be able to see Monday shifts. return (config.event_start, config.event_end + timedelta(days=1)) + @property + def shift_count_for_vouchers(self) -> Decimal: + return reduce( + lambda x, y: x + y, [entry.voucher_contribution for entry in self.user.shift_entries], Decimal(0) + ) + + @property + def qualifies_for_voucher(self) -> bool: + return self.registered_for_buildup or self.shift_count_for_vouchers >= 2 + """ class Messages(db.Model): diff --git a/templates/volunteer/recap.html b/templates/volunteer/recap.html index 0ace0f885..510353b4b 100644 --- a/templates/volunteer/recap.html +++ b/templates/volunteer/recap.html @@ -5,22 +5,22 @@ {% block body %}
You have qualified for an EMF 2028 pre-sale voucher by helping with build or teardown, many thanks! - {% if total_shifts > 0 %} - You also completed {{ total_shifts }} qualifying shifts. + {% if volunteer.shift_count_for_vouchers > 0 %} + You also completed {{ volunteer.shift_count_for_vouchers }} qualifying shifts. {% endif %}
You have qualified for an EMF 2028 pre-sale ticket voucher with {{ total_shifts }} qualifying shifts.
+You have qualified for an EMF 2028 pre-sale ticket voucher with {{ volunteer.shift_count_for_vouchers }} qualifying shifts.
Sorry, you have not qualified for an EMF 2028 pre-sale ticket voucher with {{ total_shifts }} qualifying shifts.
+Sorry, you have not qualified for an EMF 2028 pre-sale ticket voucher with {{ volunteer.shift_count_for_vouchers }} qualifying shifts.
If you think this is in error please contact us at volunteer@emfcamp.org letting us know why and we'll do our best to resolve it.