Exemple #1
0
def VersionEmail(request, pk):
    # dictionary for initial data with
    # field names as keys
    context = {}

    # fetch the object related to passed id
    obj = get_object_or_404(Email, pk=pk)
    #obj.photo.delete()
    #obj.photo.open(mode='rb')

    # pass the object as instance in form
    form = EmailForm(request.POST or None, instance=obj)

    # save the data from the form and
    # redirect to detail_view
    if form.is_valid():
        obj.pk = int(round(time.time() * 1000))
        #form.photo = request.POST.get('photo', False)
        #form.photo = request.FILES['photo']
        form.instance.creator = request.user
        form.save()
        return HttpResponseRedirect(reverse("emails:all"))

    else:

        # add form dictionary to context
        context["form"] = form

        return render(request, "emails/email_form.html", context)
Exemple #2
0
 def test_edit_form_invalid(self):
     form = EmailForm(data={'from_email': "*****@*****.**",
                            'to_email': "",
                            'subject': "hello hi",
                            'message': 'simple mail'})
     # print('yes2')
     self.assertFalse(form.is_valid())
 def test_edit_form_invalid(self):
     form = EmailForm(data={'from_email': "*****@*****.**",
                            'to_email': "",
                            'subject': "test subject",
                            'message': 'test message'})
     # print('yes2')
     self.assertFalse(form.is_valid())
Exemple #4
0
 def test_edit_form_invalid(self):
     form = EmailForm(
         data={
             "from_email": "*****@*****.**",
             "to_email": "",
             "subject": "test subject",
             "message": "test message",
         })
     # print('yes2')
     self.assertFalse(form.is_valid())
Exemple #5
0
def send_email(request):
    if request.method == "POST":
        email_form = EmailForm(request.POST)
        if email_form.is_valid():
            data = email_form.cleaned_data
            from_email = data["email_address"]
            subject = " ".join(["[biodiesel_request]", data["subject"]])
            message = data["message"]
            send_mail(subject, message, from_email, ["*****@*****.**",])      
            return HttpResponseRedirect(reverse("email_sent"))
    else:
        email_form = EmailForm()
    
    return render_to_response("emails/send_email.html", {
        "email_form": email_form,
    })
Exemple #6
0
def sent_view(request, pk):
    email = get_object_or_404(Email, pk=pk)
    if request.method == "POST":
        return redirect("emails:sent")

    else:
        form = EmailForm(instance=email)
    return render(request, "sent_view.html.j2", {"form": form})
Exemple #7
0
def email(request):
    if request.method == "POST":
        form = EmailForm(request.POST, request.FILES)
        if form.is_valid():
            subject = request.POST.get('subject', '')
            message = request.POST.get('message', '')
            from_email = request.POST.get('from_email', '')
            to_email = request.POST.get('to_email', '')
            file = request.FILES.get('files', None)
            status = request.POST.get('email_draft', '')
            email = EmailMessage(subject, message, from_email, [to_email])
            email.content_subtype = "html"
            f = form.save()
            if file is not None:
                email.attach(file.name, file.read(), file.content_type)
                f.file = file
            if status:
                f.status = "draft"
            else:
                email.send(fail_silently=False)
            f.save()
            return HttpResponseRedirect(reverse('emails:list'))
        else:
            return render(request, 'create_mail.html', {'form': form})
    else:
        form = EmailForm()
        return render(request, 'create_mail.html', {'form': form})
def email(request):
    if request.method == "POST":
        form = EmailForm(request.POST, request.FILES)
        if form.is_valid():
            subject = request.POST.get("subject", "")
            message = request.POST.get("message", "")
            from_email = request.POST.get("from_email", "")
            to_email = request.POST.get("to_email", "")
            file = request.FILES.get("files", None)
            status = request.POST.get("email_draft", "")
            email = EmailMessage(subject, message, from_email, [to_email])
            email.content_subtype = "html"
            f = form.save()
            if file is not None:
                email.attach(file.name, file.read(), file.content_type)
                f.file = file
            if status:
                f.status = "draft"
            else:
                email.send(fail_silently=False)
            f.save()
            return HttpResponseRedirect(reverse("emails:list"))
        else:
            return render(request, "create_mail.html", {"form": form})
    else:
        form = EmailForm()
        return render(request, "create_mail.html", {"form": form})
Exemple #9
0
def emails(request):
    if request.method == "POST":
        form = EmailForm(request.POST)     

        if form.is_valid(): 

            print("Form is valid")
            email=form.save(commit=False)
            email.created_by=request.user
            email.save() 

            if "send_message" in request.POST:
                email.status = "sent"
            elif "schedule_message" in request.POST:
                email.status = "scheduled"
            elif "save_draft" in request.POST:
                email.status = "draft"
            
            email.to.set(form.cleaned_data["to"])
            email.save()
        else:
            print("Form is invalid")
            for error in form.errors:
                print(error)
    else:
        form = EmailForm()
    return render(request, "emails.html.j2", {"form": form})
Exemple #10
0
def email_sent_edit(request, pk):
    em = get_object_or_404(Email, pk=pk)
    if request.method == 'POST':
        form = EmailForm(request.POST, instance=em)
        if form.is_valid():
            subject = request.POST.get('subject', '')
            message = request.POST.get('message', '')
            from_email = request.POST.get('from_email', '')
            to_email = request.POST.get('to_email', '')
            file = request.FILES.get('files', None)
            status = request.POST.get('email_draft', '')
            email = EmailMessage(subject, message, from_email, [to_email])
            f = form.save()
            if file is not None:
                email.attach(file.name, file.read(), file.content_type)
                f.file = file
            if status:
                f.status = "draft"
            else:
                email.send(fail_silently=False)
                f.status = "sent"
            f.save()
            return HttpResponseRedirect(reverse('emails:list'))
        else:
            return render(request, 'create_mail.html',
                          {'form': form, 'em': em})
    else:
        form = EmailForm()
    return render(request, 'create_mail.html',
                  {'form': form, 'em': em})
Exemple #11
0
def email_edit(request, pk):
    email = get_object_or_404(Email, pk=pk)
    if request.method == "POST":
        form = EmailForm(request.POST, instance=email)
        if form.is_valid():
            email = form.save(commit=False)
            email.to.set(form.cleaned_data["to"])
            if "send_message" in request.POST:
                email.status = "sent"
                email.save()
                return redirect("emails:sent")
            elif "schedule_message" in request.POST:
                email.status = "scheduled"
                email.save()
                return redirect("emails:outbox")
            elif "save_draft" in request.POST:
                email.status = "draft"
                email.save()
                return redirect("emails:drafts")
    else:
        form = EmailForm(instance=email)
    return render(request, "emails_edit.html.j2", {"form": form})
Exemple #12
0
def email_view(request, pk):
    email_view = get_object_or_404(Email, pk=pk)
    x = EmailForm(instance=email_view)
    return render(request, 'create_mail.html', {'x': x})