-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat: Get user feedback #54
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All in all it's good but we need to change some stuff before merge :)
# Permit to send feedback emails from users | ||
@api_view(['POST']) | ||
def feedback(request, format=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# 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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
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' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 ?
# 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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll need to revert that and use something like this in your personal .env:
EMAIL_URL=stmp://user@domain:[email protected]:587?tls=True
Send feedbacks mails from users