-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
92 lines (76 loc) · 3.48 KB
/
app.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
#!/usr/bin/env python3
'''
Flask APP
MIT License
Copyright (c) 2021 Leboncoin
Written by Yann Faure ([email protected])
'''
from flask import Flask, request, render_template
from flask_bootstrap import Bootstrap
from classes.database import Database
database = Database('database.db')
database.init_databases()
app = Flask(__name__)
@app.route('/', methods=['GET'])
def root():
'''root'''
return render_template('index.html')
@app.route('/trademarks', methods=['GET'])
def trademarks():
'''trademarks'''
return render_template('trademarks.html', trademarks=database.get_trademarks())
@app.route('/trademarks/add', methods=['POST'])
def trademarks_add():
'''trademarks add'''
database.insert_trademark(request.form['trademark'])
return render_template('trademarks.html', trademarks=database.get_trademarks())
@app.route('/trademarks/edit/<int:id_trademark>', methods=['GET'])
def trademarks_edit(id_trademark):
'''trademarks edit'''
trademarks_all = database.get_trademarks()
trademark_edit = database.get_trademark_by_id(id_trademark)
return render_template('trademarks.html',
trademarks=trademarks_all, trademark_edit=trademark_edit)
@app.route('/trademarks/edit/<int:id_trademark>', methods=['POST'])
def trademarks_edit_id(id_trademark):
'''trademarks edit id'''
database.update_trademark(id_trademark, request.form['trademark'])
trademarks_all = database.get_trademarks()
trademark_edit = database.get_trademark_by_id(id_trademark)
return render_template('trademarks.html',
trademarks=trademarks_all, trademark_edit=trademark_edit)
@app.route('/filters/edit/<int:id_trademark>', methods=['GET'])
def filters(id_trademark):
'''filters by trademark id'''
trademark = database.get_trademark_by_id(id_trademark)
keywords = database.get_keywords_by_trademark_id(id_trademark)
return render_template('filters.html', trademark=trademark, keywords=keywords)
@app.route('/trademark/<int:id_trademark>/keywords/add', methods=['POST'])
def keywords_add(id_trademark):
'''keywords add'''
database.insert_keyword(id_trademark, request.form['keyword'])
trademark = database.get_trademark_by_id(id_trademark)
keywords = database.get_keywords_by_trademark_id(id_trademark)
return render_template('filters.html', trademark=trademark, keywords=keywords)
@app.route('/trademark/<int:id_trademark>/keywords/edit/<int:id_keyword>', methods=['GET'])
def keywords_edit(id_trademark, id_keyword):
'''keywords edit'''
trademark = database.get_trademark_by_id(id_trademark)
keywords = database.get_keywords_by_trademark_id(id_trademark)
keyword_edit = database.get_keyword_by_id(id_keyword)
return render_template('filters.html',
trademark=trademark, keywords=keywords, keyword_edit=keyword_edit)
@app.route('/trademark/<int:id_trademark>/keywords/edit/<int:id_keyword>', methods=['POST'])
def keywords_edit_id(id_trademark, id_keyword):
'''keyword edit id'''
database.update_keyword(id_keyword, request.form['keyword'])
trademark = database.get_trademark_by_id(id_trademark)
keywords = database.get_keywords_by_trademark_id(id_trademark)
keyword_edit = database.get_keyword_by_id(id_keyword)
return render_template('filters.html',
trademark=trademark, keywords=keywords, keyword_edit=keyword_edit)
@app.route('/logs', methods=['GET'])
def logs():
'''logs'''
return render_template('logs.html', twitterlogs=database.get_twitter_logs())
Bootstrap(app)