From 1b996c0543384748d03961edd6a5f6742d7fc017 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Gruszczy=C5=84ski?= Date: Mon, 13 Jul 2026 14:34:32 +0200 Subject: [PATCH] ulubionetacje --- app/api.py | 13 ++++++ app/main.py | 6 ++- app/templates/admin_companies.html | 2 +- app/templates/fuel_form.html | 2 +- app/templates/stations.html | 3 +- make_zip.py | 70 ++++++++++++++++++++++++++++++ 6 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 make_zip.py diff --git a/app/api.py b/app/api.py index 2c081c1..d2a5b05 100644 --- a/app/api.py +++ b/app/api.py @@ -402,6 +402,19 @@ def company_favorites(company_id): c.favorite_stations=FuelStationCompany.query.filter(FuelStationCompany.id.in_(ids),FuelStationCompany.active.is_(True)).all() if ids else [] db.session.commit();socketio.emit('app_changed',{'resource':'company_favorites','company_id':c.id});return response(message='Zapisano ulubione stacje firmy') +@api.put('/companies//allowed-stations') +@role_required('boss','admin') +def company_allowed_stations(company_id): + company=CompanySettings.query.get_or_404(company_id) + if current_user.role=='boss' and current_user.company_id!=company.id:return fail('Brak uprawnień',403) + d=payload();ids=request.form.getlist('station_ids') if request.form else d.get('station_ids',[]);ids=[ids] if isinstance(ids,(str,int)) else ids + try: ids=[int(x) for x in ids] + except Exception:return fail('Nieprawidłowa lista stacji') + company.allowed_stations=FuelStationCompany.query.filter(FuelStationCompany.id.in_(ids),FuelStationCompany.active.is_(True)).all() if ids else [] + db.session.commit();socketio.emit('app_changed',{'resource':'allowed_stations','company_id':company.id}) + message='Wszystkie aktywne stacje są dozwolone' if not ids else 'Zapisano zamkniętą listę dozwolonych stacji' + return response([station_dict(x) for x in company.allowed_stations],message) + @api.post('/companies//favorite-stations//toggle') @role_required('boss','admin') def company_favorite_toggle(company_id,station_id): diff --git a/app/main.py b/app/main.py index 82e9c4a..5358d2c 100644 --- a/app/main.py +++ b/app/main.py @@ -172,9 +172,11 @@ def fuel(): if not favorites: favorites=sorted(stations,key=lambda x:(-x.station_count,x.company_name.lower()))[:10];favorite_scope="default" favorites=sorted(favorites,key=lambda x:(-x.station_count,x.display_name.lower())) favorite_ids={x.id for x in favorites} + top_stations=sorted((x for x in stations if x.id not in favorite_ids),key=lambda x:(-x.station_count,x.display_name.lower()))[:10] + proposed_ids=favorite_ids|{x.id for x in top_stations} favorite_catalog=sorted(stations,key=lambda x:(-x.station_count,x.display_name.lower())) - other_stations=sorted((x for x in stations if x.id not in favorite_ids),key=lambda x:x.display_name.lower()) - return render_template("fuel_form.html", vehicles=vehicles, stations=stations, favorite_stations=favorites, favorite_catalog=favorite_catalog, other_stations=other_stations, now=datetime.now().strftime("%Y-%m-%dT%H:%M"), restricted=bool(allowed), favorite_scope=favorite_scope, company=settings, fuel_cards=FuelCard.query.filter_by(active=True,company_id=settings.id).order_by(FuelCard.name).all()) + other_stations=sorted((x for x in stations if x.id not in proposed_ids),key=lambda x:x.display_name.lower()) + return render_template("fuel_form.html", vehicles=vehicles, stations=stations, favorite_stations=favorites, top_stations=top_stations, favorite_catalog=favorite_catalog, other_stations=other_stations, now=datetime.now().strftime("%Y-%m-%dT%H:%M"), restricted=bool(allowed), favorite_scope=favorite_scope, company=settings, fuel_cards=FuelCard.query.filter_by(active=True,company_id=settings.id).order_by(FuelCard.name).all()) @main.route("/api/orlen-price") @login_required diff --git a/app/templates/admin_companies.html b/app/templates/admin_companies.html index 206ef3a..48ccabc 100644 --- a/app/templates/admin_companies.html +++ b/app/templates/admin_companies.html @@ -54,7 +54,7 @@

Ulubione stacje firmy

Do 25 stacji. Pusta lista oznacza 10 największych sieci w Polsce.

- + {% else %}
Dodaj lub wybierz firmę.
{% endif %} diff --git a/app/templates/fuel_form.html b/app/templates/fuel_form.html index 894452d..3ff3731 100644 --- a/app/templates/fuel_form.html +++ b/app/templates/fuel_form.html @@ -1 +1 @@ -{% extends 'base.html' %}{% block content %}

Nowe tankowanie

Najpierw pokazujemy maksymalnie 10 ulubionych sieci. {% if restricted %} · firma ograniczyła listę do dozwolonych sieci{% endif %}.
Cena Orlen zostanie pobrana automatycznie.
{% endblock %}{% block scripts %}{% endblock %} +{% extends 'base.html' %}{% block content %}

Nowe tankowanie

Najpierw pokazujemy ulubione oraz 10 największych pozostałych sieci. {% if restricted %} · firma ograniczyła listę do dozwolonych sieci{% endif %}.
Cena Orlen zostanie pobrana automatycznie.
{% endblock %}{% block scripts %}{% endblock %} diff --git a/app/templates/stations.html b/app/templates/stations.html index 34fe5ec..eea3d43 100644 --- a/app/templates/stations.html +++ b/app/templates/stations.html @@ -9,12 +9,13 @@
{% endif %}
+

Dostęp do stacji

{% if allowed_ids %}

Aktywna jest lista zamknięta: dozwolonych stacji: {{ allowed_ids|length }}. Niezaznaczone stacje nie pojawią się w formularzu tankowania.

{% else %}

Wszystkie aktywne stacje są dozwolone. Ulubione wpływają tylko na kolejność propozycji.

{% endif %}
{% if allowed_ids %}
{% endif %}
{% for s in station_page.items %} - +{% else %}{% endfor %}
Stacja / firmaPunktyPaliwaUstawieniaWarunki kart
{% if s.station_count > 1 %}{% else %}{{s.display_name}}{% endif %}{% if s.company_name != s.display_name %}
{{s.company_name}}
{% endif %}
NIP: {{s.nip or '—'}} · REGON: {{s.regon or '—'}}
{{s.station_count}}
{% if s.has_petrol %}benzyna{% endif %}{% if s.has_diesel %}diesel{% endif %}{% if s.has_lpg %}LPG{% endif %}
{% if current_user.role == 'admin' %}
{% else %}{% endif %}
{% if current_user.role == 'admin' %}
{% else %}{% endif %}
{% for card in fuel_cards %}{% set rule=card_rules.get((card.id,s.id)) %}
{{card.name}}
{% else %}Najpierw dodaj kartę w ustawieniach firmy.{% endfor %}
Brak firm. Pobierz katalog z URE.
diff --git a/make_zip.py b/make_zip.py new file mode 100644 index 0000000..a8a050b --- /dev/null +++ b/make_zip.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python3 +import os +import sys +import zipfile +import subprocess +from pathlib import Path + + +def run_git_command(args, repo_path: Path) -> bytes: + result = subprocess.run( + ["git", *args], + cwd=repo_path, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + check=True, + ) + return result.stdout + + +def get_files_to_archive(repo_path: Path) -> list[str]: + output = run_git_command( + ["ls-files", "--cached", "--others", "--exclude-standard", "-z"], + repo_path, + ) + files = output.decode("utf-8", errors="surrogateescape").split("\0") + return [f for f in files if f] + + +def make_zip(repo_path: Path, output_zip: Path) -> None: + files = get_files_to_archive(repo_path) + + output_zip = output_zip.resolve() + if output_zip.exists(): + output_zip.unlink() + + with zipfile.ZipFile(output_zip, "w", compression=zipfile.ZIP_DEFLATED) as zf: + for rel_path in files: + abs_path = repo_path / rel_path + + if not abs_path.exists(): + continue + + if abs_path.resolve() == output_zip: + continue + + zf.write(abs_path, arcname=rel_path) + + print(f"Created: {output_zip}") + print(f"Added files: {len(files)}") + + +def main(): + repo_path = Path.cwd() + + if len(sys.argv) > 1: + output_zip = Path(sys.argv[1]) + else: + output_zip = repo_path / f"{repo_path.name}.zip" + + try: + run_git_command(["rev-parse", "--show-toplevel"], repo_path) + except subprocess.CalledProcessError: + print("Error: this directory is not a Git repository.", file=sys.stderr) + sys.exit(1) + + make_zip(repo_path, output_zip) + + +if __name__ == "__main__": + main() \ No newline at end of file