Skip to content

Commit

Permalink
переписаны view
Browse files Browse the repository at this point in the history
  • Loading branch information
KAnanev committed Jul 6, 2023
1 parent d4d6ffc commit 12f34b7
Showing 1 changed file with 10 additions and 24 deletions.
34 changes: 10 additions & 24 deletions page_analyzer/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from flask import Blueprint, render_template, request, flash, redirect, url_for, g


from page_analyzer.db import get_db
from page_analyzer.services.url import URLService

bp = Blueprint('page_analyzer', __name__)
Expand All @@ -17,11 +17,11 @@ def index():
def get_urls():
"""Страница со всеми url."""

db = g.get('my_db')
db = get_db()
url_service = URLService(db=db)
items = url_service.get_all_items()
items = url_service.get_all_urls()

return render_template('urls.html', urls=items)
return render_template('urls.html', items=items)


@bp.post('/urls')
Expand All @@ -30,39 +30,25 @@ def post_url():
добавляет в базу или берет из базы существующий,
редиректит на страницу с url."""

db = g.get('my_db')

url = request.form['url']

db = get_db()
url_service = URLService(db=db)

result = url_service.insert_item(url)
result = url_service.insert_url(url)
flash(*result['message'])

if result['item']:
return redirect(
url_for(
'page_analyzer.get_url',
url_id=result['item']['id']),
)

url_id=result['item'].id),
)
return redirect(url_for('index'))


@bp.get('/urls/<int:url_id>')
def get_url(url_id):
"""Страница c url с выдачей по id."""

db = g.get('my_db')
db = get_db()
url_service = URLService(db=db)
item = url_service.get_item_by_id(url_id)
print(item)
item = url_service.get_json_by_id(url_id)
return render_template('url.html', item=item)


@bp.post('/urls/<int:url_id>/checks')
def check_url(url_id):
db = g.get('my_db')
url_service = URLService(db=db)
message = url_service.insert_item_in_url_checks(url_id)
flash(*message)

0 comments on commit 12f34b7

Please sign in to comment.