This commit is contained in:
+30
-6
@@ -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:
|
||||
|
||||
@@ -58,6 +58,14 @@
|
||||
<input type="number" class="form-control" id="action_number">
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="auto_unit" class="form-label">Площадка</label>
|
||||
<select class="form-control" id="auto_unit">
|
||||
<option value="">Выберите площадку</option>
|
||||
</select>
|
||||
<div class="form-text">Выберите площадку из списка доступных</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="text" class="form-label required">Текст поста</label>
|
||||
<textarea class="form-control" id="text" rows="4" required></textarea>
|
||||
@@ -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 = '<option value="">Выберите площадку</option>';
|
||||
|
||||
// Добавляем площадки
|
||||
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,
|
||||
|
||||
@@ -1832,6 +1832,10 @@
|
||||
${post.is_poll ? '<span class="badge bg-success">Опрос</span>' : ''}
|
||||
${!post.marked_for_publication && !post.published_in_tg && !post.is_event && !post.is_poll ? '<span class="badge bg-secondary">Никакое</span>' : ''}
|
||||
</div>
|
||||
${post.auto_unit ? `
|
||||
<div class="mb-2">
|
||||
<strong>Площадка:</strong> ${post.auto_unit}
|
||||
</div>` : ''}
|
||||
<div class="mb-2">
|
||||
<strong>ВКонтакте:</strong> <a href="${post.vk_post_url || '#'}" target="_blank" class="text-decoration-none">${post.vk_post_url || 'Не указана'}</a>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user