Files
bricktracker
migrations
sql
views
admin
__init__.py
add.py
error.py
exceptions.py
index.py
instructions.py
login.py
minifigure.py
part.py
set.py
storage.py
upload.py
wish.py
__init__.py
app.py
config.py
configuration.py
configuration_list.py
exceptions.py
fields.py
instructions.py
instructions_list.py
login.py
metadata.py
metadata_list.py
minifigure.py
minifigure_list.py
navbar.py
parser.py
part.py
part_list.py
rebrickable.py
rebrickable_image.py
rebrickable_minifigure.py
rebrickable_part.py
rebrickable_set.py
rebrickable_set_list.py
record.py
record_list.py
reload.py
retired.py
retired_list.py
set.py
set_list.py
set_owner.py
set_owner_list.py
set_purchase_location.py
set_purchase_location_list.py
set_status.py
set_status_list.py
set_storage.py
set_storage_list.py
set_tag.py
set_tag_list.py
socket.py
socket_decorator.py
sql.py
sql_counter.py
sql_migration.py
sql_migration_list.py
sql_stats.py
theme.py
theme_list.py
version.py
wish.py
wish_list.py
wish_owner.py
wish_owner_list.py
docs
static
templates
.dockerignore
.env.sample
.gitignore
CHANGELOG.md
Dockerfile
LICENSE
README.md
__init__.py
app.py
compose.legacy.yml
compose.local.yaml
compose.yaml
entrypoint.sh
requirements.txt
test-server.sh
BrickTracker/bricktracker/views/wish.py
2025-02-04 20:07:15 +01:00

97 lines
2.4 KiB
Python

from flask import (
Blueprint,
jsonify,
redirect,
render_template,
request,
url_for
)
from flask_login import login_required
from werkzeug.wrappers.response import Response
from .exceptions import exception_handler
from ..retired_list import BrickRetiredList
from ..wish import BrickWish
from ..wish_list import BrickWishList
from ..wish_owner_list import BrickWishOwnerList
wish_page = Blueprint('wish', __name__, url_prefix='/wishes')
# Index
@wish_page.route('/', methods=['GET'])
@exception_handler(__file__)
def list() -> str:
return render_template(
'wishes.html',
table_collection=BrickWishList().all(),
retired=BrickRetiredList(),
error=request.args.get('error'),
owners=BrickWishOwnerList.list(),
)
# Add a set to the wishlit
@wish_page.route('/add', methods=['POST'])
@login_required
@exception_handler(__file__, post_redirect='wish.list')
def add() -> Response:
# Grab the set
set: str = request.form.get('set', '')
if set != '':
BrickWishList.add(set)
return redirect(url_for('wish.list'))
# Ask for deletion of a wish
@wish_page.route('/<set>/delete', methods=['GET'])
@login_required
@exception_handler(__file__)
def delete(*, set: str) -> str:
return render_template(
'wish.html',
delete=True,
item=BrickWish().select_specific(set),
error=request.args.get('error'),
owners=BrickWishOwnerList.list(),
)
# Actually delete of a set
@wish_page.route('/<set>/delete', methods=['POST'])
@login_required
@exception_handler(__file__, post_redirect='wish.list')
def do_delete(*, set: str) -> Response:
brickwish = BrickWish().select_specific(set)
brickwish.delete()
return redirect(url_for('wish.list'))
# Details
@wish_page.route('/<set>/details', methods=['GET'])
@exception_handler(__file__)
def details(*, set: str) -> str:
return render_template(
'wish.html',
item=BrickWish().select_specific(set),
retired=BrickRetiredList(),
owners=BrickWishOwnerList.list(),
)
# Change the state of a owner
@wish_page.route('/<set>/owner/<metadata_id>', methods=['POST'])
@login_required
@exception_handler(__file__, json=True)
def update_owner(*, set: str, metadata_id: str) -> Response:
brickwish = BrickWish().select_specific(set)
owner = BrickWishOwnerList.get(metadata_id)
state = owner.update_wish_state(brickwish, json=request.json)
return jsonify({'value': state})