Draft
Conversation
abrasseu
suggested changes
Dec 13, 2020
Contributor
abrasseu
left a comment
There was a problem hiding this comment.
All in all it's good but we need to change some stuff before merge :)
Comment on lines
+20
to
+22
| # Permit to send feedback emails from users | ||
| @api_view(['POST']) | ||
| def feedback(request, format=None): |
Contributor
There was a problem hiding this comment.
Suggested change
| # Permit to send feedback emails from users | |
| @api_view(['POST']) | |
| def feedback(request, format=None): | |
| @api_view(["POST"]) | |
| def feedback(request, format=None): | |
| """ | |
| Send feedback emails from users | |
| """ |
Use Python Docstrings
| @api_view(['POST']) | ||
| def feedback(request, format=None): | ||
| data = request.data | ||
| if len(data['message']) < 2: |
Contributor
There was a problem hiding this comment.
Suggested change
| if len(data['message']) < 2: | |
| if len(data.get("message", "")) < 2: |
If there is no message in the POST data, get won't throw an error.
| def feedback(request, format=None): | ||
| data = request.data | ||
| if len(data['message']) < 2: | ||
| return HttpResponse(status=500) |
Contributor
There was a problem hiding this comment.
It should raise a 400 Bad Request error, you can maybe use ValidationError with a message like "Veuillez ajouter un message". Using a Serializer with a Model could help
Comment on lines
+27
to
+29
| subject = "[WOOLLY][FeedBack] - " + data['reason'] + " - " + data['sender']['name'] | ||
| message = 'Utilisateur : ' + data['sender']['name'] + '\n' + 'ID : ' + data['sender']['id'] + '\n' + 'Email : ' + data['sender']['email'] + '\n' + 'Date : ' + datetime.now().strftime("%d/%m/%Y, %H:%M:%S") + '\n' + 'Raison : ' + data['reason'] + '\n \n' + 'Message :' + '\n' + data['message'] | ||
| message = message + '\n\nCe message a été généré automatiquement, merci de ne pas y répondre' |
Contributor
There was a problem hiding this comment.
Suggested change
| subject = "[WOOLLY][FeedBack] - " + data['reason'] + " - " + data['sender']['name'] | |
| message = 'Utilisateur : ' + data['sender']['name'] + '\n' + 'ID : ' + data['sender']['id'] + '\n' + 'Email : ' + data['sender']['email'] + '\n' + 'Date : ' + datetime.now().strftime("%d/%m/%Y, %H:%M:%S") + '\n' + 'Raison : ' + data['reason'] + '\n \n' + 'Message :' + '\n' + data['message'] | |
| message = message + '\n\nCe message a été généré automatiquement, merci de ne pas y répondre' | |
| subject = f"[WOOLLY][FeedBack] - {data['reason']} - {data['sender']['name']}" | |
| message = "\n".join([ | |
| f"Utilisateur: {data['sender']['name']}", | |
| f"Identifiant: {data['sender']['id']}", | |
| f"Email: {data['sender']['email']}", | |
| f"Date: {datetime.now().isoformat(sep=' ', timespec='seconds')}" | |
| f"Raison: {data['reason']}", | |
| "", | |
| {data['message']}, | |
| "", | |
| "Ce message a été généré automatiquement, merci de ne pas y répondre", | |
| ]) |
You should also check that all the data attributes are present, maybe create a Model and a Serializer ?
Comment on lines
+69
to
+81
| # email = env.dj_email_url("EMAIL_URL") | ||
| # EMAIL_HOST = email["EMAIL_HOST"] | ||
| # EMAIL_PORT = email["EMAIL_PORT"] | ||
| # EMAIL_HOST_USER = email["EMAIL_HOST_USER"] | ||
| # EMAIL_HOST_PASSWORD = email["EMAIL_HOST_PASSWORD"] | ||
| # EMAIL_USE_SSL = email["EMAIL_USE_SSL"] | ||
| # EMAIL_USE_TLS = email["EMAIL_USE_TLS"] | ||
| EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' | ||
| EMAIL_HOST = 'smtp.gmail.com' | ||
| EMAIL_USE_TLS = True | ||
| EMAIL_PORT = 587 | ||
| EMAIL_HOST_USER = env.str("EMAIL_HOST_USER") | ||
| EMAIL_HOST_PASSWORD = env.str("EMAIL_HOST_PASSWORD") |
Contributor
There was a problem hiding this comment.
You'll need to revert that and use something like this in your personal .env:
EMAIL_URL=stmp://user@domain:password@smtp.gmail.com:587?tls=True
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Send feedbacks mails from users