Skip to content

Commit

Permalink
Merge branch 'main' into 741-graphql-api
Browse files Browse the repository at this point in the history
  • Loading branch information
Kurocon committed Feb 17, 2025
2 parents 994f3f0 + 10de156 commit 3a4becf
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 26 deletions.
10 changes: 5 additions & 5 deletions amelie/activities/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def activity_send_enrollmentmail(participation, from_waiting_list=False):
translation.activate(current_language)


def activity_send_cancellationmail(participants, activity, request, from_waiting_list=False):
def activity_send_cancellationmail(participations, activity, from_waiting_list=False):
"""
Send a cancellation of enrollment for an activity.
"""
Expand All @@ -88,11 +88,11 @@ def activity_send_cancellationmail(participants, activity, request, from_waiting
template_name = "activities/activity_cancelled_from_waiting_list.mail"

task = MailTask(template_name=template_name)
for participant in participants:
task.add_recipient(PersonRecipient(participant.person, context={
for participation in participations:
task.add_recipient(PersonRecipient(participation.person, context={
'activity': activity,
'participation_costs': participant.calculate_costs()[0],
'paymentmethod': participant.get_payment_method_display()
'participation_costs': participation.calculate_costs()[0],
'paymentmethod': participation.get_payment_method_display()
}))

task.send()
Expand Down
5 changes: 4 additions & 1 deletion amelie/activities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,10 @@ def activity_cancel(request, pk):
messages.error(_(f'We were unable to cancel {obj}, since it has already started.'))
return redirect(obj)
else:
activity_send_cancellationmail(obj.participation_set.all(), obj, request)
# We need to explicitly set the waiting list to false because they are also included in this set.
activity_send_cancellationmail(obj.participation_set.filter(waiting_list=False), obj)
if obj.waiting_participations.exists():
activity_send_cancellationmail(obj.waiting_participations.all(), obj, from_waiting_list=True)

# Send an email to the treasurer if people have paid in cash.
# This email contains the names and amount paid by each person.
Expand Down
9 changes: 5 additions & 4 deletions amelie/members/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def statistics(request):
).distinct()
active_members_other_count = len(active_members_other)

percent_active_members = '{0:.2f}'.format((active_members_count*100.0)/members_count)
percent_active_members = '{0:.2f}'.format((active_members_count*100.0)/members_count) if members_count != 0 else 0

freshmen_bit = Person.objects.members_at(dt).filter(
Q(membership__year=association_year(dt)),
Expand All @@ -151,7 +151,8 @@ def statistics(request):

freshmen_count = freshmen_bit_count + freshmen_tcs_count

percent_active_freshmen = '{0:.2f}'.format(((active_freshmen_bit_count + active_freshmen_tcs_count) * 100.0) / active_members_count)
percent_active_freshmen = '{0:.2f}'.format(((active_freshmen_bit_count + active_freshmen_tcs_count) * 100.0) / active_members_count) if active_members_count != 0 else 0


employee_count = Employee.objects.filter(
Q(person__membership__year=association_year(dt)),
Expand Down Expand Up @@ -185,8 +186,8 @@ def statistics(request):
).count()
per_commitee_total_ex_pools = per_commitee_total_ex_pools - count

average_committees_ex_pools_per_active_member = '{0:.2f}'.format((per_commitee_total_ex_pools*1.0)/active_members_count)
average_committees_per_active_member = '{0:.2f}'.format((per_committee_total*1.0)/active_members_count)
average_committees_ex_pools_per_active_member = '{0:.2f}'.format((per_commitee_total_ex_pools*1.0)/active_members_count) if active_members_count != 0 else 0
average_committees_per_active_member = '{0:.2f}'.format((per_committee_total*1.0)/active_members_count) if active_members_count != 0 else 0

per_active_member_total = {}
for person in active_members:
Expand Down
16 changes: 13 additions & 3 deletions amelie/narrowcasting/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _spotify_refresh_token(association):
raise e
return association

@cache_page(5)
@cache_page(15)
def room_spotify_now_playing(request):
identifier = request.GET.get('id', None)
if settings.SPOTIFY_CLIENT_SECRET == "":
Expand Down Expand Up @@ -142,13 +142,16 @@ def room_spotify_now_playing(request):
return room_spotify_now_playing(request)
except ValueError as e:
data = {'error': True, 'code': 500, 'msg': str(e)}
elif res.status_code == 429:
# Since we often exceed the rate limit, do not report as error
data = {'error': False, 'is_playing': False}
else:
data = {'error': True, 'code': res.status_code, 'msg': res.content.decode()}

return JsonResponse(data)


@cache_page(5)
@cache_page(15)
def room_spotify_pause(request):
identifier = request.GET.get('id', None)
if settings.SPOTIFY_CLIENT_SECRET == "":
Expand Down Expand Up @@ -184,13 +187,16 @@ def room_spotify_pause(request):
return room_spotify_pause(request)
except ValueError as e:
data = {'error': True, 'code': 500, 'msg': str(e)}
elif res.status_code == 429:
# Since we often exceed the rate limit, do not report as error
data = {'error': False, 'is_playing': False}
else:
data = {'error': True, 'code': res.status_code, 'msg': res.content.decode()}

return JsonResponse(data)


@cache_page(5)
@cache_page(15)
def room_spotify_play(request):
identifier = request.GET.get('id', None)
if settings.SPOTIFY_CLIENT_SECRET == "":
Expand Down Expand Up @@ -226,7 +232,11 @@ def room_spotify_play(request):
return room_spotify_play(request)
except ValueError as e:
data = {'error': True, 'code': 500, 'msg': str(e)}
elif res.status_code == 429:
# Since we often exceed the rate limit, do not report as error
data = {'error': False, 'is_playing': False}
else:
data = {'error': True, 'code': res.status_code, 'msg': res.content.decode()}


return JsonResponse(data)
12 changes: 0 additions & 12 deletions amelie/settings/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,11 @@ def custom_show_toolbar(request):
# Do not redirect to HTTPS, because the nginx proxy container only listens on HTTP
SECURE_SSL_REDIRECT = False

# Add allow cidr middleware as first middleware
MIDDLEWARE = ["allow_cidr.middleware.AllowCIDRMiddleware"] + MIDDLEWARE

# Allowed hosts -- localhost and 127.0.0.1 are always allowed, the rest comes from an environment variable.
ALLOWED_HOSTS = [
"localhost", "127.0.0.1"
] + env.list("DJANGO_ALLOWED_HOSTS", default=[])

# Allowed CIDR nets -- for kubernetes internal services
ALLOWED_CIDR_NETS = ['172.30.0.0/16']
ALLOWED_CIDR_NETS.extend(env.list("DJANGO_ALLOWED_CIDR_NETS", default=[]))

# Add Kubernetes POD IP, if running in Kubernetes
KUBE_POD_IP = env("THIS_POD_IP", default="")
if KUBE_POD_IP:
ALLOWED_CIDR_NETS.append(KUBE_POD_IP)

# Example: DJANGO_ADMINS="Jan Janssen <[email protected]>, Bob de Bouwer <[email protected]>"
ADMINS = getaddresses([env("DJANGO_ADMINS", default="WWW-committee <[email protected]>")])
MANAGERS = ADMINS
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ celery>=5.3.5,<5.4
flower==1.2.0
django-celery-results>=2.4,<2.5

django-allow-cidr>=0.5.0,<0.6
django-compressor>=4.1,<4.2
django-localflavor>=3.1,<3.2
django-extensions>=3.2.1,<3.3
Expand Down

0 comments on commit 3a4becf

Please sign in to comment.