Add a basic email on case study submission. Closes #50.
This commit is contained in:
parent
1847b22c09
commit
f4a7a108b5
@ -1,3 +1,5 @@
|
||||
from django.core.mail import send_mail
|
||||
from django.conf import settings
|
||||
from django.views.generic import DetailView
|
||||
from django.views.generic.base import TemplateView
|
||||
from django.views.generic.edit import CreateView
|
||||
@ -6,6 +8,17 @@ from django.urls import reverse
|
||||
from .models import CaseStudy
|
||||
from .forms import ShortCaseStudyForm, LongCaseStudyForm
|
||||
|
||||
NOTIFY_MESSAGE = """
|
||||
Hello,
|
||||
|
||||
Someone has submitted a new case study to the Ojuso website. Please
|
||||
follow the below link to look over and approve it:
|
||||
|
||||
%s%s
|
||||
|
||||
– Case Study Robot
|
||||
|
||||
"""
|
||||
|
||||
class Map(TemplateView):
|
||||
template_name = "map/index.html"
|
||||
@ -21,6 +34,25 @@ class BaseForm(LoginRequiredMixin, CreateView):
|
||||
success_url = '/case-study/create/success/'
|
||||
model = CaseStudy
|
||||
|
||||
def send_email(self):
|
||||
"""Sends email to moderator to approve case study."""
|
||||
|
||||
send_mail(
|
||||
'New case study submitted',
|
||||
NOTIFY_MESSAGE % (
|
||||
settings.SITE_URL,
|
||||
reverse('admin:map_casestudy_change', args=[self.object.id])
|
||||
),
|
||||
'noreply@ojuso.org',
|
||||
['database@ojuso.org'],
|
||||
fail_silently=False,
|
||||
)
|
||||
|
||||
def form_valid(self, form):
|
||||
self.object = form.save()
|
||||
self.send_email()
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
class ShortForm(BaseForm):
|
||||
"""View for short version of case study form."""
|
||||
|
@ -84,6 +84,7 @@ MIDDLEWARE = [
|
||||
ROOT_URLCONF = 'ojusomap.urls'
|
||||
|
||||
SITE_ID = 1
|
||||
SITE_URL = 'https://map.ojuso.org'
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user