-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
58 lines (52 loc) · 2.28 KB
/
__init__.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
# prosaicweb
# Copyright (C) 2016 nathaniel smith
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
from . import views
from .models import Base, engine
from .views.auth import login, logout, register
from .app import app, bcrypt
routes = [
# TODO
# because html is dumb and forms can only use post/get, that's all we take
# here. However, within each view function, we check for a _method on a
# POST and treat that as the method. This should really be handled by a
# middleware.
('/', 'index', views.index, {}),
('/generate', 'generate', views.generate, {'methods': ['GET', 'POST']}),
('/corpora', 'corpora', views.corpora, {'methods': ['GET', 'POST',]}),
('/sources', 'sources', views.sources, {'methods': ['GET', 'POST',]}),
('/sources/<source_id>', 'source', views.source,
{'methods': ['GET', 'POST']}),
('/corpora/<corpus_id>', 'corpus', views.corpus,
{'methods': ['GET', 'POST']}),
('/phrases', 'phrases', views.phrases, {'methods': ['POST']}),
('/templates', 'templates', views.templates, {'methods': ['GET', 'POST']}),
('/templates/<template_id>', 'template', views.template,
{'methods': ['GET', 'POST']}),
('/auth/login', 'login', login, {'methods': ['POST']}),
('/auth/register', 'register', register, {'methods':['GET', 'POST']}),
('/auth/logout', 'logout', logout, {}),
]
for [route, name, fn, opts] in routes:
app.add_url_rule(route, name, fn, **opts)
def main() -> None:
if len(sys.argv) > 1 and sys.argv[1] == 'dbinit':
print('initializing prosaic and prosaicweb database state...')
Base.metadata.create_all(bind=engine)
exit(0)
app.run()
if __name__ == '__main__':
main()