zmiany w edycji listy przez usera

This commit is contained in:
Mateusz Gruszczyński
2025-08-15 13:12:40 +02:00
parent 1f2fc60683
commit 719735b6d7
3 changed files with 27 additions and 16 deletions

35
app.py
View File

@@ -1527,18 +1527,20 @@ def edit_my_list(list_id):
next_page = request.args.get("next") or request.referrer
if request.method == "POST":
move_to_month = request.form.get("move_to_month")
move_to_month = request.form.get("move_to_month", "")
if move_to_month:
try:
year, month = map(int, move_to_month.split("-"))
new_created_at = datetime(year, month, 1, tzinfo=timezone.utc)
l.created_at = new_created_at
db.session.commit()
flash(
f"Zmieniono datę utworzenia listy na {new_created_at.strftime('%Y-%m-%d')}",
"success",
)
return redirect(next_page or url_for("main_page"))
if l.created_at is None or l.created_at.year != year or l.created_at.month != month:
l.created_at = new_created_at
db.session.commit()
flash(
f"Zmieniono datę utworzenia listy na {new_created_at.strftime('%Y-%m-%d')}",
"success",
)
return redirect(next_page or url_for("main_page"))
except ValueError:
flash("Nieprawidłowy format miesiąca", "danger")
return redirect(next_page or url_for("main_page"))
@@ -1574,10 +1576,14 @@ def edit_my_list(list_id):
db.session.commit()
flash("Zaktualizowano dane listy", "success")
return redirect(next_page or url_for("main_page"))
now = datetime.now()
current_year = now.year
current_month = f"{now.month:02d}"
if l.created_at:
selected_year = l.created_at.year
selected_month = f"{l.created_at.month:02d}"
else:
now = datetime.now()
selected_year = now.year
selected_month = f"{now.month:02d}"
return render_template(
"edit_my_list.html",
@@ -1585,11 +1591,12 @@ def edit_my_list(list_id):
receipts=receipts,
categories=categories,
selected_categories=selected_categories_ids,
current_year=current_year,
current_month=current_month
current_year=selected_year,
current_month=selected_month,
)
@app.route("/delete_user_list/<int:list_id>", methods=["POST"])
@login_required
def delete_user_list(list_id):

View File

@@ -282,4 +282,5 @@
{% endblock %}
{% block scripts %}
<script src="{{ url_for('static_bp.serve_js', filename='select.js') }}"></script>
<script src="{{ url_for('static_bp.serve_js', filename='move_to_month.js') }}"></script>
{% endblock %}

View File

@@ -67,15 +67,18 @@
<div class="d-flex gap-2">
<select id="move_to_month_year" class="form-select bg-dark text-white border-secondary rounded">
{% for y in range(2022, 2031) %}
<option value="{{ y }}" {% if y == (selected_year or current_year) %}selected{% endif %}>{{ y }}</option>
<option value="{{ y }}" {% if y == current_year %}selected{% endif %}>{{ y }}</option>
{% endfor %}
</select>
<select id="move_to_month_month" class="form-select bg-dark text-white border-secondary rounded">
{% for m in range(1, 13) %}
<option value="{{ "%02d"|format(m) }}" {% if "%02d"|format(m) == (selected_month or current_month) %}selected{% endif %}>{{ "%02d"|format(m) }}</option>
<option value="{{ "%02d"|format(m) }}" {% if "%02d"|format(m) == current_month %}selected{% endif %}>
{{ "%02d"|format(m) }}
</option>
{% endfor %}
</select>
</div>
<!-- Ukryte pole, które jest wysyłane do backendu -->
<input type="hidden" id="move_to_month" name="move_to_month" value="{{ list.move_to_month or '' }}">
</div>