forked from bradtraversy/btre_project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.py
40 lines (33 loc) · 1.44 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from django.shortcuts import render, redirect
from django.contrib import messages
from django.core.mail import send_mail
from .models import Contact
def contact(request):
if request.method == 'POST':
listing_id = request.POST['listing_id']
listing = request.POST['listing']
name = request.POST['name']
email = request.POST['email']
phone = request.POST['phone']
message = request.POST['message']
user_id = request.POST['user_id']
realtor_email = request.POST['realtor_email']
# Check if user has made inquiry already
if request.user.is_authenticated:
user_id = request.user.id
has_contacted = Contact.objects.all().filter(listing_id=listing_id, user_id=user_id)
if has_contacted:
messages.error(request, 'You have already made an inquiry for this listing')
return redirect('/listings/'+listing_id)
contact = Contact(listing=listing, listing_id=listing_id, name=name, email=email, phone=phone, message=message, user_id=user_id )
contact.save()
# Send email
# send_mail(
# 'Property Listing Inquiry',
# 'There has been an inquiry for ' + listing + '. Sign into the admin panel for more info',
# '[email protected]',
# [realtor_email, '[email protected]'],
# fail_silently=False
# )
messages.success(request, 'Your request has been submitted, a realtor will get back to you soon')
return redirect('/listings/'+listing_id)