send_mail -> EmailMessage
This commit is contained in:
parent
cd9aa73a34
commit
b8a9d67cc2
3 changed files with 19 additions and 9 deletions
|
@ -12,7 +12,7 @@ from django.contrib import admin
|
||||||
from reversion.admin import VersionAdmin
|
from reversion.admin import VersionAdmin
|
||||||
from korektury.models import KorekturovanePDF
|
from korektury.models import KorekturovanePDF
|
||||||
|
|
||||||
from django.core.mail import send_mail
|
from django.core.mail import EmailMessage
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
|
@ -64,6 +64,11 @@ Popis souboru:
|
||||||
S pozdravem a korekturám zdar!
|
S pozdravem a korekturám zdar!
|
||||||
Korekturovátko
|
Korekturovátko
|
||||||
'''
|
'''
|
||||||
send_mail(predmet,text,odesilatel,[prijemce])
|
EmailMessage(
|
||||||
|
subject=predmet,
|
||||||
|
body=text,
|
||||||
|
from_email=odesilatel,
|
||||||
|
to=[prijemce],
|
||||||
|
).send()
|
||||||
|
|
||||||
admin.site.register(KorekturovanePDF, KorekturovanePDFAdmin)
|
admin.site.register(KorekturovanePDF, KorekturovanePDFAdmin)
|
||||||
|
|
|
@ -8,7 +8,7 @@ from django.views import generic
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.http import HttpResponseForbidden
|
from django.http import HttpResponseForbidden
|
||||||
from django.core.mail import send_mail
|
from django.core.mail import EmailMessage
|
||||||
from django.db.models import Count,Q
|
from django.db.models import Count,Q
|
||||||
|
|
||||||
from .models import Oprava,Komentar,KorekturovanePDF, Organizator
|
from .models import Oprava,Komentar,KorekturovanePDF, Organizator
|
||||||
|
@ -207,7 +207,12 @@ class KorekturyView(generic.TemplateView):
|
||||||
print("---- Konec upozornění")
|
print("---- Konec upozornění")
|
||||||
return
|
return
|
||||||
|
|
||||||
send_mail(subject, text, from_email, list(emails))
|
EmailMessage(
|
||||||
|
subject=subject,
|
||||||
|
body=text,
|
||||||
|
from_email=from_email,
|
||||||
|
to=list(emails),
|
||||||
|
).send()
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
from django.views.generic import ListView, DetailView, FormView
|
from django.views.generic import ListView, DetailView, FormView
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
from django.core.mail import send_mail
|
from django.core.mail import EmailMessage
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.views.generic import ListView, DetailView, FormView, CreateView
|
from django.views.generic import ListView, DetailView, FormView, CreateView
|
||||||
from django.views.generic.list import MultipleObjectTemplateResponseMixin,MultipleObjectMixin
|
from django.views.generic.list import MultipleObjectTemplateResponseMixin,MultipleObjectMixin
|
||||||
|
@ -449,11 +449,11 @@ class NahrajReseniView(LoginRequiredMixin, CreateView):
|
||||||
seznam = "problému " + str(problemy[0]) if len(problemy) == 1 else 'následujícím problémům:\n' + ', \n'.join(map(str, problemy))
|
seznam = "problému " + str(problemy[0]) if len(problemy) == 1 else 'následujícím problémům:\n' + ', \n'.join(map(str, problemy))
|
||||||
seznam_do_subjectu = "problému " + str(problemy[0]) + ("" if len(problemy) == 1 else f" (a dalším { len(problemy) - 1 })")
|
seznam_do_subjectu = "problému " + str(problemy[0]) + ("" if len(problemy) == 1 else f" (a dalším { len(problemy) - 1 })")
|
||||||
|
|
||||||
send_mail(
|
EmailMessage(
|
||||||
subject="Nové řešení k " + seznam_do_subjectu,
|
subject="Nové řešení k " + seznam_do_subjectu,
|
||||||
message=f"Řešitel{ '' if resitel.pohlavi_muz else 'ka' } { resitel } právě nahrál{'' if resitel.pohlavi_muz else 'a' } nové řešení k { seznam }.\n\nHurá do opravování: { self.object.absolute_url() }",
|
body=f"Řešitel{ '' if resitel.pohlavi_muz else 'ka' } { resitel } právě nahrál{'' if resitel.pohlavi_muz else 'a' } nové řešení k { seznam }.\n\nHurá do opravování: { self.object.absolute_url() }",
|
||||||
from_email="submitovatko@mam.mff.cuni.cz", # FIXME: Chceme to mít radši tady, nebo v nastavení?
|
from_email="submitovatko@mam.mff.cuni.cz", # FIXME: Chceme to mít radši tady, nebo v nastavení?
|
||||||
recipient_list=list(prijemci),
|
to=list(prijemci),
|
||||||
)
|
).send()
|
||||||
|
|
||||||
return formularOKView(self.request, text='Řešení úspěšně odevzdáno')
|
return formularOKView(self.request, text='Řešení úspěšně odevzdáno')
|
||||||
|
|
Loading…
Reference in a new issue