[ВОЛК] редактируемость факта и даты публикации площадки
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
2025-12-25 23:20:23 +03:00
parent 84cc0573e5
commit 008ecbd3ed
2 changed files with 47 additions and 5 deletions
+9 -4
View File
@@ -1306,15 +1306,17 @@ def api_create_category():
data = request.json
with db.conn.cursor() as cursor:
cursor.execute("""
INSERT INTO categories (ID, TITLE, description, image_url, tg_id, marked_for_publication)
VALUES (%s, %s, %s, %s, %s, %s)
INSERT INTO categories (ID, TITLE, description, image_url, tg_id, marked_for_publication, is_tg_published, tg_published_date)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s)
""", (
data.get('id'),
data.get('title', ''),
data.get('description', ''),
data.get('image_url', ''),
data.get('tg_id'),
bool(data.get('marked_for_publication', False))
bool(data.get('marked_for_publication', False)),
bool(data.get('is_tg_published', False)),
data.get('tg_published_date') or None
))
db.conn.commit()
client_ip = get_client_ip()
@@ -1356,7 +1358,8 @@ def api_update_category(category_id):
# Обновляем категорию, включая ID если он изменился
cursor.execute("""
UPDATE categories
SET ID = %s, TITLE = %s, description = %s, image_url = %s, tg_id = %s, marked_for_publication = %s
SET ID = %s, TITLE = %s, description = %s, image_url = %s, tg_id = %s,
marked_for_publication = %s, is_tg_published = %s, tg_published_date = %s
WHERE AUTO_ID = %s
""", (
new_id,
@@ -1365,6 +1368,8 @@ def api_update_category(category_id):
data.get('image_url', ''),
data.get('tg_id'),
bool(data.get('marked_for_publication', False)),
bool(data.get('is_tg_published', False)),
data.get('tg_published_date') or None,
auto_id
))
db.conn.commit()
+38 -1
View File
@@ -122,6 +122,22 @@
<label class="form-check-label" for="marked_for_publication">Отметить для публикации</label>
</div>
<!-- Опубликовано в TG -->
<div class="mb-3 form-check form-switch">
<input class="form-check-input" type="checkbox" id="is_tg_published">
<label class="form-check-label" for="is_tg_published">Опубликовано в TG</label>
</div>
<!-- Дата публикации в TG -->
<div class="d-flex align-items-center mb-3">
<div class="label-narrow">
<label for="tg_published_date" class="form-label">Дата публикации в TG:</label>
</div>
<div style="flex: 0 0 300px;">
<input type="datetime-local" class="form-control" id="tg_published_date">
</div>
</div>
<div class="d-flex justify-content-end mt-4">
<button type="button" class="btn btn-secondary me-2" id="cancel-btn">Отмена</button>
<button type="submit" class="btn btn-primary">
@@ -210,6 +226,17 @@
document.getElementById('image_url').value = category.image_url || '';
document.getElementById('tg_id').value = category.tg_id || '';
document.getElementById('marked_for_publication').checked = category.marked_for_publication || false;
document.getElementById('is_tg_published').checked = category.is_tg_published || false;
// Устанавливаем дату публикации, если она есть
if (category.tg_published_date) {
// Преобразуем ISO дату в формат datetime-local (YYYY-MM-DDTHH:mm)
const date = new Date(category.tg_published_date);
const localDate = new Date(date.getTime() - date.getTimezoneOffset() * 60000);
document.getElementById('tg_published_date').value = localDate.toISOString().slice(0, 16);
} else {
document.getElementById('tg_published_date').value = '';
}
// Показываем предпросмотр изображения, если есть
if (category.image_url) {
@@ -226,13 +253,23 @@
// Сохранение категории
async function saveCategory(categoryId) {
const form = document.getElementById('category-form');
const tgPublishedDateValue = document.getElementById('tg_published_date').value;
let tgPublishedDate = null;
if (tgPublishedDateValue) {
// Преобразуем локальное время в UTC для сохранения в БД
const localDate = new Date(tgPublishedDateValue);
tgPublishedDate = localDate.toISOString().slice(0, 19).replace('T', ' ');
}
const formData = {
id: document.getElementById('id').value.trim(),
title: document.getElementById('title').value.trim(),
description: document.getElementById('description').value.trim(),
image_url: document.getElementById('image_url').value.trim(),
tg_id: document.getElementById('tg_id').value.trim() || null,
marked_for_publication: document.getElementById('marked_for_publication').checked
marked_for_publication: document.getElementById('marked_for_publication').checked,
is_tg_published: document.getElementById('is_tg_published').checked,
tg_published_date: tgPublishedDate
};
if (!formData.id) {