forked from FrederikBaerentsen/BrickTracker
Deduplicated parts and missing parts
This commit is contained in:
+11
-16
@@ -30,31 +30,26 @@ def missing() -> str:
|
||||
|
||||
|
||||
# Part details
|
||||
@part_page.route('/<number>/<int:color>/details', defaults={'element': None}, methods=['GET']) # noqa: E501
|
||||
@part_page.route('/<number>/<int:color>/<int:element>/details', methods=['GET']) # noqa: E501
|
||||
@part_page.route('/<part>/<int:color>/details', methods=['GET']) # noqa: E501
|
||||
@exception_handler(__file__)
|
||||
def details(*, number: str, color: int, element: int | None) -> str:
|
||||
def details(*, part: str, color: int) -> str:
|
||||
return render_template(
|
||||
'part.html',
|
||||
item=BrickPart().select_generic(number, color, element_id=element),
|
||||
item=BrickPart().select_generic(part, color),
|
||||
sets_using=BrickSetList().using_part(
|
||||
number,
|
||||
color,
|
||||
element_id=element
|
||||
part,
|
||||
color
|
||||
),
|
||||
sets_missing=BrickSetList().missing_part(
|
||||
number,
|
||||
color,
|
||||
element_id=element
|
||||
part,
|
||||
color
|
||||
),
|
||||
minifigures_using=BrickMinifigureList().using_part(
|
||||
number,
|
||||
color,
|
||||
element_id=element
|
||||
part,
|
||||
color
|
||||
),
|
||||
minifigures_missing=BrickMinifigureList().missing_part(
|
||||
number,
|
||||
color,
|
||||
element_id=element
|
||||
part,
|
||||
color
|
||||
),
|
||||
)
|
||||
|
||||
+28
-31
@@ -107,16 +107,34 @@ def details(*, id: str) -> str:
|
||||
)
|
||||
|
||||
|
||||
# Update the missing pieces of a minifig part
|
||||
@set_page.route('/<id>/minifigures/<figure>/parts/<part>/missing', methods=['POST']) # noqa: E501
|
||||
# Update the missing pieces of a part
|
||||
@set_page.route('/<id>/parts/<part>/<int:color>/<int:spare>/missing', defaults={'figure': None}, methods=['POST']) # noqa: E501
|
||||
@set_page.route('/<id>/minifigures/<figure>/parts/<part>/<int:color>/<int:spare>/missing', methods=['POST']) # noqa: E501
|
||||
@login_required
|
||||
@exception_handler(__file__, json=True)
|
||||
def missing_minifigure_part(*, id: str, figure: str, part: str) -> Response:
|
||||
def missing_part(
|
||||
*,
|
||||
id: str,
|
||||
figure: str | None,
|
||||
part: str,
|
||||
color: int,
|
||||
spare: int,
|
||||
) -> Response:
|
||||
from pprint import pprint
|
||||
pprint(locals())
|
||||
|
||||
brickset = BrickSet().select_specific(id)
|
||||
brickminifigure = BrickMinifigure().select_specific(brickset, figure)
|
||||
|
||||
if figure is not None:
|
||||
brickminifigure = BrickMinifigure().select_specific(brickset, figure)
|
||||
else:
|
||||
brickminifigure = None
|
||||
|
||||
brickpart = BrickPart().select_specific(
|
||||
brickset,
|
||||
part,
|
||||
color,
|
||||
spare,
|
||||
minifigure=brickminifigure,
|
||||
)
|
||||
|
||||
@@ -125,35 +143,14 @@ def missing_minifigure_part(*, id: str, figure: str, part: str) -> Response:
|
||||
brickpart.update_missing(missing)
|
||||
|
||||
# Info
|
||||
logger.info('Set {set} ({id}): updated minifigure ({figure}) part ({part}) missing count to {missing}'.format( # noqa: E501
|
||||
logger.info('Set {set} ({id}): updated part ({part} color: {color}, spare: {spare}, minifigure: {figure}) missing count to {missing}'.format( # noqa: E501
|
||||
set=brickset.fields.set,
|
||||
id=brickset.fields.id,
|
||||
figure=brickminifigure.fields.figure,
|
||||
part=brickpart.fields.id,
|
||||
missing=missing,
|
||||
))
|
||||
|
||||
return jsonify({'missing': missing})
|
||||
|
||||
|
||||
# Update the missing pieces of a part
|
||||
@set_page.route('/<id>/parts/<part>/missing', methods=['POST'])
|
||||
@login_required
|
||||
@exception_handler(__file__, json=True)
|
||||
def missing_part(*, id: str, part: str) -> Response:
|
||||
brickset = BrickSet().select_specific(id)
|
||||
brickpart = BrickPart().select_specific(brickset, part)
|
||||
|
||||
missing = request.json.get('missing', '') # type: ignore
|
||||
|
||||
brickpart.update_missing(missing)
|
||||
|
||||
# Info
|
||||
logger.info('Set {set} ({id}): updated part ({part}) missing count to {missing}'.format( # noqa: E501
|
||||
set=brickset.fields.set,
|
||||
id=brickset.fields.id,
|
||||
part=brickpart.fields.id,
|
||||
missing=missing,
|
||||
figure=figure,
|
||||
part=brickpart.fields.part,
|
||||
color=brickpart.fields.color,
|
||||
spare=brickpart.fields.spare,
|
||||
missing=brickpart.fields.missing,
|
||||
))
|
||||
|
||||
return jsonify({'missing': missing})
|
||||
|
||||
Reference in New Issue
Block a user