Ejemplo n.º 1
0
def share_via_email(request):
    url = '/'
    if request.method == 'POST':
        id  = request.POST.get('id')
        url = request.build_absolute_uri((reverse('idea_details', kwargs={'pk': id})))
        send_email('Idea Shared', 'Hi, Refer to view: %s ' % (url,) , request.POST.get('email'))
    return HttpResponseRedirect(url)
Ejemplo n.º 2
0
 def partial_update(self, request, *args, **kwargs):
     serializer = self.get_serializer(data=request.data)
     serializer.is_valid()
     serializer.complete(self.get_object(), serializer.data.get('status'))
     super(TaskViewSet, self).partial_update(request, *args, **kwargs)
     send_email(pk=self.get_object().id)
     # send_email.delay(pk=self.get_object().id)
     return Response(TaskSerializer(self.get_object()).data)
Ejemplo n.º 3
0
 def delete(self, request, *args, **kwargs):
     """
     Call the delete() method on the fetched object and then redirect to the
     success URL.
     """
     self.object = self.get_object()
     self.object.deleted_at = timezone.now()
     self.object.save()
     send_email('Your idea deleted successfully!', 'Hi, your deleted successfully', self.object.owner.email)
     return HttpResponseRedirect(self.success_url)
Ejemplo n.º 4
0
def email_from_admin(username, subject, message, html=False):
    """ Use user, subject and message to build and send a standard
        Atmosphere admin email from admins to a user.
        Returns True on success and False on failure.
    """
    from_name, from_email = admin_address()
    user_email = lookupEmail(username)
    if not user_email:
        user_email = "%s@%s" % (username, settings.DEFAULT_EMAIL_DOMAIN)
    send_email(subject, message,
               from_email=email_address_str(from_name, from_email),
               to=[email_address_str(username, user_email)],
               cc=[email_address_str(from_name, from_email)],
               html=html)

    return True
Ejemplo n.º 5
0
def email_to_admin(
        subject,
        body,
        username=None,
        user_email=None,
        cc_user=True,
        admin_user=None,
        request_tracker=False,
        html=False):
    """
    Send a basic email to the admins. Nothing more than subject and message
    are required.
    """
    if admin_user:
        sendto, sendto_email = admin_address(admin_user)
    elif request_tracker:
        sendto, sendto_email = request_tracker_address()
    else:
        sendto, sendto_email = admin_address()
    # E-mail yourself if no users are provided
    if not username and not user_email:
        username, user_email = sendto, sendto_email
    elif not user_email:  # Username provided
        # TODO: Pass only strings, avoid passing 'User' object here.
        if isinstance(username, User):
            username = username.username
        user_email = lookupEmail(username)
        if not user_email:
            user_email = "%s@%s" % (username, settings.DEFAULT_EMAIL_DOMAIN)
    elif not username:  # user_email provided
        username = '******'
    if request_tracker or not cc_user:
        # Send w/o the CC
        cc = []
    else:
        cc = [email_address_str(username, user_email)]

    send_email(subject, body,
               from_email=email_address_str(username, user_email),
               to=[email_address_str(sendto, sendto_email)],
               cc=cc,
               html=html)

    return True
Ejemplo n.º 6
0
def test_send_email():
    mail.outbox = []
    subject = 'Foo'
    text_body = 'bar'
    html_body = '<a>bar</a>'
    recipient_email = '*****@*****.**'
    from_email = '*****@*****.**'

    send_email(
        subject=subject,
        text_body=text_body,
        html_body=html_body,
        recipient_email=recipient_email,
        from_email=from_email,
    )

    assert len(mail.outbox) == 1
    email = mail.outbox[0]
    assert email.body == text_body
    assert email.to[0] == recipient_email
    assert email.from_email == from_email
    assert email.subject == subject
    assert email.alternatives[0] == (html_body, 'text/html')
Ejemplo n.º 7
0
 def form_valid(self, form):
     obj = form.save(commit=False)
     obj.owner = self.request.user
     obj.save()
     send_email('New idea created!', 'Hi, your new idea created', obj.owner.email)
     return super().form_valid(form)