Skip to content

Commit

Permalink
Fix newsletter signup URL
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed May 30, 2022
1 parent 2064e6e commit 8b5ae5d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
# path("questions/random", views.question_random, name="question_random"),
# path("authors", views.author_list, name="author_list"),
# path("notion-questions", views.notion_questions, name="notion-questions"),
path("newsletter", views.newsletter, name="newsletter"),
path("newsletter/", views.newsletter, name="newsletter"),
# Swagger / OpenAPI documentation
path("schema/", SpectacularAPIView.as_view(), name="schema"),
path("docs/", SpectacularSwaggerView.as_view(url_name="api:schema"), name="swagger-ui"),
Expand Down
17 changes: 11 additions & 6 deletions api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,18 @@ def newsletter(request):
if request.method == "POST":
try:
response = sendinblue.newsletter_registration(request.data["email"])
if response.status_code != 201:
if response.status_code == 201:
success_message = (
"Votre inscription a été reçu, merci ! "
"Vous allez reçevoir un email pour confirmer votre inscription."
)
return Response(success_message, status=status.HTTP_201_CREATED)
elif response.status_code == 204:
success_message = "Vous êtes déjà inscrit.e :)"
return Response(success_message, status=status.HTTP_201_CREATED)
else:
raise Exception(json.loads(response._content))
success_message = (
"Votre inscription a été reçu, merci ! "
"Vous allez reçevoir un email pour confirmer votre inscription."
)
return Response(success_message, status=status.HTTP_201_CREATED)
except Exception as e:
print(e)
error_message = f"Erreur lors de votre inscription à la newsletter. {e}"
return Response(error_message, status=status.HTTP_500_INTERNAL_SERVER_ERROR)

0 comments on commit 8b5ae5d

Please sign in to comment.