Skip to content

Commit df71ecd

Browse files
author
Filip Kula
committed
2 parents e7367fd + 8585531 commit df71ecd

File tree

7 files changed

+299
-4
lines changed

7 files changed

+299
-4
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<!DOCTYPE html>
2+
<html lang="pl">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Powiadomienie o nowej wiadomości</title>
7+
<style>
8+
body {
9+
font-family: Arial, sans-serif;
10+
line-height: 1.6;
11+
color: #333;
12+
max-width: 600px;
13+
margin: 0 auto;
14+
padding: 20px;
15+
}
16+
.header {
17+
background-color: #007bff;
18+
color: white;
19+
padding: 20px;
20+
text-align: center;
21+
border-radius: 5px 5px 0 0;
22+
}
23+
.content {
24+
background-color: #f8f9fa;
25+
padding: 20px;
26+
border: 1px solid #dee2e6;
27+
}
28+
.message-box {
29+
background-color: white;
30+
padding: 15px;
31+
border-left: 4px solid #007bff;
32+
margin: 15px 0;
33+
border-radius: 3px;
34+
}
35+
.footer {
36+
background-color: #6c757d;
37+
color: white;
38+
padding: 15px;
39+
text-align: center;
40+
border-radius: 0 0 5px 5px;
41+
font-size: 12px;
42+
}
43+
.paper-title {
44+
font-weight: bold;
45+
color: #007bff;
46+
}
47+
.sender-info {
48+
color: #6c757d;
49+
font-size: 14px;
50+
margin-bottom: 10px;
51+
}
52+
</style>
53+
</head>
54+
<body>
55+
<div class="header">
56+
<h2>Otrzymano nową wiadomość</h2>
57+
</div>
58+
59+
<div class="content">
60+
<p>Szanowny/a {{ author_name }},</p>
61+
62+
<p>Otrzymano nową wiadomość dotyczącą Twojego artykułu: <span class="paper-title">{{ paper_title }}</span></p>
63+
64+
<div class="message-box">
65+
<div class="sender-info">
66+
<strong>Od:</strong> {{ sender_name }}<br>
67+
<strong>Recenzent:</strong> {{ reviewer_name }}<br>
68+
<strong>Data:</strong> {{ message_date|date:"d F Y, H:i" }}
69+
</div>
70+
<div>
71+
<strong>Wiadomość:</strong><br>
72+
{{ message_text|linebreaks }}
73+
</div>
74+
</div>
75+
76+
<p>Prosimy o zalogowanie się do systemu, aby wyświetlić i odpowiedzieć na tę wiadomość.</p>
77+
78+
<p>Z poważaniem,<br>
79+
Zespół Systemu Recenzji</p>
80+
</div>
81+
82+
<div class="footer">
83+
To jest automatyczne powiadomienie. Prosimy nie odpowiadać na ten e-mail.
84+
</div>
85+
</body>
86+
</html>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Szanowny/a {{ author_name }},
2+
3+
Otrzymano nową wiadomość dotyczącą Twojego artykułu: {{ paper_title }}
4+
5+
Od: {{ sender_name }}
6+
Recenzent: {{ reviewer_name }}
7+
Data: {{ message_date|date:"d F Y, H:i" }}
8+
9+
Wiadomość:
10+
{{ message_text }}
11+
12+
Prosimy o zalogowanie się do systemu, aby wyświetlić i odpowiedzieć na tę wiadomość.
13+
14+
Z poważaniem,
15+
Zespół Systemu Recenzji
16+
17+
---
18+
To jest automatyczne powiadomienie. Prosimy nie odpowiadać na ten e-mail.

messaging/utils.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from django.core.mail import send_mail
2+
from django.conf import settings
3+
from django.template.loader import render_to_string
4+
from django.utils.html import strip_tags
5+
6+
def send_message_notification_email(message):
7+
paper = message.paper
8+
author = paper.author
9+
sender = message.author
10+
11+
if sender == author:
12+
return
13+
14+
if not author.email:
15+
return
16+
17+
subject = f'Nowa wiadomość dotycząca Twojego artykułu: {paper.title}'
18+
19+
context = {
20+
'author_name': f'{author.first_name} {author.last_name}',
21+
'sender_name': f'{sender.first_name} {sender.last_name}',
22+
'paper_title': paper.title,
23+
'message_text': message.text,
24+
'message_date': message.created_at,
25+
'reviewer_name': f'{message.reviewer.first_name} {message.reviewer.last_name}' if message.reviewer else 'System',
26+
}
27+
28+
html_message = render_to_string('email/message_notification.html', context)
29+
plain_message = render_to_string('email/message_notification.txt', context)
30+
31+
send_mail(
32+
subject=subject,
33+
message=plain_message,
34+
from_email=settings.DEFAULT_FROM_EMAIL,
35+
recipient_list=[author.email],
36+
html_message=html_message,
37+
fail_silently=False,
38+
)

messaging/views.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from django.http import JsonResponse
44
from django.shortcuts import render
55
from django.views.decorators.csrf import csrf_exempt
6+
from .utils import send_message_notification_email
67

78
from papers.models import Message, MessageSeen, Paper
89

@@ -69,12 +70,15 @@ def send_message(request):
6970
response.status_code = 400
7071

7172
if has_user_access_to_messages(user, paper):
72-
Message.objects.create(
73+
message = Message.objects.create(
7374
author=user,
7475
paper=paper,
7576
reviewer=reviewer,
7677
text=request.POST['message_text'],
7778
)
79+
80+
send_message_notification_email(message)
81+
7882
response.status_code = 200
7983
else:
8084
response.status_code = 400
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<!DOCTYPE html>
2+
<html lang="pl">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Powiadomienie o nowej recenzji</title>
7+
<style>
8+
body {
9+
font-family: Arial, sans-serif;
10+
line-height: 1.6;
11+
color: #333;
12+
max-width: 600px;
13+
margin: 0 auto;
14+
padding: 20px;
15+
}
16+
.header {
17+
background-color: #007bff;
18+
color: white;
19+
padding: 20px;
20+
text-align: center;
21+
border-radius: 5px 5px 0 0;
22+
}
23+
.content {
24+
background-color: #f8f9fa;
25+
padding: 20px;
26+
border: 1px solid #dee2e6;
27+
}
28+
.review-box {
29+
background-color: white;
30+
padding: 15px;
31+
border-left: 4px solid #007bff;
32+
margin: 15px 0;
33+
border-radius: 3px;
34+
}
35+
.footer {
36+
background-color: #6c757d;
37+
color: white;
38+
padding: 15px;
39+
text-align: center;
40+
border-radius: 0 0 5px 5px;
41+
font-size: 12px;
42+
}
43+
.paper-title {
44+
font-weight: bold;
45+
color: #007bff;
46+
}
47+
.reviewer-info {
48+
color: #6c757d;
49+
font-size: 14px;
50+
margin-bottom: 10px;
51+
}
52+
.grades-list {
53+
list-style: none;
54+
padding-left: 0;
55+
}
56+
.grades-list li {
57+
margin: 8px 0;
58+
padding: 5px 0;
59+
border-bottom: 1px solid #e9ecef;
60+
}
61+
.grades-list li:last-child {
62+
border-bottom: none;
63+
}
64+
</style>
65+
</head>
66+
<body>
67+
<div class="header">
68+
<h2>Nowa recenzja została dodana</h2>
69+
</div>
70+
71+
<div class="content">
72+
<p>Szanowny/a Autorze,</p>
73+
74+
<p>Otrzymano nową recenzję dotyczącą Twojego artykułu: <span class="paper-title">{{ paper.title }}</span></p>
75+
76+
<div class="review-box">
77+
<div class="reviewer-info">
78+
<strong>Recenzent:</strong> {{ reviewer.first_name }} {{ reviewer.last_name }}<br>
79+
<strong>Data recenzji:</strong> {{ review.created_at|date:"d F Y, H:i" }}
80+
</div>
81+
<div>
82+
<strong>Oceny:</strong>
83+
<ul class="grades-list">
84+
<li><strong>Zgodność z tematyką:</strong> {{ review.correspondence.name|default:"Brak" }}</li>
85+
<li><strong>Oryginalność:</strong> {{ review.originality.name|default:"Brak" }}</li>
86+
<li><strong>Poprawność merytoryczna:</strong> {{ review.merits.name|default:"Brak" }}</li>
87+
<li><strong>Jakość prezentacji:</strong> {{ review.presentation.name|default:"Brak" }}</li>
88+
<li><strong>Ocena końcowa:</strong> {{ review.final_grade.name|default:"Brak" }}</li>
89+
</ul>
90+
</div>
91+
</div>
92+
93+
<p>Aby zobaczyć pełną recenzję, prosimy o zalogowanie się do systemu.</p>
94+
95+
<p>Z poważaniem,<br>
96+
System Zarządzania Artykułami</p>
97+
</div>
98+
99+
<div class="footer">
100+
To jest automatyczne powiadomienie. Prosimy nie odpowiadać na ten e-mail.
101+
</div>
102+
</body>
103+
</html>

papers/templates/papers/paper_detail.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ <h4>Informacje o artykule</h4>
1515
</div>
1616
<div class="col-md-2 offset-md-4 text-right">
1717
{% if user == paper.author %}
18-
<div class="input-group mb-4">
18+
<div class="input-group mb-4 justify-content-between">
1919
<div class="input-group-prepend">
2020
<a href="{% url 'paperDelete' paper.pk %}">
2121
<button type="button" class="btn btn-danger">

papers/views.py

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
55
from django.contrib.messages.views import SuccessMessageMixin
66
from django.core.paginator import Paginator, PageNotAnInteger, EmptyPage
7+
from django.core.mail import EmailMultiAlternatives, BadHeaderError
78
from django.db import transaction
9+
from django.utils.html import strip_tags
810
from django.http import FileResponse, HttpResponseRedirect, HttpResponse
911
from django.shortcuts import redirect, render
1012
from django.template.loader import render_to_string
1113
from django.urls import reverse_lazy
1214
from django.views.decorators.csrf import csrf_exempt
1315
from django.views.generic import ListView, DetailView, CreateView, UpdateView, DeleteView, TemplateView
1416
from django.views.static import serve
15-
from StronaProjektyKol.settings import SITE_NAME, BASE_DIR
17+
from StronaProjektyKol.settings import SITE_NAME, BASE_DIR, SITE_ADMIN_MAIL
1618
from .filters import PaperFilter
1719
from .forms import *
1820

@@ -332,6 +334,45 @@ def handle_no_permission(self):
332334
return redirect('login')
333335

334336

337+
def send_review_notification_email(review):
338+
paper = review.paper
339+
reviewer = paper.reviewers.filter(pk=review.author.pk).first()
340+
341+
recipients = []
342+
343+
if paper.author.email:
344+
recipients.append(paper.author.email)
345+
346+
for coauthor in paper.coauthor_set.all():
347+
if coauthor.email:
348+
recipients.append(coauthor.email)
349+
350+
recipients = list(set(recipients))
351+
if not recipients:
352+
return
353+
354+
context = {
355+
"paper": paper,
356+
"reviewer": reviewer,
357+
"review": review,
358+
}
359+
360+
subject = f"Nowa recenzja dla artykułu: {paper.title[:50]}..."
361+
html_content = render_to_string("emails/review_notification.html", context)
362+
plain_text_content = strip_tags(html_content)
363+
364+
msg = EmailMultiAlternatives(
365+
subject=subject,
366+
body=plain_text_content,
367+
from_email=SITE_ADMIN_MAIL,
368+
to=[SITE_ADMIN_MAIL],
369+
bcc=recipients,
370+
headers={'Reply-To': SITE_ADMIN_MAIL}
371+
)
372+
373+
msg.attach_alternative(html_content, "text/html")
374+
msg.send()
375+
335376
class ReviewCreateView(CsrfExemptMixin, LoginRequiredMixin, UserPassesTestMixin, SuccessMessageMixin, CreateView):
336377
model = Review
337378
template_name = 'papers/review_add.html'
@@ -361,7 +402,12 @@ def handle_no_permission(self):
361402
def form_valid(self, form):
362403
form.instance.author = self.request.user
363404
form.instance.paper = Paper.objects.get(pk=self.kwargs.get('paper'))
364-
return super(ReviewCreateView, self).form_valid(form)
405+
406+
response = super(ReviewCreateView, self).form_valid(form)
407+
408+
send_review_notification_email(self.object)
409+
410+
return response
365411

366412

367413
class ReviewUpdateView(SuccessMessageMixin, CsrfExemptMixin, LoginRequiredMixin, UserPassesTestMixin, UpdateView):

0 commit comments

Comments
 (0)