SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit faf70d31 authored by Jorran de Wit's avatar Jorran de Wit
Browse files

Set mail for prepublication

parent c1be3039
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,8 @@ import json ...@@ -4,6 +4,8 @@ import json
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.decorators import permission_required from django.contrib.auth.decorators import permission_required
from django.core.urlresolvers import reverse, reverse_lazy from django.core.urlresolvers import reverse, reverse_lazy
from django.db import transaction
from django.utils.decorators import method_decorator
from django.views.generic.edit import CreateView from django.views.generic.edit import CreateView
from django.shortcuts import get_object_or_404, render, redirect from django.shortcuts import get_object_or_404, render, redirect
...@@ -78,6 +80,7 @@ class HttpRefererMixin: ...@@ -78,6 +80,7 @@ class HttpRefererMixin:
return super().form_valid(form) return super().form_valid(form)
@method_decorator(transaction.atomic, name='dispatch')
class CreateGrantView(PermissionsMixin, HttpRefererMixin, CreateView): class CreateGrantView(PermissionsMixin, HttpRefererMixin, CreateView):
""" """
Create a Grant in a separate window which may also be used by Production Supervisors. Create a Grant in a separate window which may also be used by Production Supervisors.
......
...@@ -52,14 +52,7 @@ class MailUtilsMixin: ...@@ -52,14 +52,7 @@ class MailUtilsMixin:
self.mail_template = mail_template.render(kwargs) self.mail_template = mail_template.render(kwargs)
# Gather Recipients data # Gather Recipients data
self.original_recipient = '' self.original_recipient = self._validate_single_entry(self.mail_data.get('to_address'))[0]
if self.object:
recipient = self.object
for attr in self.mail_data.get('to_address').split('.'):
recipient = getattr(recipient, attr)
if inspect.ismethod(recipient):
recipient = recipient()
self.original_recipient = recipient
self.subject = self.mail_data['subject'] self.subject = self.mail_data['subject']
...@@ -74,18 +67,20 @@ class MailUtilsMixin: ...@@ -74,18 +67,20 @@ class MailUtilsMixin:
# Email string # Email string
return [entry] return [entry]
else: else:
bcc_to = self.object mail_to = self.object
for attr in entry.split('.'): for attr in entry.split('.'):
try: try:
bcc_to = getattr(bcc_to, attr) mail_to = getattr(mail_to, attr)
if inspect.ismethod(mail_to):
mail_to = mail_to()
except AttributeError: except AttributeError:
# Invalid property, don't use bcc # Invalid property/mail
return [] return []
if not isinstance(bcc_to, list): if not isinstance(mail_to, list):
return [bcc_to] return [mail_to]
else: else:
return bcc_to return mail_to
elif re.match("[^@]+@[^@]+\.[^@]+", entry): elif re.match("[^@]+@[^@]+\.[^@]+", entry):
return [entry] return [entry]
...@@ -96,8 +91,9 @@ class MailUtilsMixin: ...@@ -96,8 +91,9 @@ class MailUtilsMixin:
""" """
# Get recipients list. Try to send through BCC to prevent privacy issues! # Get recipients list. Try to send through BCC to prevent privacy issues!
self.bcc_list = [] self.bcc_list = []
for bcc_entry in self.mail_data.get('bcc_to', '').split(','): if self.mail_data.get('bcc_to'):
self.bcc_list += self._validate_single_entry(bcc_entry) for bcc_entry in self.mail_data['bcc_to'].split(','):
self.bcc_list += self._validate_single_entry(bcc_entry)
def validate_recipients(self): def validate_recipients(self):
# Check the send list # Check the send list
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment