Skip to content

Commit

Permalink
Comment emails (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
kovacspe authored Aug 31, 2024
1 parent 4830517 commit b70b3c1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
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
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 úlohe {{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

0 comments on commit b70b3c1

Please sign in to comment.