Skip to content

Commit b2e43fa

Browse files
authored
Merge pull request #54 from skni-kod/feature/review-email-notification
Feature/review email notification
2 parents 9f0d24d + 9e20e35 commit b2e43fa

File tree

3 files changed

+152
-3
lines changed

3 files changed

+152
-3
lines changed
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)