-
Notifications
You must be signed in to change notification settings - Fork 1
/
sermons.py
392 lines (331 loc) · 11.5 KB
/
sermons.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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
#!/usr/bin/env python
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import os
from google.appengine.ext import blobstore
from google.appengine.ext.webapp import blobstore_handlers
import webapp2
import jinja2
from google.appengine.ext import ndb
from google.appengine.api import users
import logging
import math
import datetime
template_env = jinja2.Environment(loader=jinja2.FileSystemLoader(os.getcwd()))
sixtySixBooks = ["Genesis 50",
"Exodus 40",
"Leviticus 27",
"Numbers 36",
"Deuteronomy 34",
"Joshua 24",
"Judges 21",
"Ruth 4",
"1 samuel 31",
"2 samuel 24",
"1 kings 22",
"2 kings 25",
"1 Chronicles 29",
"2 Chronicles 36",
"Ezra 10",
"Nehemiah 13",
"Esther 10",
"Job 42",
"Psalms 150",
"Proverbs 31",
"Ecclesiastes 12",
"Song of Solomon 8",
"Isaiah 66",
"Jeremiah 52",
"Lamentations 5",
"Ezekiel 48",
"Daniel 12",
"Hosea 14",
"Joel 3",
"Amos 9",
"Obadiah 1",
"Jonah 4",
"Micah 7",
"Nahum 3",
"Habakkuk 3",
"Zephaniah 3",
"Haggai 2",
"Zechariah 14",
"Malachi 4",
"Matthew 28",
"Mark 16",
"Luke 24",
"John 21",
"Acts 28",
"Romans 16",
"1 Corinthians 16",
"2 Corinthians 13",
"Galatians 6",
"Ephesians 6",
"Philippians 4",
"Colossians 4",
"1 Thessalonians 5",
"2 Thessalonians 3",
"1 Timothy 6",
"2 Timothy 4",
"Titus 3",
"Philemon 1",
"Hebrews 13",
"James 5",
"1 Peter 5",
"2 Peter 3",
"1 John 5",
"2 John 1",
"3 John 1",
"Jude 1",
"Revelation 22"]
#TODO Consider storing the whole bible using this class
class BibleVerses(ndb.Expando):
strBookID = ndb.StringProperty()
strBookNumber = ndb.StringProperty()
strChapter = ndb.StringProperty()
strBookName = ndb.StringProperty()
strBookContents = ndb.StringProperty()
def writeBookID(self,strinput):
try:
strinput = str(strinput)
if not(strinput == None):
self.strBookID = strinput
return True
else:
return False
except:
return False
def writeBookNumber(self,strinput):
try:
strinput = str(strinput)
if not(strinput == None):
self.strBookNumber = strinput
return True
else:
return False
except:
return False
def writeChapter(self,strinput):
try:
strinput = str(strinput)
if not(strinput == None):
self.strChapter = strinput
return True
else:
return False
except:
return False
def writeBookName(self,strinput):
try:
strinput = str(strinput)
if not(strinput == None):
self.strBookName = strinput
return True
else:
return False
except:
return False
def writeBookContents(self,strinput):
try:
strinput = str(strinput)
if not(strinput == None):
self.strBookContents = strinput
return True
else:
return False
except:
return False
#TODO- Extend Sermons to include YOUTUBE extensions for video sermons, and also consider making it publish on the forums
class Sermons(ndb.Expando):
strMemberID = ndb.StringProperty()
strChurchID = ndb.StringProperty()
strChurchBranchID = ndb.StringProperty()
strTitle = ndb.StringProperty()
strExcerpt = ndb.StringProperty()
strSermon = ndb.StringProperty()
strDateOfDelivery = ndb.DateProperty()
def writeExcerpt(self,strinput):
try:
strinput = str(strinput)
if not(strinput == None):
strLimit = len(strinput)
if strLimit > 256:
strExcerptLen = 256
else:
strExcerptLen = strLimit
#TODO- Actually cut the excetp at the excerpt length
self.strExcerpt = strinput
return True
else:
return False
except:
return False
def writeChurchID(self,strinput):
try:
strinput = str(strinput)
if not(strinput == None):
self.strChurchID = strinput
return True
else:
return False
except:
return False
def writeChurchBranchID(self,strinput):
try:
strinput = str(strinput)
if not(strinput == None):
self.strChurchBranchID = strinput
return True
else:
return False
except:
return False
def writeMemberID(self,strinput):
try:
strinput = str(strinput)
if not(strinput == None):
self.strMemberID = strinput
return True
else:
return False
except:
return False
def writeTitle(self,strinput):
try:
strinput = str(strinput)
if not(strinput == None):
self.strTitle = strinput
return True
else:
return False
except:
return False
def writeSermon(self,strinput):
try:
strinput = str(strinput)
if not(strinput == None):
self.strSermon = strinput
return True
else:
return False
except:
return False
def writeDateOfDelivery(self,strinput):
try:
if isinstance(strinput,datetime.date):
self.strDateOfDelivery = strinput
return True
else:
return False
except:
return False
class SermonsHandler(webapp2.RequestHandler):
def get(self):
Guser = users.get_current_user()
from church import ChurchMember,UserRights
if Guser:
findRequest = ChurchMember.query(ChurchMember.strMemberID == Guser.user_id())
thisChurchMemberList = findRequest.fetch()
if len(thisChurchMemberList) > 0:
thisChurchMember = thisChurchMemberList[0]
else:
thisChurchMember = ChurchMember()
findRequest = UserRights.query(UserRights.strMemberID == Guser.user_id())
thisUserRightsList = findRequest.fetch()
if len(thisUserRightsList) > 0:
thisUserRight = thisUserRightsList[0]
else:
thisUserRight = UserRights()
if thisUserRight.strAdminUser or thisUserRight.strSuperUser:
newBookList = []
for thisBook in sixtySixBooks:
strBookSplit = thisBook.split(" ")
if len(strBookSplit) == 2:
strBookName = strBookSplit[0]
strBookChapter = int(strBookSplit[1])
strBookNumber = 0
elif len(strBookSplit) == 3:
strBookName = strBookSplit[1]
strBookChapter = int(strBookSplit[2])
strBookNumber = int(strBookSplit[0])
# Song of Solomon 8
else:
strBookName = "Song of Solomon"
strBookChapter = 8
strBookNumber = 0
for i in range(strBookChapter):
if strBookNumber == 0:
strBook = strBookName + " " + str(i+1)
else:
strBook = str(strBookNumber) + " " + strBookName + " " +str(i+1)
newBookList.append(strBook)
findRequest = Sermons.query(Sermons.strChurchID == thisChurchMember.strChurchID,Sermons.strChurchBranchID == thisChurchMember.strChurchBranchID)
thisSermonsList = findRequest.fetch()
logging.info("Sixty Six Books : " + str(len(newBookList)))
template = template_env.get_template('templates/sermons/sermons.html')
context = {"sixtySixBooks":newBookList,'thisSermonsList':thisSermonsList}
self.response.write(template.render(context))
else:
template = template_env.get_template('templates/subRestricted.html')
context = {'thisChurchMember':thisChurchMember}
self.response.write(template.render(context))
def post(self):
Guser = users.get_current_user()
from church import ChurchMember, Churches, UserRights
if Guser:
findRequest = ChurchMember.query(ChurchMember.strMemberID == Guser.user_id())
thisChurchMemberList = findRequest.fetch()
if len(thisChurchMemberList) > 0:
thisChurchMember = thisChurchMemberList[0]
else:
thisChurchMember = ChurchMember()
findRequest = UserRights.query(UserRights.strMemberID == Guser.user_id())
thisUserRightsList = findRequest.fetch()
if len(thisUserRightsList) > 0:
thisUserRight = thisUserRightsList[0]
else:
thisUserRight = UserRights()
if thisUserRight.strAdminUser or thisUserRight.strSuperUser:
vstrTitle = self.request.get('vstrTitle')
vstrSermon = self.request.get('vstrSermon')
vstrDateDelivery = self.request.get('vstrDateDelivery')
vstrDateList = vstrDateDelivery.split("-")
vstrYear = vstrDateList[0]
vstrMonth = vstrDateList[1]
vstrDay = vstrDateList[2]
vstrThisDate = datetime.date(year=int(vstrYear),month=int(vstrMonth),day=int(vstrDay))
findRequest = Sermons.query(Sermons.strChurchID == thisChurchMember.strChurchID,Sermons.strChurchBranchID == thisChurchMember.strChurchBranchID,Sermons.strDateOfDelivery ==vstrThisDate)
thisSermonsList = findRequest.fetch()
if len(thisSermonsList) > 0:
thisSermon = thisSermonsList[0]
else:
thisSermon = Sermons()
thisSermon.writeMemberID(strinput=thisChurchMember.strMemberID)
thisSermon.writeChurchID(strinput=thisChurchMember.strChurchID)
thisSermon.writeChurchBranchID(strinput=thisChurchMember.strChurchBranchID)
thisSermon.writeTitle(strinput=vstrTitle)
thisSermon.writeSermon(strinput=vstrSermon)
thisSermon.writeExcerpt(strinput=vstrSermon)
thisSermon.writeDateOfDelivery(strinput=vstrThisDate)
thisSermon.put()
self.response.write("Successfully updated sermons")
else:
template = template_env.get_template('templates/subRestricted.html')
context = {'thisChurchMember':thisChurchMember}
self.response.write(template.render(context))
app = webapp2.WSGIApplication([
('/admin/sermons', SermonsHandler),
], debug=True)