poprawki w synchronizacji produktow
This commit is contained in:
20
app.py
20
app.py
@@ -220,7 +220,7 @@ def require_system_password():
|
||||
# specjalny wyjątek dla statycznych, ale sprawdzany ręcznie niżej
|
||||
if request.endpoint == 'static_bp.serve_js':
|
||||
# tu sprawdzamy czy to JS, który ma być chroniony
|
||||
protected_js = ["live.js", "list_guest.js", "hide_list.js", "socket_reconnect.js"]
|
||||
protected_js = ["live.js", "list_guest.js", "hide_list.js", "socket_reconnect.js","sync_products.js", "expenses.js", "toggle_button.js"]
|
||||
requested_file = request.view_args.get("filename", "")
|
||||
if requested_file in protected_js:
|
||||
return redirect(url_for('system_auth', next=request.url))
|
||||
@@ -858,21 +858,23 @@ def list_products():
|
||||
suggestions_dict=suggestions_dict
|
||||
)
|
||||
|
||||
@app.route('/admin/sync_suggestion/<item_name>')
|
||||
@app.route('/admin/sync_suggestion_ajax/<int:item_id>', methods=['POST'])
|
||||
@login_required
|
||||
def sync_suggestion(item_name):
|
||||
def sync_suggestion_ajax(item_id):
|
||||
if not current_user.is_admin:
|
||||
return redirect(url_for('index_guest'))
|
||||
return jsonify({'success': False, 'message': 'Brak uprawnień'}), 403
|
||||
|
||||
existing = SuggestedProduct.query.filter(func.lower(SuggestedProduct.name) == item_name.lower()).first()
|
||||
item = Item.query.get_or_404(item_id)
|
||||
|
||||
existing = SuggestedProduct.query.filter(func.lower(SuggestedProduct.name) == item.name.lower()).first()
|
||||
if not existing:
|
||||
new_suggestion = SuggestedProduct(name=item_name)
|
||||
new_suggestion = SuggestedProduct(name=item.name)
|
||||
db.session.add(new_suggestion)
|
||||
db.session.commit()
|
||||
flash(f'Utworzono sugestię dla produktu: {item_name}', 'success')
|
||||
return jsonify({'success': True, 'message': f'Utworzono sugestię dla produktu: {item.name}'})
|
||||
else:
|
||||
flash(f'Sugestia dla produktu "{item_name}" już istnieje.', 'info')
|
||||
return redirect(url_for('list_products'))
|
||||
return jsonify({'success': True, 'message': f'Sugestia dla produktu „{item.name}” już istnieje.'})
|
||||
|
||||
|
||||
@app.route('/admin/delete_suggestion/<int:suggestion_id>')
|
||||
@login_required
|
||||
|
Reference in New Issue
Block a user