Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions apps/volunteer/recap.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
)


Expand Down
12 changes: 12 additions & 0 deletions models/volunteer/volunteer.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand Down
12 changes: 6 additions & 6 deletions templates/volunteer/recap.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@

{% block body %}
<h2>Volunteering Recap - {{ volunteer.nickname }}</h2>
{% if registered_for_build %}
{% if volunteer.registered_for_buildup %}
<div class="alert alert-success">
<p>
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 %}
</p>
</div>
{% elif qualifies_for_voucher %}
{% elif volunteer.qualifies_for_voucher %}
<div class="alert alert-success">
<p>You have qualified for an EMF 2028 pre-sale ticket voucher with {{ total_shifts }} qualifying shifts.</p>
<p>You have qualified for an EMF 2028 pre-sale ticket voucher with {{ volunteer.shift_count_for_vouchers }} qualifying shifts.</p>
</div>
{% else %}
<div class="alert alert-danger">
<p>Sorry, you have not qualified for an EMF 2028 pre-sale ticket voucher with {{ total_shifts }} qualifying shifts.</p>
<p>Sorry, you have not qualified for an EMF 2028 pre-sale ticket voucher with {{ volunteer.shift_count_for_vouchers }} qualifying shifts.</p>
<p>If you think this is in error please contact us at <a href="mailto:volunteer@emfcamp.org">volunteer@emfcamp.org</a> letting us know why and we'll do our best to resolve it.</p>
</div>
{% endif %}
Expand Down
Loading