uprawnienia do stacji i usuwanie firm
This commit is contained in:
+16
-13
@@ -365,6 +365,22 @@ def stations():
|
||||
page = request.args.get("page", 1, type=int)
|
||||
sort = request.args.get("sort", "company_name")
|
||||
direction = request.args.get("direction", "asc")
|
||||
companies_q = CompanySettings.query.filter_by(active=True).order_by(CompanySettings.name.asc())
|
||||
if current_user.role == "boss":
|
||||
companies_q = companies_q.filter_by(id=current_user.company_id)
|
||||
companies = companies_q.all()
|
||||
requested_company_id = request.args.get("company_id", type=int)
|
||||
if current_user.role == "boss":
|
||||
company = current_user.company
|
||||
elif requested_company_id is None:
|
||||
return render_template("stations_company_select.html", companies=companies)
|
||||
else:
|
||||
company = db.session.get(CompanySettings, requested_company_id)
|
||||
if company not in companies:
|
||||
abort(404, description="Nie znaleziono aktywnej firmy")
|
||||
if company is None:
|
||||
abort(404, description="Brak aktywnej firmy do konfiguracji")
|
||||
|
||||
query = FuelStationCompany.query.filter_by(active=True)
|
||||
if q:
|
||||
terms = [term for term in q.split() if term]
|
||||
@@ -375,19 +391,6 @@ def stations():
|
||||
column = columns.get(sort, FuelStationCompany.company_name)
|
||||
query = query.order_by(column.desc() if direction == "desc" else column.asc(), FuelStationCompany.brand_name.asc())
|
||||
station_page = query.paginate(page=page, per_page=30, error_out=False)
|
||||
companies_q = CompanySettings.query.filter_by(active=True).order_by(CompanySettings.name.asc())
|
||||
if current_user.role == "boss":
|
||||
companies_q = companies_q.filter_by(id=current_user.company_id)
|
||||
companies = companies_q.all()
|
||||
requested_company_id = request.args.get("company_id", type=int)
|
||||
if current_user.role == "boss":
|
||||
company = current_user.company
|
||||
else:
|
||||
company = db.session.get(CompanySettings, requested_company_id) if requested_company_id else None
|
||||
if company not in companies:
|
||||
company = companies[0] if companies else None
|
||||
if company is None:
|
||||
abort(404, description="Brak aktywnej firmy do konfiguracji")
|
||||
cards_q=FuelCard.query.filter_by(active=True, company_id=company.id)
|
||||
cards=cards_q.order_by(FuelCard.name).all()
|
||||
rules={(r.fuel_card_id,r.station_company_id):r for r in FuelCardStationRule.query.filter(FuelCardStationRule.fuel_card_id.in_([c.id for c in cards] or [-1])).all()}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
{% extends 'base.html' %}
|
||||
{% block title %}Wybierz firmę – stacje paliw{% endblock %}
|
||||
{% block content %}
|
||||
<div class="d-flex flex-column flex-lg-row justify-content-between gap-3 align-items-lg-end mb-4">
|
||||
<div>
|
||||
<h1 class="h2 mb-1">Predefiniowane stacje paliw</h1>
|
||||
<p class="text-body-secondary mb-0">Wybierz firmę, dla której chcesz skonfigurować dostęp, ulubione stacje i warunki kart.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<div class="card-body p-4">
|
||||
{% if companies %}
|
||||
<form method="get" action="{{ url_for('main.stations') }}" class="row g-3 align-items-end">
|
||||
<div class="col-lg-8">
|
||||
<label class="form-label" for="stations-company-select">Firma</label>
|
||||
<select class="form-select" id="stations-company-select" name="company_id" required autofocus>
|
||||
<option value="" selected disabled>Wybierz firmę</option>
|
||||
{% for company in companies %}
|
||||
<option value="{{ company.id }}">{{ company.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-lg-4">
|
||||
<button class="btn btn-primary w-100">Przejdź do konfiguracji</button>
|
||||
</div>
|
||||
</form>
|
||||
{% else %}
|
||||
<div class="text-center py-4">
|
||||
<h2 class="h5">Brak aktywnych firm</h2>
|
||||
<p class="text-body-secondary mb-3">Najpierw dodaj lub aktywuj firmę w panelu administracyjnym.</p>
|
||||
<a class="btn btn-primary" href="{{ url_for('main.admin_companies') }}">Przejdź do firm</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user