-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontact.py
261 lines (219 loc) · 7.39 KB
/
contact.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
import os
import webapp2
import jinja2
from google.appengine.ext import ndb
from google.appengine.api import users
from google.appengine.api import mail
template_env = jinja2.Environment(loader=jinja2.FileSystemLoader(os.getcwd()))
class ContactMessages(ndb.Expando):
strMessageReference = ndb.StringProperty()
strNames = ndb.StringProperty()
strEmail = ndb.StringProperty()
strCell = ndb.StringProperty()
strSubject = ndb.StringProperty()
strMessage = ndb.StringProperty()
strMessageExcerpt = ndb.StringProperty()
strDateSubmitted = ndb.DateProperty(auto_now_add=True)
strTimeSubmitted = ndb.TimeProperty(auto_now_add=True)
strResponseSent = ndb.BooleanProperty(default=False)
def readDateSubmitted(self):
try:
strTemp = str(self.strDateSubmitted)
strTemp = strTemp.strip()
return strTemp
except:
return None
def readTimeSubmitted(self):
try:
strTemp = str(self.strTimeSubmitted)
strTemp = strTemp.strip()
return strTemp
except:
return None
def readResposeSent(self):
try:
return self.strResponseSent
except:
return False
def writeResponseSent(self,strinput):
try:
if strinput == True:
self.strResponseSent = True
return True
else:
self.strResponseSent = False
return True
except:
return False
def readNames(self):
try:
strTemp = str(self.strNames)
strTemp = strTemp.strip()
if not(strTemp == None):
return strTemp
else:
return None
except:
return None
def writeNames(self,strinput):
try:
strinput = str(strinput)
strinput = strinput.strip()
if strinput != None:
self.strNames = strinput
return True
else:
return False
except:
return False
def readEmail(self):
try:
strTemp = str(self.strEmail)
strTemp = strTemp.strip()
if not(strTemp == None):
return strTemp
else:
return None
except:
return None
def writeEmail(self,strinput):
try:
strinput = str(strinput)
strinput = strinput.strip()
if strinput != None:
self.strEmail = strinput
return True
else:
return False
except:
return False
def readCell(self):
try:
strTemp = str(self.strCell)
strTemp = strTemp.strip()
if not(strTemp == None):
return strTemp
else:
return None
except:
None
def writeCell(self,strinput):
try:
strinput = str(strinput)
strinput = strinput.strip()
if strinput != None:
self.strCell = strinput
return True
else:
return False
except:
return False
def readSubject(self):
try:
strTemp = str(self.strSubject)
strTemp = strTemp.strip()
if not(strTemp == None):
return strTemp
else:
return None
except:
return None
def writeSubject(self,strinput):
try:
strinput = str(strinput)
strinput = strinput.strip()
if strinput != None:
self.strSubject = strinput
return True
else:
return False
except:
return False
def readMessage(self):
try:
strTemp = str(self.strMessage)
strTemp = strTemp.strip()
if not(strTemp == None):
return strTemp
else:
return None
except:
return None
def writeMessage(self,strinput):
try:
strinput = str(strinput)
strinput = strinput.strip()
if strinput != None:
self.strMessage = strinput
MessageLen = len(self.strMessage)
if MessageLen > 16:
self.strMessageExcerpt = self.strMessage[0:16]
else:
self.strMessageExcerpt = self.strMessage
return True
else:
return False
except:
return False
def sendResponse(self):
try:
sender_address = ('[email protected]')
mail.send_mail(sender_address, self.strEmail, self.strSubject, self.strMessage)
return True
except:
return False
class ContactHandler(webapp2.RequestHandler):
def get(self):
Guser = users.get_current_user()
if Guser:
template = template_env.get_template('templates/contact/contact.html')
context = {}
self.response.write(template.render(context))
def post(self):
try:
Guser = users.get_current_user()
if Guser:
strnames = self.request.get('vstrNames')
strEmail = self.request.get('vstrEmail')
strcell = self.request.get('vstrCell')
strsubject = self.request.get('vstrSubject')
strmessage = self.request.get('vstrMessage')
ContactMessage = ContactMessages()
ContactMessage.strMessageReference = str(Guser.user_id())
ContactMessage.writeNames(strinput=strnames)
ContactMessage.writeEmail(strinput=strEmail)
ContactMessage.writeCell(strinput=strcell)
ContactMessage.writeSubject(strinput=strsubject)
ContactMessage.writeMessage(strinput=strmessage)
ContactMessage.put()
self.response.write("""
Contact Message Submitted Successfully One of our Representatives will get back to you as soon as possible
""")
else:
self.response.write("""
Please Login to Send Messages, [*]
""")
except:
self.response.write("""
Error unable to send contact message
""")
class readContactHandler(webapp2.RequestHandler):
def get(self):
Guser = users.get_current_user()
if Guser:
URL = self.request.url
URLlist = URL.split("/")
strReference = URLlist[len(URLlist) - 1]
findRequest = ContactMessages.query(ContactMessages.strMessageReference == strReference)
thisContactMessagesList = findRequest.fetch()
if len(thisContactMessagesList) > 0:
thisContactMessage = thisContactMessagesList[0]
else:
thisContactMessage = ContactMessages()
template = template_env.get_template('templates/contact/readContact.html')
context = {'thisContactMessage':thisContactMessage}
self.response.write(template.render(context))
app = webapp2.WSGIApplication([
('/contact', ContactHandler),
('/contact/read/.*', readContactHandler)
], debug=True)