Skip to content

Commit

Permalink
Pridaný content do emailov ku komentárom
Browse files Browse the repository at this point in the history
  • Loading branch information
kovacspe committed Aug 25, 2024
1 parent 8edb147 commit 6680c4f
Show file tree
Hide file tree
Showing 4 changed files with 29 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 ú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

0 comments on commit 6680c4f

Please sign in to comment.