-
Notifications
You must be signed in to change notification settings - Fork 0
/
soscommon.py
executable file
·72 lines (63 loc) · 2.21 KB
/
soscommon.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
import os
from google.appengine.ext.webapp import template
import datetime
import time
from datetime import date
from datetime import datetime, date, time, timedelta
import cgi
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
from google.appengine.api import mail
from sosdata import UsersWaitingList2
from sosdata import UsersData
from sosdata import InventoryList
from sosdata import Item
from sosdata import UserPO
from soserrors import SOSException
import sosdata
from google.appengine.api import datastore_errors
import logging
import traceback
# admin code
class AdminRootPage(webapp.RequestHandler):
def get_harvest_date(self, harvest_date):
target_day = 3 # weds
if harvest_date == None or harvest_date == "":
now = date.today()
wd = now.weekday()
day_diff = target_day - wd
if day_diff < 0:
day_diff = day_diff + 6
td = timedelta(day_diff)
harvest_date = now + td
else:
harvest_date = datetime.strptime(harvest_date, "%Y-%m-%d")
return harvest_date
def verify_admin(self):
if users.get_current_user():
self.url = users.create_logout_url("/")
self.url_linktext = 'Logout'
else:
self.url = users.create_login_url("/")
self.url_linktext = 'Login'
raise SOSException("You must login")
if users.is_current_user_admin():
pass
else:
user = users.get_current_user()
msg = user.email() + " is not authorized for this"
raise SOSException(msg)
def error_write(self, ex, tb=None):
template_values = {
'error_msg': str(ex),
'logout_url': self.url,
'url_linktext': self.url_linktext,
}
if tb != None:
msg = tb.format_exc()
logging.error("Error TB %s", (msg))
logging.error("and exception occurred %s", (str(ex)))
path = os.path.join(os.path.dirname(__file__), 'error.html')
self.response.out.write(template.render(path, template_values))