forked from jeztek/imok_appengine
-
Notifications
You must be signed in to change notification settings - Fork 1
/
browsedata.py
63 lines (56 loc) · 2.04 KB
/
browsedata.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
import os, datetime
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template, util
from google.appengine.ext.webapp.util import login_required
from google.appengine.api import mail
# must import template before importing django stuff
import django.core.exceptions
from django.utils import simplejson
import settings
from datastore import *
from imokutils import *
from imokforms import *
from timeutils import *
class MapHandler(RequestHandlerPlus):
@login_required
def get(self):
posts = [p
for p in Post.all().order('-datetime').fetch(100)
if p.hasLocation()]
features = []
now = datetime.datetime.utcnow()
for post in posts:
profile = ImokUser.getProfileForUser(post.user)
phoneNumber = Phone.all().filter('user =', post.user).fetch(1)[0].number
diff = now - post.datetime
if post.isOk:
color='green'
else:
if diff.seconds > 60*60*12:
color = 'yellow'
else:
color = 'red'
feature = dict(lat=post.lat,
lon=post.lon,
positionText=post.positionText,
tags=post.tags(),
message=post.message,
firstName=profile.firstName,
lastName=profile.lastName,
phoneNumber=phoneNumber,
timestamp=formatLocalFromUtc(post.datetime, profile.tz),
color=color,
url=post.permalink(),
)
features.append(feature)
featureText = simplejson.dumps(features)
self.render('map.html', self.getContext(dict(features=featureText,
key=settings.MAP_KEY)))
def main():
application = webapp.WSGIApplication([
('/data/map', MapHandler),
], debug=True)
util.run_wsgi_app(application)
if __name__ == '__main__':
main()