From 877742675631c9d2483e5d8d0610f9658e77ecea Mon Sep 17 00:00:00 2001 From: gitadmin Date: Sun, 12 Oct 2025 18:03:22 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5?= =?UTF-8?q?=D0=B9=D1=81=D0=BD=D1=8B=D0=B5=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=B4=D0=BB=D1=8F=20auto=5Funit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db_edit.py | 36 ++++++++++++++++++++++++++++++------ templates/edit_post.html | 38 ++++++++++++++++++++++++++++++++++++++ templates/index.html | 4 ++++ 3 files changed, 72 insertions(+), 6 deletions(-) diff --git a/db_edit.py b/db_edit.py index 8b85d81..77daadc 100644 --- a/db_edit.py +++ b/db_edit.py @@ -113,7 +113,7 @@ class DatabaseManager: with self.conn.cursor() as cursor: cursor.execute(""" SELECT id, vk_post_id, shortname, text, published_at, - marked_for_publication, published_in_tg, is_event, is_poll, action_number + marked_for_publication, published_in_tg, is_event, is_poll, action_number, auto_unit FROM posts ORDER BY published_at DESC """) @@ -141,6 +141,17 @@ class DatabaseManager: cursor.execute("SELECT * FROM events WHERE id = %s", (event_id,)) return cursor.fetchone() + def get_venues(self): + """Получает список всех уникальных площадок из таблицы events""" + with self.conn.cursor() as cursor: + cursor.execute(""" + SELECT DISTINCT unit_name + FROM events + WHERE unit_name IS NOT NULL AND unit_name != '' + ORDER BY unit_name + """) + return cursor.fetchall() + def toggle_event_publication(self, event_id): with self.conn.cursor() as cursor: cursor.execute(""" @@ -305,8 +316,8 @@ class DatabaseManager: vk_post_id, shortname, text, image_url, vk_post_url, published_at, is_event, is_poll, poll_question, poll_options, poll_multiple, poll_end_date, marked_for_publication, published_in_tg, tg_publication_date, tg_message_id, - tg_poll_id, tg_markpost_id, tg_poll_results, action_number - ) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) + tg_poll_id, tg_markpost_id, tg_poll_results, action_number, auto_unit + ) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) """ values = ( clean_int(data['vk_post_id']), @@ -328,7 +339,8 @@ class DatabaseManager: clean_int(data.get('tg_poll_id', '')), clean_int(data.get('tg_markpost_id', '')), data.get('tg_poll_results', ''), - clean_int(data.get('action_number', '')) + clean_int(data.get('action_number', '')), + data.get('auto_unit', '') ) cursor.execute(query, values) self.conn.commit() @@ -354,7 +366,7 @@ class DatabaseManager: published_at = %s, is_event = %s, is_poll = %s, poll_question = %s, poll_options = %s, poll_multiple = %s, poll_end_date = %s, marked_for_publication = %s, published_in_tg = %s, tg_publication_date = %s, tg_message_id = %s, - tg_poll_id = %s, tg_markpost_id = %s, tg_poll_results = %s, action_number = %s + tg_poll_id = %s, tg_markpost_id = %s, tg_poll_results = %s, action_number = %s, auto_unit = %s WHERE id = %s """ values = ( @@ -378,6 +390,7 @@ class DatabaseManager: clean_int(data.get('tg_markpost_id', '')), data.get('tg_poll_results', ''), clean_int(data.get('action_number', '')), + data.get('auto_unit', ''), post_id ) cursor.execute(query, values) @@ -597,6 +610,16 @@ def logout(): log_event(f"Пользователь {username} вышел из системы с IP {client_ip}") return redirect(url_for('zilant.login')) +@bp.route('/api/venues') +@login_required +def api_venues(): + db = get_db() + try: + venues = db.get_venues() + return jsonify(venues) + finally: + db.close() + @bp.route('/api/posts') @login_required def api_posts(): @@ -615,7 +638,8 @@ def api_posts(): 'published_in_tg': bool(post['published_in_tg']), 'is_event': bool(post['is_event']), 'is_poll': bool(post['is_poll']), - 'action_number': post['action_number'] + 'action_number': post['action_number'], + 'auto_unit': post['auto_unit'] }) return jsonify(posts_list) finally: diff --git a/templates/edit_post.html b/templates/edit_post.html index 4edd934..fb3a79b 100644 --- a/templates/edit_post.html +++ b/templates/edit_post.html @@ -58,6 +58,14 @@ +
+ + +
Выберите площадку из списка доступных
+
+
@@ -221,6 +229,9 @@ } }); + // Загрузка списка площадок + loadVenues(); + // Загрузка данных поста (если редактирование) if (postId) { loadPostData(postId); @@ -233,6 +244,31 @@ }); }); + // Загрузка списка площадок + async function loadVenues() { + try { + const response = await fetch(`${PREFIX}/api/venues`); + if (!response.ok) { + throw new Error('Ошибка загрузки списка площадок'); + } + const venues = await response.json(); + + const select = document.getElementById('auto_unit'); + // Очищаем список, оставляя только первую опцию + select.innerHTML = ''; + + // Добавляем площадки + venues.forEach(venue => { + const option = document.createElement('option'); + option.value = venue.unit_name; + option.textContent = venue.unit_name; + select.appendChild(option); + }); + } catch (error) { + console.error('Ошибка загрузки площадок:', error); + } + } + // Загрузка данных поста async function loadPostData(postId) { try { @@ -247,6 +283,7 @@ document.getElementById('vk_post_id').value = post.vk_post_id || ''; document.getElementById('shortname').value = post.shortname || ''; document.getElementById('action_number').value = post.action_number || ''; + document.getElementById('auto_unit').value = post.auto_unit || ''; document.getElementById('text').value = post.text || ''; document.getElementById('image_url').value = post.image_url || ''; document.getElementById('vk_post_url').value = post.vk_post_url || ''; @@ -313,6 +350,7 @@ vk_post_id: document.getElementById('vk_post_id').value, shortname: document.getElementById('shortname').value, action_number: document.getElementById('action_number').value, + auto_unit: document.getElementById('auto_unit').value, text: document.getElementById('text').value, image_url: document.getElementById('image_url').value, vk_post_url: document.getElementById('vk_post_url').value, diff --git a/templates/index.html b/templates/index.html index c209606..61ca799 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1832,6 +1832,10 @@ ${post.is_poll ? 'Опрос' : ''} ${!post.marked_for_publication && !post.published_in_tg && !post.is_event && !post.is_poll ? 'Никакое' : ''}
+ ${post.auto_unit ? ` +
+ Площадка: ${post.auto_unit} +
` : ''}
ВКонтакте: ${post.vk_post_url || 'Не указана'}