zmiana month na m i poprawka w kolorach paginaci
This commit is contained in:
36
app.py
36
app.py
@@ -939,6 +939,25 @@ def save_pdf_as_webp(file, path):
|
||||
raise ValueError(f"Błąd podczas przetwarzania PDF: {e}")
|
||||
|
||||
|
||||
def get_active_months_query(visible_lists_query=None):
|
||||
if db.engine.name == "sqlite":
|
||||
month_col = func.strftime('%Y-%m', ShoppingList.created_at)
|
||||
else:
|
||||
month_col = func.to_char(ShoppingList.created_at, 'YYYY-MM')
|
||||
|
||||
query = db.session.query(month_col.label("month"))
|
||||
if visible_lists_query is not None:
|
||||
query = query.select_from(visible_lists_query.subquery())
|
||||
|
||||
active_months = (
|
||||
query.filter(ShoppingList.created_at != None)
|
||||
.distinct()
|
||||
.order_by("month")
|
||||
.all()
|
||||
)
|
||||
return [row.month for row in active_months]
|
||||
|
||||
|
||||
############# OCR ###########################
|
||||
|
||||
|
||||
@@ -1317,6 +1336,7 @@ def main_page():
|
||||
.order_by(ShoppingList.created_at.desc())
|
||||
.all()
|
||||
)
|
||||
month_options = get_active_months_query(visible_lists_query)
|
||||
|
||||
all_lists = user_lists + public_lists + archived_lists
|
||||
all_ids = [l.id for l in all_lists]
|
||||
@@ -1378,6 +1398,7 @@ def main_page():
|
||||
archived_lists=archived_lists,
|
||||
now=now,
|
||||
timedelta=timedelta,
|
||||
month_options=month_options
|
||||
)
|
||||
|
||||
|
||||
@@ -2171,20 +2192,7 @@ def admin_panel():
|
||||
all_lists = base_query.all()
|
||||
|
||||
# tylko listy z danych miesięcy
|
||||
if db.engine.name == "sqlite":
|
||||
month_col = func.strftime('%Y-%m', ShoppingList.created_at)
|
||||
else:
|
||||
month_col = func.to_char(ShoppingList.created_at, 'YYYY-MM')
|
||||
|
||||
active_months = (
|
||||
db.session.query(month_col.label("month"))
|
||||
.filter(ShoppingList.created_at != None)
|
||||
.distinct()
|
||||
.order_by("month") # bez min()
|
||||
.all()
|
||||
)
|
||||
|
||||
month_options = [row.month for row in active_months]
|
||||
month_options = get_active_months_query()
|
||||
|
||||
all_ids = [l.id for l in all_lists]
|
||||
|
||||
|
@@ -33,19 +33,19 @@
|
||||
|
||||
{% set month_names = ["styczeń", "luty", "marzec", "kwiecień", "maj", "czerwiec", "lipiec", "sierpień", "wrzesień",
|
||||
"październik", "listopad", "grudzień"] %}
|
||||
{% set selected_month = request.args.get('month') or now.strftime('%Y-%m') %}
|
||||
{% set selected_month = selected_month or now.strftime('%Y-%m') %}
|
||||
|
||||
<!-- Pulpit: zwykły <select> -->
|
||||
<div class="d-none d-md-flex justify-content-end align-items-center flex-wrap gap-2 mb-3">
|
||||
<label for="monthSelect" class="text-white small mb-0">📅 Wybierz miesiąc:</label>
|
||||
<select id="monthSelect" class="form-select form-select-sm bg-dark text-white border-secondary"
|
||||
style="min-width: 180px;">
|
||||
{% for offset in range(0, 6) %}
|
||||
{% set d = (now - timedelta(days=offset * 30)) %}
|
||||
{% set val = d.strftime('%Y-%m') %}
|
||||
<option value="{{ val }}" {% if selected_month==val %}selected{% endif %}>
|
||||
{{ month_names[d.month - 1] }} {{ d.year }}
|
||||
</option>
|
||||
style="min-width: 180px;"
|
||||
onchange="window.location.search='?month='+this.value">
|
||||
{% for m in month_options %}
|
||||
{% set year, month = m.split('-') %}
|
||||
<option value="{{ m }}" {% if selected_month == m %}selected{% endif %}>
|
||||
{{ month_names[month|int - 1] }} {{ year }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
<option value="">Wyświetl wszystko</option>
|
||||
</select>
|
||||
@@ -58,6 +58,7 @@
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
||||
{% if current_user.is_authenticated %}
|
||||
<h3 class="mt-4 d-flex justify-content-between align-items-center flex-wrap">
|
||||
Twoje listy
|
||||
@@ -227,14 +228,16 @@
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="d-grid gap-2">
|
||||
{% for offset in range(0, 6) %}
|
||||
{% set d = (now - timedelta(days=offset * 30)) %}
|
||||
{% set val = d.strftime('%Y-%m') %}
|
||||
<a href="{{ url_for('main_page', month=val) }}" class="btn btn-outline-light">
|
||||
{{ month_names[d.month - 1] }} {{ d.year }}
|
||||
</a>
|
||||
{% for m in month_options %}
|
||||
{% set year, month = m.split('-') %}
|
||||
<a href="{{ url_for('main_page', month=m) }}"
|
||||
class="btn btn-outline-light {% if selected_month == m %}active{% endif %}">
|
||||
{{ month_names[month|int - 1] }} {{ year }}
|
||||
</a>
|
||||
{% endfor %}
|
||||
<a href="{{ url_for('main_page') }}" class="btn btn-outline-secondary">📋 Wyświetl wszystkie</a>
|
||||
<a href="{{ url_for('main_page') }}" class="btn btn-outline-secondary {% if not selected_month %}active{% endif %}">
|
||||
📋 Wyświetl wszystkie
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user