Skip to content
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

Display number of available reward points on staff page #1941

Merged
merged 4 commits into from
May 22, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@

{% block content %}
{{ block.super }}

<p>
<a href="{% url 'rewards:reward_point_redemption_event_create' %}" class="btn btn-dark btn-sm">{% trans 'Create new event' %}</a>
</p>
<div class="row mb-2">
<div class="col">
<a href="{% url 'rewards:reward_point_redemption_event_create' %}" class="btn btn-dark btn-sm">{% trans 'Create new event' %}</a>
</div>
<div class="col text-end">
{% trans 'Available reward points' %}: {{ total_points_available }}
</div>
</div>

<div class="card card-outline-primary mb-3">
{% trans 'Upcoming events' as title %}
Expand Down
10 changes: 9 additions & 1 deletion evap/rewards/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.contrib import messages
from django.core.exceptions import BadRequest, SuspiciousOperation
from django.db.models import Sum
from django.http import HttpResponse
from django.shortcuts import get_object_or_404, redirect, render
from django.utils.translation import get_language
Expand Down Expand Up @@ -91,7 +92,14 @@ def index(request):
def reward_point_redemption_events(request):
upcoming_events = RewardPointRedemptionEvent.objects.filter(redeem_end_date__gte=datetime.now()).order_by("date")
past_events = RewardPointRedemptionEvent.objects.filter(redeem_end_date__lt=datetime.now()).order_by("-date")
template_data = {"upcoming_events": upcoming_events, "past_events": past_events}
total_points_granted = RewardPointGranting.objects.aggregate(Sum("value"))["value__sum"] or 0
total_points_redeemed = RewardPointRedemption.objects.aggregate(Sum("value"))["value__sum"] or 0
total_points_available = total_points_granted - total_points_redeemed
template_data = {
"upcoming_events": upcoming_events,
"past_events": past_events,
"total_points_available": total_points_available,
}
return render(request, "rewards_reward_point_redemption_events.html", template_data)


Expand Down