ux i poprawki
This commit is contained in:
31
app.py
31
app.py
@ -49,14 +49,19 @@ def load_user(user_id):
|
||||
|
||||
@app.before_request
|
||||
def require_system_password():
|
||||
if 'authorized' not in request.cookies and request.endpoint != 'system_auth' and not request.endpoint.startswith('static') and not request.endpoint.startswith('login'):
|
||||
return redirect(url_for('system_auth'))
|
||||
if 'authorized' not in request.cookies \
|
||||
and request.endpoint != 'system_auth' \
|
||||
and not request.endpoint.startswith('static') \
|
||||
and not request.endpoint.startswith('login'):
|
||||
return redirect(url_for('system_auth', next=request.url))
|
||||
|
||||
@app.route('/system-auth', methods=['GET', 'POST'])
|
||||
def system_auth():
|
||||
DEFAULT_ADMIN_USERNAME = app.config.get('DEFAULT_ADMIN_USERNAME', 'admin')
|
||||
DEFAULT_ADMIN_PASSWORD = app.config.get('DEFAULT_ADMIN_PASSWORD', 'admin123')
|
||||
|
||||
next_page = request.args.get('next') or url_for('index_guest')
|
||||
|
||||
if request.method == 'POST':
|
||||
if request.form['password'] == SYSTEM_PASSWORD:
|
||||
db.create_all()
|
||||
@ -69,7 +74,7 @@ def system_auth():
|
||||
db.session.add(admin_user)
|
||||
db.session.commit()
|
||||
flash(f'Utworzono konto administratora: login={DEFAULT_ADMIN_USERNAME}, hasło={DEFAULT_ADMIN_PASSWORD}')
|
||||
resp = redirect(url_for('index_guest'))
|
||||
resp = redirect(next_page)
|
||||
resp.set_cookie('authorized', 'true')
|
||||
return resp
|
||||
flash('Nieprawidłowe hasło do systemu')
|
||||
@ -80,6 +85,10 @@ def index_guest():
|
||||
lists = ShoppingList.query.all()
|
||||
return render_template('index.html', lists=lists)
|
||||
|
||||
@app.errorhandler(404)
|
||||
def page_not_found(e):
|
||||
return render_template('404.html'), 404
|
||||
|
||||
@app.route('/login', methods=['GET', 'POST'])
|
||||
def login():
|
||||
if request.method == 'POST':
|
||||
@ -128,6 +137,12 @@ def share_list(token):
|
||||
items = Item.query.filter_by(list_id=shopping_list.id).all()
|
||||
return render_template('list_guest.html', list=shopping_list, items=items)
|
||||
|
||||
@app.route('/guest-list/<int:list_id>')
|
||||
def guest_list(list_id):
|
||||
shopping_list = ShoppingList.query.get_or_404(list_id)
|
||||
items = Item.query.filter_by(list_id=list_id).all()
|
||||
return render_template('list_guest.html', list=shopping_list, items=items)
|
||||
|
||||
@app.route('/copy/<int:list_id>')
|
||||
@login_required
|
||||
def copy_list(list_id):
|
||||
@ -281,6 +296,16 @@ def handle_check_item(data):
|
||||
db.session.commit()
|
||||
emit('item_checked', {'item_id': item.id}, to=str(item.list_id))
|
||||
|
||||
@socketio.on('uncheck_item')
|
||||
def handle_uncheck_item(data):
|
||||
item = Item.query.get(data['item_id'])
|
||||
if item:
|
||||
item.purchased = False
|
||||
item.purchased_at = None
|
||||
db.session.commit()
|
||||
emit('item_unchecked', {'item_id': item.id}, to=str(item.list_id))
|
||||
|
||||
|
||||
@app.cli.command('create_db')
|
||||
def create_db():
|
||||
db.create_all()
|
||||
|
Reference in New Issue
Block a user