diff --git a/frontend/app.py b/frontend/app.py index 4dbc1d0..85ff2bc 100644 --- a/frontend/app.py +++ b/frontend/app.py @@ -47,6 +47,7 @@ def rents(): if not session['token']: return redirect(url_for('login')) + a = requests.get('http://localhost:8080/api/rents/', headers={'Authorization': session['token']}) rents_data = requests.get('http://localhost:8080/api/rents/', headers={'Authorization': session['token']}).json() cars = list( filter(lambda c: c['car_station_id'] == session['car_station_id'], @@ -59,8 +60,13 @@ def rents(): from datetime import datetime date_format = '%Y-%m-%dT%H:%M:%S.%f' + date_format_another = '%Y-%m-%dT%H:%M:%S' + + try: + parsed_date = datetime.strptime(rent['start_time'], date_format) + except ValueError: + parsed_date = datetime.strptime(rent['start_time'], date_format_another) - parsed_date = datetime.strptime(rent['start_time'], date_format) rent['start_time'] = parsed_date.strftime('%Y-%m-%d %H:%M:%S') for car in cars: @@ -84,8 +90,8 @@ def rents(): cars=cars, clients=clients, logged_in=True, - selected_client=int(request.args.get('client')) if request.args.get('client') else None, - selected_car=int(request.args.get('car')) if request.args.get('car') else None + selected_client=request.args.get('client') if request.args.get('client') else None, + selected_car=request.args.get('car') if request.args.get('car') else None ) response = None @@ -94,8 +100,8 @@ def rents(): headers={'Authorization': session['token']}) else: response = requests.post('http://localhost:8080/api/rents/', headers={'Authorization': session['token']}, json={ - "client_id": int(request.form.get('client_id')), - "car_id": int(request.form.get('car_id')) + "client_id": request.form.get('client_id'), + "car_id": request.form.get('car_id') }) if response.status_code != 200: @@ -107,8 +113,8 @@ def rents(): cars=cars, clients=clients, logged_in=True, - selected_client=int(request.args.get('client')) if request.args.get('client') else None, - selected_car=int(request.args.get('car')) if request.args.get('car') else None + selected_client=request.args.get('client') if request.args.get('client') else None, + selected_car=request.args.get('car') if request.args.get('car') else None ) if request.form.get('id'): @@ -149,12 +155,12 @@ def rents(): cars=cars, clients=clients, logged_in=True, - selected_client=int(request.args.get('client')) if request.args.get('client') else None, - selected_car=int(request.args.get('car')) if request.args.get('car') else None + selected_client=request.args.get('client') if request.args.get('client') else None, + selected_car=request.args.get('car') if request.args.get('car') else None ) -@app.route('/rents/', methods=['GET', 'POST']) +@app.route('/rents/', methods=['GET', 'POST']) def rent(id): if not session['token']: return redirect(url_for('login')) @@ -178,7 +184,7 @@ def rent(id): @app.route('/clients', defaults={'id': 0}, methods=['GET', 'POST']) -@app.route('/clients/', methods=['GET', 'POST']) +@app.route('/clients/', methods=['GET', 'POST']) def clients(id): if not session['token']: return redirect(url_for('login')) @@ -242,7 +248,7 @@ def clients(id): @app.route('/owners', defaults={'id': 0}, methods=['GET', 'POST']) -@app.route('/owners/', methods=['GET', 'POST']) +@app.route('/owners/', methods=['GET', 'POST']) def owners(id): if not session['token']: return redirect(url_for('login')) @@ -315,7 +321,7 @@ def owners(id): @app.route('/cars', defaults={'id': 0}, methods=['GET', 'POST']) -@app.route('/cars/', methods=['GET', 'POST']) +@app.route('/cars/', methods=['GET', 'POST']) def cars(id): if not session['token']: return redirect(url_for('login')) @@ -338,7 +344,7 @@ def cars(id): cars=cars, owners=owners, logged_in=True, - selected_owner=int(request.args.get('owner')) if request.args.get('owner') else None + selected_owner=request.args.get('owner') if request.args.get('owner') else None ) response = requests.patch(f'http://localhost:8080/api/cars/{id}', headers={'Authorization': session['token']}, @@ -346,7 +352,7 @@ def cars(id): 'brand': request.form.get('brand'), 'model': request.form.get('model'), 'price': float(request.form.get('price')), - 'owner_id': int(request.form.get('owner_id')), + 'owner_id': request.form.get('owner_id'), 'car_station_id': session['car_station_id'] }) @@ -359,14 +365,14 @@ def cars(id): owners=owners, current_car=list(filter(lambda c: c['id'] == id, cars))[0], logged_in=True, - selected_owner=int(request.args.get('owner')) if request.args.get('owner') else None + selected_owner=request.args.get('owner') if request.args.get('owner') else None ) return redirect(url_for('cars')) else: if not request.form.get('brand') or not request.form.get('model') or not request.form.get('price') or not request.form.get('owner_id'): return render_template('cars.html', title='Автомобили', errors='Должны быть заполнены все поля!', - owners=owners, selected_owner=int(request.args.get('owner')) if request.args.get('owner') else None, + owners=owners, selected_owner=request.args.get('owner') if request.args.get('owner') else None, cars=cars, logged_in=True) response = requests.post('http://localhost:8080/api/cars/', headers={'Authorization': session['token']}, @@ -374,21 +380,21 @@ def cars(id): 'brand': request.form.get('brand'), 'model': request.form.get('model'), 'price': float(request.form.get('price')), - 'owner_id': int(request.form.get('owner_id')), + 'owner_id': request.form.get('owner_id'), 'car_station_id': session['car_station_id'] }) if response.status_code != 200: return render_template('cars.html', title='Автомобили', errors=response.json(), cars=cars, - owners=owners, selected_owner=int(request.args.get('owner')) if request.args.get('owner') else None, + owners=owners, selected_owner=request.args.get('owner') if request.args.get('owner') else None, logged_in=True) cars = requests.get('http://localhost:8080/api/cars/', headers={'Authorization': session['token']}).json() if id != 0: - return render_template('cars.html', title='Изменение автомобиля', cars=cars, logged_in=True, owners=owners, selected_owner=int(request.args.get('owner')) if request.args.get('owner') else None, current_car=list(filter(lambda c: c['id'] == id, cars))[0]) + return render_template('cars.html', title='Изменение автомобиля', cars=cars, logged_in=True, owners=owners, selected_owner=request.args.get('owner') if request.args.get('owner') else None, current_car=list(filter(lambda c: c['id'] == id, cars))[0]) - return render_template('cars.html', title='Автомобили', cars=cars, logged_in=True, owners=owners, selected_owner=int(request.args.get('owner')) if request.args.get('owner') else None) + return render_template('cars.html', title='Автомобили', cars=cars, logged_in=True, owners=owners, selected_owner=request.args.get('owner') if request.args.get('owner') else None) @app.route('/report')