def contactLandOwner(farmlandId):
    form = ContactLandOwnerForm(request.form)
    farmland = Farmland.query.filter(Farmland.id == farmlandId).all()[0]
    if form.validate_on_submit():
        address = "Unknown" if farmland.address is None else farmland.address
        mainBodyContent = ("<p style=\"margin-left: 50px;\">"
                                "<b>Name:</b> " + form.name.data + "<br>"
                                "<b>Email:</b> " + form.email.data + "<br>"
                                "<b>Phone:</b> " + form.phone.data + "<br>"
                            "</p>"
                            "<p style=\"margin-left: 50px;\">"
                                "<b>What is your past experience farming?</b><br>"
                                "" + form.experience.data + "</p>"
                            "<p><br>Thanks,<br>"
                                "Acres"
                            "</p>")
        # msg = Message("Inquiry: " + address + " Property", recipients=["*****@*****.**")
        msg = Message("Inquiry: " + address + " Property", recipients=[farmland.email])
        msg.html = ("<html>"
                        "<body>"
                            "<p>Someone has contacted you about your " + address + " property:</p>"
                            "" + mainBodyContent + ""
                        "</body>"
                    "</html>")
        mail.send(msg)
        Email.create(sender=msg.sender,
                        recipients=",".join(msg.recipients),
                        body=msg.html)
        msg = Message("Inquiry: " + address + " Property", recipients=[form.email.data])
        msg.html = ("<html>"
                        "<body>"
                            "<p>Just a note that we sent your request for more information about the " + address + " property to " + farmland.ownerName + ":</p>"
                            "" + mainBodyContent + ""
                        "</body>"
                    "</html>")
        mail.send(msg)
        Email.create(sender=msg.sender,
                        recipients=",".join(msg.recipients),
                        body=msg.html)
        flash("Thanks for your inquiry! We sent your email for more information about the property. " + farmland.ownerName + " will follow up with you shortly.", 'info')
        return redirect(url_for('public.home'))
    else:
        flash_errors(form)
    return render_template("public/contact-land-owner.html", form=form, farmland=farmland)
def reject(farmlandId):
    farmland = Farmland.query.filter(Farmland.id == farmlandId).all()[0]
    msg = Message("Your property cannot be published on Acres", recipients=[farmland.email])
    msg.html = ("<html>"
                    "<body>"
                        "<p>"
                            "We're sorry, but your property cannot be published on Acres at this time. "
                            "Someone will be reaching out to your with more information."
                        "</p>"
                        "<p>Thanks,<br>"
                            "Acres"
                        "</p>"
                    "</body>"
                "</html>")
    mail.send(msg)
    Email.create(sender=msg.sender,
                    recipients=",".join(msg.recipients),
                    body=msg.html)
    return redirect(url_for('public.home'))
def approve(farmlandId):
    farmland = Farmland.query.filter(Farmland.id == farmlandId).all()[0]
    db.session.query(Farmland).filter(Farmland.id == farmlandId).update({"public": True})
    db.session.commit()
    msg = Message("Your property is now published on Acres!", recipients=[farmland.email])
    anchorTagHtml = "<a href=\"http://" + server + "/farmland-details/" + str(farmlandId) + "\">the property listing</a>"
    msg.html = ("<html>"
                    "<body>"
                        "<p>Please, visit " + anchorTagHtml + " on Acres to see how it looks.</p>"
                        "<p>Thanks,<br>"
                            "Acres"
                        "</p>"
                    "</body>"
                "</html>")
    mail.send(msg)
    Email.create(sender=msg.sender,
                recipients=",".join(msg.recipients),
                body=msg.html)
    return redirect(url_for('public.home'))