This repository has been archived by the owner on Jan 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pages.py
146 lines (108 loc) · 3.53 KB
/
pages.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
"""UI pages."""
import datetime
import logging
from flask import redirect, render_template, request
import humanize
from oauth_dropins.webutil import flask_util, logs, util
from oauth_dropins.webutil.flask_util import error, flash, redirect
from oauth_dropins.webutil.util import json_dumps, json_loads
from app import app, cache
import common
#from models import ...
PAGE_SIZE = 20
logger = logging.getLogger(__name__)
@app.route('/')
@flask_util.cached(cache, datetime.timedelta(days=1))
def front_page():
"""View for the front page."""
return render_template('index.html')
@app.route('/docs')
@flask_util.cached(cache, datetime.timedelta(days=1))
def docs():
"""View for the docs page."""
return render_template('docs.html')
@app.get('/web-site')
@flask_util.cached(cache, datetime.timedelta(days=1))
def enter_web_site():
return render_template('enter_web_site.html')
@app.post('/web-site')
def check_web_site():
url = request.values['url']
domain = util.domain_from_link(url, minimize=False)
if not domain:
error(f'No domain found in {url}')
user = User.get_or_create(domain)
try:
user = user.verify()
except BaseException as e:
if util.is_connection_failure(e):
flash(f"Couldn't connect to {url}")
return render_template('enter_web_site.html')
raise
user.put()
return redirect(f'/user/{user.key.id()}')
@app.get(f'/user/<regex("{common.DOMAIN_RE}"):domain>')
def user(domain):
user = User.get_by_id(domain)
...
@app.get(f'/user/<regex("{common.DOMAIN_RE}"):domain>/feed')
def feed(domain):
...
@app.get('/responses') # deprecated
def recent_deprecated():
return redirect('/recent', code=301)
@app.get('/recent')
def recent():
"""Renders recent activities, with links to logs."""
...
activities, before, after = fetch_activities(query)
return render_template(
'recent.html',
show_domains=True,
logs=logs,
util=util,
**locals(),
)
def fetch_page(query, model_class):
"""Fetches a page of results from a datastore query.
Uses the `before` and `after` query params (if provided; should be ISO8601
timestamps) and the queried model class's `updated` property to identify the
page to fetch.
Populates a `log_url_path` property on each result entity that points to a
its most recent logged request.
Args:
query: :class:`ndb.Query`
model_class: ndb model class
Returns:
(results, new_before, new_after) tuple with:
results: list of query result entities
new_before, new_after: str query param values for `before` and `after`
to fetch the previous and next pages, respectively
"""
...
def fetch_activities(query):
"""Fetches a page of Activity entities from a datastore query.
Wraps :func:`fetch_page` and adds attributes to the returned Activity
entities for rendering in activities.html.
Args:
query: :class:`ndb.Query`
Returns:
(results, new_before, new_after) tuple with:
results: list of Activity entities
new_before, new_after: str query param values for `before` and `after`
to fetch the previous and next pages, respectively
"""
...
@app.get('/stats')
def stats():
def count(kind):
return humanize.intcomma(
KindStat.query(KindStat.kind_name == kind).get().count)
return render_template(
'stats.html',
...,
)
@app.get('/log')
@flask_util.cached(cache, logs.CACHE_TIME)
def log():
return logs.log()