video elements shift fix

This commit is contained in:
aneuhmanh 2025-04-08 14:08:21 +03:00
parent 7ce532f765
commit 04e282d097
3 changed files with 6 additions and 41 deletions

43
app.py
View File

@ -129,7 +129,6 @@ def view(content_type, id):
content = Image.query.get_or_404(id)
comments = Comments.query.filter_by(image_id=id).order_by(Comments.comment_date.desc()).all()
# Запись просмотра для изображения
if current_user.is_authenticated:
existing_view = Views.query.filter_by(image_id=id, username=current_user.username).first()
if not existing_view:
@ -327,13 +326,12 @@ async def video_edit(id):
if form.video_thumbnail.data:
thumbnail_file = form.video_thumbnail.data
if allowed_file(thumbnail_file.filename, app.config['ALLOWED_IMAGE_EXTENSIONS']):
# Используем await для получения уникального имени файла
thumbnail_filename = await generate_unique_filename(
app.config['UPLOAD_FOLDER']['thumbnails'], 'webp'
)
thumbnail_path = os.path.join(app.config['UPLOAD_FOLDER']['thumbnails'], thumbnail_filename)
# Сохраняем файл
webp_thumbnail = await convert_to_webp(thumbnail_file)
async with aiofiles.open(thumbnail_path, 'wb') as f:
await f.write(webp_thumbnail.read())
@ -497,11 +495,9 @@ def videos():
if current_user.is_authenticated:
subscriptions = [sub.author_id for sub in Subscription.query.filter_by(user_id=current_user.id).all()]
# Fetch paginated videos based on search query and subscriptions
query = get_content_query(Video, subscriptions, search_query)
pagination = query.paginate(page=page, per_page=10, error_out=False)
# Add views count for each video in the pagination
videos_with_views = []
for video in pagination.items:
views_count = db.session.query(func.count(Views.id)).filter(Views.video_id == video.id).scalar()
@ -510,7 +506,6 @@ def videos():
'views_count': views_count
})
# Fetch the most popular videos (sorted by cookie_votes and views_count)
popular_videos = [
{
'video': video[0],
@ -524,7 +519,6 @@ def videos():
.all()
]
# Fetch the most viewed videos (sorted only by views_count)
most_viewed_videos = [
{
'video': video[0],
@ -538,12 +532,10 @@ def videos():
.all()
]
# Extract tags for filtering
videos_tags = [video.tags for video in Video.query.all() if video.tags]
all_tags = [tag.strip() for tags in videos_tags for tag in tags.split(',')]
sorted_tags = sorted(set(all_tags))
# Fetch user cookies count
user_cookies = 0
if current_user.is_authenticated:
user_cookies_record = Cookies.query.filter_by(username=current_user.username).first()
@ -551,14 +543,14 @@ def videos():
return render_template(
'videos.html',
videos=videos_with_views, # Pass videos with views count
videos=videos_with_views,
pagination=pagination,
user_cookies=user_cookies,
search_query=search_query,
content_type='video',
tags=sorted_tags,
popular_videos=popular_videos, # Pass popular videos with views count
most_viewed_videos=most_viewed_videos # Pass most viewed videos with views count
popular_videos=popular_videos,
most_viewed_videos=most_viewed_videos
)
@ -955,33 +947,6 @@ def terms_of_use():
def publication_rules():
return render_template('publication_rules.html')
@app.route('/shop')
@login_required
def shop():
items = Item.query.filter_by(visible=True).all()
user_cookies = Cookies.query.filter_by(username=current_user.username).first().cookies if Cookies.query.filter_by(username=current_user.username).first() else 0
user_item_ids = {ui.item_id for ui in UserItem.query.filter_by(username=current_user.username).all()}
return render_template('shop.html', items=items, user=current_user, user_cookies=user_cookies, user_item_ids=user_item_ids)
@app.route('/buy_item/<int:item_id>', methods=['POST'])
@login_required
def buy_item(item_id):
username = current_user.username
user_cookies = Cookies.query.filter_by(username=username).first()
item = Item.query.get(item_id)
if not user_cookies or not item or not item.visible or user_cookies.cookies < item.price:
return redirect(url_for('shop'))
if UserItem.query.filter_by(username=username, item_id=item.id).first():
return redirect(url_for('shop'))
user_cookies.cookies -= item.price
db.session.add(UserItem(username=username, item_id=item.id))
db.session.commit()
return redirect(url_for('shop'))
if __name__ == '__main__':
with app.app_context():
db.create_all()

View File

@ -961,5 +961,4 @@ body {
font-family: Inter;
}
}
}
}

View File

@ -124,5 +124,6 @@
<button class="view-more-button"><span class="new-context-button-text">Смотреть Больше</span></button>
</div>
<script src="{{ url_for('static', filename='js/hoverPreview.js') }}"></script>
<script src="{{ url_for('static', filename='js/adjustScrollbar.js') }}"></script>
</body>
</html>