-
Notifications
You must be signed in to change notification settings - Fork 0
/
evictalert.py
78 lines (64 loc) · 2.34 KB
/
evictalert.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
import os
from google.appengine.api import users
from google.appengine.ext import ndb
import jinja2
import webapp2
JINJA_ENVIRONMENT = jinja2.Environment(
loader = jinja2.FileSystemLoader(os.path.dirname(__file__)),
extensions=['jinja2.ext.autoescape'],
autoescape=True)
class District(ndb.Model):
name = ndb.StringProperty()
class Eviction(ndb.Model):
"""Contains eviction info"""
location=ndb.GeoPtProperty()
address = ndb.TextProperty()
postcode = ndb.StringProperty()
district = ndb.KeyProperty(kind=District)
description = ndb.TextProperty()
evictionDateTime = ndb.DateTimeProperty()
lastUpdated = ndb.DateTimeProperty(auto_now=True)
class EvictionAlert(ndb.Model):
"""Model for an eviction alert"""
eviction = ndb.KeyProperty(kind=Eviction)
tweetText = ndb.TextProperty()
# Might need this model to handle permissions etc.
# class EvictAlertUser(ndb.Model):
# user_id = ndb.StringProperty(required=True)
class AlertGroup(ndb.Model):
name = ndb.StringProperty()
class GroupAlerter(ndb.Model):
userid = ndb.StringProperty(required=True)
group = ndb.KeyProperty(required=True, kind=AlertGroup)
class HomePage(webapp2.RequestHandler):
def get(self):
current_user = users.get_current_user()
if current_user:
alert_groups = getUserAlertGroups(current_user.user_id())
template = JINJA_ENVIRONMENT.get_template('templates/grouplist.html')
template_values = {
'logout_url' : users.create_logout_url('/'),
'alert_groups' : alert_groups
}
self.response.write(template.render(template_values))
else:
template = JINJA_ENVIRONMENT.get_template('templates/index.html')
template_values = {
'login_url' : users.create_login_url('/')
}
self.response.write(template.render(template_values))
def getUserAlertGroups(user_id):
user_groups = GroupAlerter.query(GroupAlerter.userid==user_id)
alert_groups = []
for user_group in user_groups:
alert_group = AlertGroup.get_by_id(user_group.group.id())
alert_groups.append(alert_group)
return alert_groups
# hacky code to put stuff into datastore
# tg = AlertGroup(name='testgroup1', id='testgroup1')
# tgk = tg.put()
# tga = GroupAlerter(userid='185804764220139124118', group='testgroup1')
# tga.put()
application = webapp2.WSGIApplication([
('/', HomePage),
], debug=True)