File tree Expand file tree Collapse file tree 2 files changed +24
-6
lines changed Expand file tree Collapse file tree 2 files changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -47,8 +47,22 @@ def index():
4747def urls ():
4848 conn = get_db_connection ()
4949 cur = conn .cursor ()
50- cur .execute ('SELECT * FROM urls ORDER BY created_at DESC' )
50+
51+ # Получение всех URL и последней проверки для каждого URL
52+ cur .execute ('''
53+ SELECT u.id, u.name, u.created_at,
54+ uc.status_code, uc.created_at AS last_check
55+ FROM urls u
56+ LEFT JOIN url_checks uc ON u.id = uc.url_id
57+ WHERE uc.created_at = (
58+ SELECT MAX(created_at)
59+ FROM url_checks
60+ WHERE url_id = u.id
61+ )
62+ ORDER BY u.created_at DESC
63+ ''' )
5164 urls = cur .fetchall ()
65+
5266 cur .close ()
5367 conn .close ()
5468
@@ -61,12 +75,14 @@ def url_detail(url_id):
6175 cursor = conn .cursor ()
6276 cursor .execute ('SELECT * FROM urls WHERE id = %s' , (url_id ,))
6377 url = cursor .fetchone ()
78+ cursor .execute ('SELECT * FROM url_checks WHERE url_id = %s' , (url_id ,))
79+ checks = cursor .fetchall ()
6480 cursor .close ()
6581 conn .close ()
6682 if url is None :
6783 flash ('Сайт не найден.' , 'error' )
6884 return redirect (url_for ('urls' ))
69- return render_template ('result.html' , url = url )
85+ return render_template ('result.html' , url = url , checks = checks )
7086
7187
7288@app .route ('/urls/<int:url_id>/checks' , methods = ['POST' ])
Original file line number Diff line number Diff line change @@ -7,9 +7,10 @@ <h1 class="mb-4">Сайты</h1>
77 < thead class ="table-light ">
88 < tr >
99 < th > ID</ th >
10- < th > Имя</ th >
11- < th > Последняя проверка</ th >
12- < th > Код ответа</ th >
10+ < th > URL</ th >
11+ < th > Дата создания</ th >
12+ < th > Код статуса последней проверки</ th >
13+ < th > Дата последней проверки</ th >
1314 </ tr >
1415 </ thead >
1516 < tbody >
@@ -18,7 +19,8 @@ <h1 class="mb-4">Сайты</h1>
1819 < td > {{ url[0] }}</ td >
1920 < td > < a href ="{{ url_for('url_detail', url_id=url[0]) }} "> {{ url[1] }}</ a > </ td >
2021 < td > {{ url[2] }}</ td >
21- < td > {{ url_id }}</ td >
22+ < td > {{ url[3] if url[3] is not none else 'Нет проверок' }}</ td >
23+ < td > {{ url[4] if url[4] is not none else 'Нет проверок' }}</ td >
2224 </ tr >
2325 {% endfor %}
2426 </ tbody >
You can’t perform that action at this time.
0 commit comments