-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutone.py
175 lines (137 loc) · 5.2 KB
/
butone.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
import os
import logging
from google.appengine.ext.webapp import template
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
"""Load custom Django template filters"""
webapp.template.register_template_library('butone.customfilters')
class Geotag(db.Model):
user = db.StringProperty()
tag = db.StringProperty()
lat = db.StringProperty()
lon = db.StringProperty()
date = db.DateTimeProperty(auto_now_add=True)
class MainPage(webapp.RequestHandler):
def get(self):
geotags_query = Geotag.all()
geotags = []
users = []
tags = []
for geotag in geotags_query:
user = geotag.user
tag = geotag.tag
if (user not in users): users.append(user)
if (tag not in tags): tags.append(tag)
users.sort()
tags.sort()
template_values = {
'geotags': geotags,
'users': users,
'tags': tags
}
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))
class Upload(webapp.RequestHandler):
def post(self):
lat = self.request.get("lat")
lon = self.request.get("lon")
tag = self.request.get("tag")
user = self.request.get("username")
geotag = Geotag()
geotag.lat = lat;
geotag.lon = lon;
geotag.tag = tag;
geotag.user = user;
geotag.put()
class BrowseHandler(webapp.RequestHandler):
def get(self, filterName, filterValue):
filterName = filterName.replace("%20"," ");
filterValue = filterValue.replace("%20", " ");
# Prepare the query based on the groups of the regex
geotags_query = Geotag.all()
geotags_query.filter(filterName + " =", filterValue)
geotags_query.order("date")
# Prepare the data to pass to the template
geotags = [geotag for geotag in geotags_query]
displayData = []
dataType = ""
mapsQuery = ""
# logging.debug("filterName: %s, filterValue: %s", filterName, filterValue)
if (filterName == "user"):
tags = list(set([geotag.tag for geotag in geotags]))
dataType = "tag"
displayData = [[geotag for geotag in geotags if geotag.tag == tag] for tag in tags]
mapsQuery = ""
elif (filterName == "tag"):
users = list(set([geotag.user for geotag in geotags]))
dataType = "user"
displayData = [[geotag for geotag in geotags if geotag.user == user] for user in users]
template_values = { 'geotags': geotags,
'filterName': filterName,
'filterValue': filterValue,
'dataType': dataType,
'displayData': displayData }
path = os.path.join(os.path.dirname(__file__), 'browse.html')
self.response.out.write(template.render(path, template_values))
class AboutPage(webapp.RequestHandler):
def get(self):
template_values = {
}
path = os.path.join(os.path.dirname(__file__), 'about.html')
self.response.out.write(template.render(path, template_values))
class DownloadPage(webapp.RequestHandler):
def get(self):
template_values = {
}
path = os.path.join(os.path.dirname(__file__), 'download.html')
self.response.out.write(template.render(path, template_values))
class CreateMap(webapp.RequestHandler):
def get(self, user, tag):
a = 1
class CreateKml(webapp.RequestHandler):
def get(self, user, tag):
# Prepare the query based on the groups of the regex
geotags_query = Geotag.all()
if (user != "" and user != "null"):
logging.debug('The user is %s',user)
geotags_query.filter("user =", user.replace("_"," "))
if (tag != ""):
geotags_query.filter("tag =", tag.replace("_"," "))
geotags = [geotag for geotag in geotags_query]
template_values = {'geotags': geotags}
self.response.headers['Content-Type'] = 'application/vnd.google-earth.kml+xml'
path = os.path.join(os.path.dirname(__file__), 'tagmap.kml')
self.response.out.write(template.render(path, template_values))
class TaxiApp(webapp.RequestHandler):
def get(self):
template_values = {
}
path = os.path.join(os.path.dirname(__file__), 'taxiapp.html')
self.response.out.write(template.render(path, template_values))
class Generate(webapp.RequestHandler):
def get(self):
geotag = Geotag()
geotag.lat = "5";
geotag.lon = "5";
geotag.tag = "Debug Tag";
geotag.user = "Debug User";
geotag.put()
application = webapp.WSGIApplication(
[('/butone/', MainPage),
('/butone/upload', Upload),
(r'/butone/browse/(.*)/(.*)', BrowseHandler),
('/butone/about', AboutPage),
(r'/butone/map/(.*)/(.*)', CreateMap),
(r'/butone/kml/(.*)/(.*)', CreateKml),
('/butone/generate', Generate),
('/butone/download', DownloadPage),
('/butone/taxiapp', TaxiApp)
],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()