diff --git a/amivapi/events/emails.py b/amivapi/events/emails.py index 258f5332..be510ccc 100644 --- a/amivapi/events/emails.py +++ b/amivapi/events/emails.py @@ -28,7 +28,11 @@ def find_reply_to_email(event): return current_app.config.get('DEFAULT_EVENT_REPLY_TO') -def notify_signup_accepted(event, signup, waiting_list=False): +def notify_signup_accepted( + event, + signup, + waiting_list=False, + spots_available=False): """Send an email to a user that his signup was accepted""" id_field = current_app.config['ID_FIELD'] @@ -84,16 +88,28 @@ def notify_signup_accepted(event, signup, waiting_list=False): calendar_invite = None if waiting_list: - mail_from_template( - to=[email], - subject='Your signup for %s was put on the waiting list' - % (title_en or title_de), - template_name='events_waitingList', - template_args=dict( - name=name, - title_en=(title_en or title_de), - title_de=(title_de or title_en)), - reply_to=reply_to_email) + if spots_available: + mail_from_template( + to=[email], + subject='Your signup for %s was put on the waiting list' + % (title_en or title_de), + template_name='events_waitingListManual', + template_args=dict( + name=name, + title_en=(title_en or title_de), + title_de=(title_de or title_en)), + reply_to=reply_to_email) + else: + mail_from_template( + to=[email], + subject='Your signup for %s was put on the waiting list' + % (title_en or title_de), + template_name='events_waitingList', + template_args=dict( + name=name, + title_en=(title_en or title_de), + title_de=(title_de or title_en)), + reply_to=reply_to_email) else: mail_from_template( to=[email], diff --git a/amivapi/events/queue.py b/amivapi/events/queue.py index db1ab6b1..7f099dbf 100644 --- a/amivapi/events/queue.py +++ b/amivapi/events/queue.py @@ -96,10 +96,19 @@ def update_waiting_list_after_insert(signups): if signup['_id'] in accepted: signup['accepted'] = True elif signup.get('user') is not None: - lookup = {current_app.config['ID_FIELD']: signup.get('event')} + event_id = signup.get('event') + lookup = {current_app.config['ID_FIELD']: event_id} event = current_app.data.find_one('events', None, **lookup) + lookup = {'event': event_id, 'accepted': True} + signup_count = ( + current_app.data.driver.db['eventsignups'] + .count_documents(lookup)) if event is not None: - notify_signup_accepted(event, signup, True) + if event['selection_strategy'] == "manual" \ + and signup_count < event['spots']: + notify_signup_accepted(event, signup, True, True) + else: + notify_signup_accepted(event, signup, True, False) def update_waiting_list_after_delete(signup): diff --git a/amivapi/templates/events_waitingListManual.html b/amivapi/templates/events_waitingListManual.html new file mode 100644 index 00000000..070a172c --- /dev/null +++ b/amivapi/templates/events_waitingListManual.html @@ -0,0 +1,19 @@ +{% extends "base.html" %} + +{% block text_german %} +
Hey {{ name }}!
+ +Deine Anmeldung für {{ title_de }} wurde auf die Warteliste gesetzt, da bei diesem Event die Teilnehmer manuell akzeptiert werden.
+Du erhältst eine E-Mail sobald deine Anmeldung definitiv aufgenommen wird.
+ +Freundliche Grüsse,AMIV
+{% endblock %} + +{% block text_english %} +Hello {{ name }}!
+ +Your signup for {{ title_en }} was put on the waiting list, as the signups for this event are manually reviewed.
+You will be notified as soon as your signup has been definitively accepted.
+ +Best Regards,AMIV
+{% endblock %} diff --git a/amivapi/templates/events_waitingListManual.txt b/amivapi/templates/events_waitingListManual.txt new file mode 100644 index 00000000..17582332 --- /dev/null +++ b/amivapi/templates/events_waitingListManual.txt @@ -0,0 +1,21 @@ +{% extends "base.txt" %} + +{% block text_german %} +Hey {{ name }}! + +Deine Anmeldung für {{ title_de }} wurde auf die Warteliste gesetzt, da bei diesem Event die Teilnehmer manuell akzeptiert werden. +Du erhältst eine E-Mail sobald deine Anmeldung definitiv aufgenommen wird. + +Freundliche Grüsse, +AMIV +{% endblock %} + +{% block text_english %} +Hello {{ name }}! + +Your signup for {{ title_en }} was put on the waiting list, as the signups for this event are manually reviewed. +You will be notified as soon as your signup has been definitively accepted. + +Best Regards, +AMIV +{% endblock %} diff --git a/amivapi/tests/events/test_emails.py b/amivapi/tests/events/test_emails.py index a476e745..c1f07e23 100644 --- a/amivapi/tests/events/test_emails.py +++ b/amivapi/tests/events/test_emails.py @@ -440,7 +440,9 @@ def test_notify_waitlist_on_signup_update(self): 'event': str(manual_event['_id']) }, status_code=201).json - self.assertTrue('was rejected' in self.app.test_mails[0]['text']) + # this results in a different email + self.assertTrue('are manually reviewed' + in self.app.test_mails[0]['text']) # User manually accepted from waiting list self.api.patch('/eventsignups/%s' % manual_signup['_id'],