forked from snarfed/bridgy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.py
68 lines (50 loc) · 1.79 KB
/
admin.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
"""Renders admin pages for ops and other management tasks.
Currently just /admin/responses, which shows active responses with tasks that
haven't completed yet.
"""
import datetime
import json
import appengine_config
from activitystreams.oauth_dropins.webutil import handlers
import facebook
import googleplus
from models import Response
import instagram
import twitter
import util
from google.appengine.ext import ndb
import webapp2
class ResponsesHandler(handlers.TemplateHandler):
NUM_RESPONSES = 30
def template_file(self):
return 'templates/admin_responses.html'
def template_vars(self):
responses = []
# Find the most recently propagated responses with error URLs
for r in Response.query().order(-Response.updated):
if (len(responses) >= self.NUM_RESPONSES or
r.updated < datetime.datetime.now() - datetime.timedelta(hours=1)):
break
elif not r.error or r.status == 'complete':
continue
# r.source = r.source.get()
r.links = [util.pretty_link(u, new_tab=True) for u in r.error + r.failed]
r.response = json.loads(r.response_json)
r.activities = [json.loads(a) for a in r.activities_json]
responses.append(r)
responses.sort(key=lambda r: (r.source, r.activities, r.response))
return {'responses': responses}
class MarkCompleteHandler(util.Handler):
def post(self):
responses = ndb.get_multi(ndb.Key(urlsafe=u)
for u in self.request.params.getall('key'))
for r in responses:
r.status = 'complete'
ndb.put_multi(responses)
self.redirect('/admin/responses')
application = webapp2.WSGIApplication([
('/admin/responses', ResponsesHandler),
('/admin/mark_complete', MarkCompleteHandler),
], debug=appengine_config.DEBUG)
if __name__ == '__main__':
main()