def send_notification_email(self, template_method, users=None, context=None): if not users: return if not isinstance(users, collections.Iterable): users = (users,) mails = template_mail.MagicMailBuilder() for user in users: email = getattr(mails, template_method)(user, context) email.send()
def _send_contact_email(self, request, contact): context = { 'request': request, 'contact': contact, 'project_name': get_configuration("QS_PROJECT_NAME"), 'project_url': get_configuration("QS_PROJECT_URL"), } mails = template_mail.MagicMailBuilder() email = mails.new_contact(get_configuration("QS_PROJECT_CONTACT"), context, headers={"Reply-To": contact.email}) email.send()
def send_change_email(self, request, user): signer = Signer() context = { 'request': request, 'user': user, 'activation_key': signer.sign(user.get_username()), 'project_name': get_configuration("QS_PROJECT_NAME"), 'project_url': get_configuration("QS_PROJECT_URL"), } mails = template_mail.MagicMailBuilder() email = mails.change_email(user.new_email, context) email.send()
def send_password_reset_email(self, request, user): signer = TimestampSigner() reset_token = signer.sign(user.get_username()) context = { "request": request, "user": user, "project_name": get_configuration("QS_PROJECT_NAME"), "project_url": get_configuration("QS_PROJECT_URL"), "reset_token": reset_token, } mails = template_mail.MagicMailBuilder() email = mails.password_reset(user, context) email.send()
def send_activation_email(self, request, user): signer = TimestampSigner() context = { 'request': request, 'user': user, 'activation_key': signer.sign(user.get_username()), 'project_name': get_configuration("QS_PROJECT_NAME"), 'project_url': get_configuration("QS_PROJECT_URL"), 'expiration_days': get_configuration("QS_SIGNUP_TOKEN_EXPIRATION_DAYS"), } mails = template_mail.MagicMailBuilder() email = mails.activation(user, context) email.send()
from sbirez.serializers import FirmSerializer, ProposalSerializer, PartialProposalSerializer from sbirez.serializers import AddressSerializer, ElementSerializer from sbirez.serializers import JargonSerializer, NaicsSerializer from sbirez.serializers import PersonSerializer, DocumentSerializer, DocumentVersionSerializer import marshmallow as mm from rest_framework.permissions import AllowAny, IsAuthenticated from .permissions import IsStaffOrTargetUser, IsStaffOrFirmRelatedUser from .permissions import HasObjectEditPermissions, ReadOnlyUnlessStaff from .utils import nested_update from PyPDF2 import PdfFileMerger from pywkher import generate_pdf mails = template_mail.MagicMailBuilder() # To send new types of emails from views, simply call # `mails.my_new_email_name(target_email_address, {dict for template substitution}) # and write files `sbirez/templates/emails/my_new_email_name-body-text.html` # (or `sbirez/templates/emails/my_new_email_name-body-html.html`) # and `sbirez/templates/emails/my_new_email_name-subject.html` class UserViewSet(viewsets.ModelViewSet): """ API endpoint that allows users to be viewed or edited. """ queryset = get_user_model().objects.all() serializer_class = UserSerializer def get_permissions(self):