Exemplo n.º 1
0
def MailSendView(request, id):
    post = get_object_or_404(Post, id=id, status='published')
    sent = False  #default send is falase
    if request.method == 'POST':  # when ever fill the form and click send mail button the request is post method
        form = EmailForm(request.POST)  #create form object with data
        if form.is_valid():  # chek validations
            cd = form.cleaned_data  # This method returns the clean data, which is then inserted into the cleaned_data dictionary of the form.# it is end user submited form data
            #cleaned_data is dictionary which is stores all form fields
            subject = "{}({}) recomeds you read '{}'".format(
                cd['name'], cd['email'], post.title)
            #post_url=post.get_absolute_url()# it gives absloute url means    2019/05/11/indian-army/  total url means http://127.0.0.1:8000/2019/05/11/indian-army/
            post_url = request.build_absolute_uri(
                post.get_absolute_url()
            )  #gives main url means http://127.0.0.1:8000 and post.get_absolute_url() gives 2019/05/11/indian-army/
            #finalyy this post_url gives total url  http://127.0.0.1:8000/2019/05/15/data-science/
            message = "Reat post at :\n {}\n\n{}\'s Comments:\n{}".format(
                post_url, cd['name'], cd['comments'])
            send_mail(
                subject, message, '*****@*****.**', [cd['to']]
            )  #cd is dict cd['to']='recever mail' ,recever mail put in list [cd['to']]
            #send_mail('subject','message','sender mail',['recever mail'])
            sent = True
            print('status code of mail', sent)
    else:  #if method is not post method display form end user
        form = EmailForm()

    return render(request, 'blog/sharebyemail.html', {
        'post': post,
        'form': form,
        'sent': sent
    })
Exemplo n.º 2
0
Arquivo: views.py Projeto: Eimis/yaga
def contact(request):
    if request.is_ajax():
        form = EmailForm(request.POST)
        if form.is_valid():
            subject = ('Contact message from '
                       + form.cleaned_data['name']
                       + ' (' + form.cleaned_data['sender'] + ')')
            sender = form.cleaned_data['sender']
            message = form.cleaned_data['message']
            recipient = [settings.MY_EMAIL, ]

            send_mail(subject, message, sender, recipient)
            return HttpResponse(json.dumps({'success': True}))
        else:
            return HttpResponse(json.dumps(form.errors))
    else:
        return HttpResponse(status=400)  # bad request
Exemplo n.º 3
0
def post_email_view(request, id):
    post = get_object_or_404(Post, id=id, status="published")
    sent = False
    if request.method == 'POST':
        form = EmailForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            post_url = request.build_absolute_uri(post.get_absolute_url())
            send_mail = ('subject', 'message', '*****@*****.**', [cd['to']])
            sent = True
    else:
        form = EmailForm()
    return render(request, 'blog/sharebymail.html', {
        'form': form,
        'post': post,
        'sent': sent
    })
Exemplo n.º 4
0
def post_share(request, pk):
    post = get_object_or_404(Post, pk=pk, status='publicado')
    sent = False
    if request.method == 'POST':
        form = EmailForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            post_url = request.build_absolute_uri(post.get_absolute_url())
            subject = f"{data['nome']}"
            message = f"Leia o post {post.titulo} em {post_url}\n\n"\
                f"Seu comentário:{data['comentario']}"
            send_mail(subject, message, '*****@*****.**', [data['email']])
            sent = True

    else:
        form = EmailForm()

    return render(request, 'blog/share.html', {
        'post': post,
        'form': form,
        'sent': sent
    })
Exemplo n.º 5
0
def post_share(request, post_id):
    post = get_object_or_404(Post, id=post_id, status='published')
    form = EmailForm()
    sent = False

    if request.method == "POST":
        form = EmailForm(request.POST)
        if form.is_valid():
            terms = form.cleaned_data
            post_url = request.build_absolute_uri(post.get_absolute_url())
            subject = f"{ post.title } was intresting check this out..!"
            message = f"{ post_url } of "\
                      f"By: {terms['name']}'s \n comments:{terms['subject']}"
            send_mail(subject, message, '*****@*****.**',
                      [terms['to']])
            sent = True
        else:
            form = EmailForm()
    return render(request, 'blog/share.html', {
        'form': form,
        'sent': sent,
        'post': post
    })