-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
163 lines (143 loc) · 8.88 KB
/
main.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
# -*- coding: utf-8 -*-
import webapp2
import jinja2
import os
from webapp2_extras import routes
from models import Commune
from handlers.static_pages import ViewServiceHandler, PublicExportHandler, AboutHandler, ContactHandler, MainHandler, SearchHandler, ServicesHandler, SuggestServicesHandler, ManualHandler, RecordHandler, LanguageHandler, PublicRecordHandler
from handlers.admin import AdminServiceViewHandler, SearchRecordHandler, IndexHandler, UsersIndexHandler, NewUserHandler, EmailEndpointHandler, DashboardHandler, DashboardItemHandler, UserDashboardHandler, UserDashboardItemHandler, AdminIFormBuilderHandler, AdminRecordHandler, AdminViewRecordHandler, EditRecordHandler, NewServiceHandler, NewProgramHandler, NewRecordHandler, ExportHandler
from handlers.users import EditHandler, LoginHandler, LogoutHandler, ProfileHandler, ResetPasswordHandler, SetPasswordHandler, DeleteHandler
from handlers.api.users import ApiLoginHandler
from handlers.admin.organizations import AdminRecordDashboardHandler, AdminOrgIndexHandler, AdminOrgNewHandler, AdminOrgEditHandler, AdminOrgDeleteHandler, AdminOrgDashboardHandler
from handlers.admin.programs import AdminProgramIndexHandler, AdminProgramNewHandler, AdminProgramEditHandler, AdminProgramDeleteHandler, AdminProgramDashboardHandler
from handlers.admin.services import AdminServiceIndexHandler, AdminServiceNewHandler, AdminServiceEditHandler, AdminServiceDeleteHandler, AdminServiceDashboardHandler
from handlers.schema_updates import UpdateHandler
from handlers.site_test import SiteTest
from helpers import QueryHandler
config = {}
config['webapp2_extras.sessions'] = {
'secret_key': 'LK@#J$LK@#J$@#IUR(E*R)WE(FIUAFOJOWE%IUQ#)(%*TU$OIJQTJRWKGUWRE(T*W)$#(*%W$#%OIJRWOIEUWR"0t9*',
}
class Route(routes.RedirectRoute):
def __init__(self, *args, **kwargs):
# This causes a URL to redirect to its canonical version without a slash.
# See http://webapp-improved.appspot.com/api/webapp2_extras/routes.html#webapp2_extras.routes.RedirectRoute
if 'strict_slash' not in kwargs:
kwargs['strict_slash'] = True
routes.RedirectRoute.__init__(self, *args, **kwargs)
def handle_404(request, response, exception):
response.write('Page not found')
# if request.url[-1:] == "/":
# redirect_url = request.url[:-1]
# webapp2.RequestHandler.redirect(webapp2.RequestHandler, "e")
# return
response.set_status(404)
def handle_500(request, response, exception):
response.write('Oops! I could swear this page was here!')
response.set_status(500)
app = webapp2.WSGIApplication([
(r'/', MainHandler.MainHandler, "home"),
(r'/about', AboutHandler.AboutHandler, "about"),
(r'/search', SearchHandler.SearchHandler, "search"),
(r'/contact', ContactHandler.ContactHandler, "contact"),
(r'/suggest_services', SuggestServicesHandler.SuggestServicesHandler, "suggest_services"),
(r'/mental_illness_services', ServicesHandler.ServicesHandler, "mental_illness_services"),
(r'/manual', ManualHandler.ManualHandler, "manual"),
(r'/admin', IndexHandler.IndexHandler, "admin"),
#('/admin/iformbuilder_task', AdminIFormBuilderHandler.AdminIFormBuilderHandler),
(r'/admin/searches', SearchRecordHandler.SearchRecordHandler, "admin_searches"),
(r'/admin/users', UsersIndexHandler.UsersIndexHandler, "admin_users"),
(r'/admin/users/new', NewUserHandler.NewUserHandler, "admin_users_new" ),
(r'/admin/users/dashboard', UserDashboardHandler.UserDashboardHandler, "admin_user_dashboard"),
(r'/admin/users_dashboard/([^/]+)', UserDashboardItemHandler.UserDashboardItemHandler, "admin_user_dashboard_item"),
(r'/admin/users/([^/]+)', EmailEndpointHandler.EmailEndpointHandler, "users_item"),
(r'/admin/dashboard', DashboardHandler.DashboardHandler, "admin_dashboard"),
(r'/admin/dashboard/([^/]+)', DashboardItemHandler.DashboardItemHandler, "admin_dashboard_item"),
# ('/admin/organizations', AdminOrgIndexHandler.AdminOrgIndexHandler),
(r'/admin/records', AdminRecordHandler.AdminRecordHandler, "admin_records"),
(r'/admin/records/dashboard', AdminRecordDashboardHandler.AdminRecordDashboardHandler, "admin_records_dashboard"),
(r'/admin/records/([^/]+)', AdminViewRecordHandler.AdminViewRecordHandler, "admin_records_item"),
# ('/admin/organizations/new', AdminOrgNewHandler.AdminOrgNewHandler),
('/records/([^/]+)/edit', AdminOrgEditHandler.AdminOrgEditHandler),
('/organizations/([^/]+)/delete', AdminOrgDeleteHandler.AdminOrgDeleteHandler),
# ('/admin/organizations/dashboard', AdminOrgDashboardHandler.AdminOrgDashboardHandler),
# (r'/admin/programs', AdminProgramIndexHandler.AdminProgramIndexHandler, "admin_programs"),
(r'/admin/programs/new', AdminProgramNewHandler.AdminProgramNewHandler, "admin_programs_new"),
(r'/programs/([^/]+)/edit', AdminProgramEditHandler.AdminProgramEditHandler, "programs_edit"),
(r'/programs/([^/]+)/delete', AdminProgramDeleteHandler.AdminProgramDeleteHandler, "programs_delete"),
(r'/admin/programs/dashboard', AdminProgramDashboardHandler.AdminProgramDashboardHandler, "programs_dashboard"),
(r'/admin/services/dashboard', AdminServiceDashboardHandler.AdminServiceDashboardHandler),
# ('/admin/services', AdminServiceIndexHandler.AdminServiceIndexHandler),
(r'/admin/services/([^/]+)', AdminServiceViewHandler.AdminServiceViewHandler, "admin_service_view"),
# ('/admin/services/new', AdminServiceNewHandler.AdminServiceNewHandler),
('/services/([^/]+)/edit', AdminServiceEditHandler.AdminServiceEditHandler),
('/services/([^/]+)/delete', AdminServiceDeleteHandler.AdminServiceDeleteHandler),
(r'/users/([^/]+)/edit', EditHandler.EditHandler, "users_edit"),
(r'/records/new', NewRecordHandler.NewRecordHandler, "records_new"),
(r'/programs/new', NewProgramHandler.NewProgramHandler, "programs_new"),
(r'/services/new', NewServiceHandler.NewServiceHandler, "services_new"),
(r'/services/([^/]+)', ViewServiceHandler.ViewServiceHandler, "services_view"),
# ('/records/([^/]+)', RecordHandler.RecordHandler),
(r'/users/([^/]+)/delete', DeleteHandler.DeleteHandler, "users_delete"),
(r'/users/login', LoginHandler.LoginHandler, "users_login"),
(r'/users/logout', LogoutHandler.LogoutHandler, "users_logout"),
(r'/users/profile', ProfileHandler.ProfileHandler, "users_profile"),
(r'/users/reset_password', ResetPasswordHandler.ResetPasswordHandler, "users_reset_password"),
(r'/users/set_password/([^/]+)', SetPasswordHandler.SetPasswordHandler, "users_set_password"),
(r'/language', LanguageHandler.LanguageHandler, "language"),
# (r'/records/([^/]+)/edit', EditRecordHandler.EditRecordHandler, "records_edit"),
# (r'/update_handler', UpdateHandler.UpdateHandler, "update_handler"),
(r'/admin/export/([^/]+)', ExportHandler.ExportHandler, "admin_export_csv"),
(r'/isitlive', SiteTest.SiteTest, "isitlive"),
(r"/records/([^/]+)", PublicRecordHandler.PublicRecordHandler, "records_view"),
(r"/export/([^/]+)", PublicExportHandler.PublicExportHandler, "public_export_handler")
#('/api/users/login', ApiLoginHandler.ApiLoginHandler),
], config=config, debug=True)
app.error_handlers[404] = handle_404
# app.error_handlers[500] = handle_500
# def update_gps():
# sql_statement = "SELECT * FROM organization WHERE latitude IS NULL"
# records = QueryHandler.execute_query(sql_statement)
# # raise Exception(len(records))
# others = []
# # for r in records:
# # print others.append(r[9])
# # raise Exception(others)
# for r in records:
# try:
# first_index = r[9].index(",")
# longitude = r[9][:first_index]
# second_index = r[9][first_index + 1:].index(",")
# latitude = r[9][first_index + 1:second_index + first_index + 1]
# record_id = r[0]
# # raise Exception(latitude, longitude)
# # update lat and long and save
# sql_statement = """
# UPDATE `organization` SET
# `latitude` = "{0}",
# `longitude` = "{1}"
# WHERE `id` = "{2}"
# LIMIT 1;
# """.format(latitude, longitude, record_id)
# # raise Exception(sql_statement)
# QueryHandler.execute_query(sql_statement, True)
# except:
# others.append(r)
# for r in others:
# try:
# first_index = r[9].index(":")
# latitude = r[9][:first_index]
# longitude = r[9][first_index + 1:]
# record_id = r[0]
# sql_statement = """
# UPDATE `organization` SET
# `latitude` = "{0}",
# `longitude` = "{1}"
# WHERE `id` = "{2}"
# LIMIT 1;
# """.format(latitude, longitude, record_id)
# # raise Exception(sql_statement)
# QueryHandler.execute_query(sql_statement, True)
# except:
# pass
# update_gps()