Beispiel #1
0
def createPost(request):
    form = DetailedPost(request.POST, request.FILES)
    if form.is_valid():
        mailid = form.cleaned_data.get('mailid')
        status = form.cleaned_data.get('status')
        postername = form.cleaned_data.get('postername')
        mobilenumber = form.cleaned_data.get('mobilenumber')
        location = form.cleaned_data.get('location')
        date = form.cleaned_data.get('fdate')
        time = form.cleaned_data.get('time')
        defintion = form.cleaned_data.get('definition')
        description = form.cleaned_data.get('description')
        # post_count=DummyPost.objects.filter().count()

        newpost = Post(mailid=mailid,
                       status=status,
                       posterName=postername,
                       mobileNumber=mobilenumber,
                       location=location,
                       defintion=defintion,
                       description=description,
                       date=date,
                       time=time)
        newpost.save()
        for f in request.FILES.getlist('image'):
            curimg = PostImage(imagefile=f, post=newpost)
            curimg.save()

        postId = str(newpost.id)

        subject = "Your post has been Acknowledged."
        message = "Hi, " + newpost.posterName + "! " + "Your " + newpost.get_status(
        ) + " post at https://www.LinGa.com has been successfully published! You can view the post at http://localhost:8000/posts/" + str(
            newpost.id
        ) + " .You can visit it to search for new feedbacks there. Best of luck!"

        from_email = settings.EMAIL_HOST_USER
        to_email = [newpost.mailid]
        send_mail(subject, message, from_email, to_email, fail_silently=True)

        return redirect('/posts/' + postId)

    return render(request, 'landing/postfeed.html',
                  {'messg': "Something Went Wrong"})
Beispiel #2
0
def createnidLostPost(request):
    form = nid(request.POST)
    if form.is_valid():
        mailid = form.cleaned_data.get('mailid')
        status = form.cleaned_data.get('status')
        postername = form.cleaned_data.get('postername')
        mobilenumber = form.cleaned_data.get('mobilenumber')
        location = form.cleaned_data.get('location')
        dat = datetime.today().strftime('%Y-%m-%d')
        tim = datetime.now().strftime("%H:%M:%S")
        defintion = 'nid'
        description = form.cleaned_data.get('country')

        newpost = Post(mailid=mailid,
                       status=status,
                       posterName=postername,
                       mobileNumber=mobilenumber,
                       location=location,
                       defintion=defintion,
                       description=description,
                       date=dat,
                       time=tim)
        newpost.save()

        postId = str(newpost.id)

        subject = "Your post has been Acknowledged."
        message = "Hi, " + newpost.posterName + "! " + "Your " + newpost.get_status(
        ) + " post at https://www.LinGa.com has been successfully published! You can view the post at http://localhost:8000/posts/" + str(
            newpost.id
        ) + " .You can visit it to search for new feedbacks there. Best of luck!"

        from_email = settings.EMAIL_HOST_USER
        to_email = [newpost.mailid]
        send_mail(subject, message, from_email, to_email, fail_silently=True)

        return redirect('/posts/' + postId)

    return render(request, 'landing/postfeed.html',
                  {'messg': "Something Went Wrong"})