Skip to content
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

Comment emails #403

Merged
merged 3 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion competition/templates/competition/emails/comment_added.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Bol pridaný nový komentár.
Bol pridaný nový komentár k úlohe {{problem}}:
{{comment}}
5 changes: 4 additions & 1 deletion competition/templates/competition/emails/comment_hidden.txt
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. riadok má byť "k úlohe" nie "k úloje"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opravil som

Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
Tvoj komentár bol skrytý a dostal si k nemu súkromnú odpoveď.
Tvoj komentár
{{comment}}
k úloje {{problem}} bol skrytý a dostal si k nemu súkromnú odpoveď:
{{response}}
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Tvoj komentár bol zverejnený a dostal si k nemu odpoveď.
Tvoj komentár
{{comment}}
k úlohe {{problem}} bol zverejnený a dostal/a si k nemu odpoveď.
26 changes: 20 additions & 6 deletions competition/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,17 @@ def get_serializer_context(self):
@action(methods=['post'], detail=True)
def publish(self, request, pk=None):
"""Publikovanie, teda zverejnenie komentára"""
comment = self.get_object()
comment: Comment = self.get_object()
comment.publish()

send_mail(
'Zverejnený komentár',
render_to_string('competition/emails/comment_published.txt'),
render_to_string(
'competition/emails/comment_published.txt',
context={
'comment': comment.text,
'problem': comment.problem
}),
None,
[comment.posted_by.email],
)
Expand All @@ -166,12 +171,17 @@ def publish(self, request, pk=None):
@action(methods=['post'], detail=True)
def hide(self, request, pk=None):
"""Skrytie komentára"""
comment = self.get_object()
comment: Comment = self.get_object()
comment.hide(message=request.data.get('hidden_response'))

send_mail(
'Skrytý komentár',
render_to_string('competition/emails/comment_hidden.txt'),
render_to_string('competition/emails/comment_hidden.txt',
context={
'comment': comment.text,
'problem': comment.problem,
'response': comment.hidden_response
}),
None,
[comment.posted_by.email],
)
Expand Down Expand Up @@ -224,14 +234,18 @@ def comments(self, request, pk=None):
permission_classes=[IsAuthenticated])
def add_comment(self, request, pk=None):
"""Pridá komentár (otázku) k úlohe"""
problem = self.get_object()
problem: Problem = self.get_object()
also_publish = problem.can_user_modify(request.user)

problem.add_comment(request.data['text'], request.user, also_publish)

send_mail(
'Nový komentár',
render_to_string('competition/emails/comment_added.txt'),
render_to_string('competition/emails/comment_added.txt',
context={
'problem': problem,
'comment': request.data['text']
}),
None,
[EMAIL_ALERT],
)
Expand Down
5 changes: 5 additions & 0 deletions webstrom/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@

ALLOWED_HOSTS = []

CSRF_TRUSTED_ORIGINS = [
'http://localhost:3000',
'https://localhost:3000'
]

SITE_ID = 1

# Application definition
Expand Down