From 34408a1bff0071e71b448fceeab54563ac39f751 Mon Sep 17 00:00:00 2001 From: Gregoo Date: Mon, 3 Feb 2025 10:10:06 +0100 Subject: [PATCH] Display same parts using a different color --- CHANGELOG.md | 1 + bricktracker/part_list.py | 30 +++++++++++++++++++ .../sql/part/list/with_different_color.sql | 17 +++++++++++ bricktracker/views/part.py | 3 +- templates/part/card.html | 1 + 5 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 bricktracker/sql/part/list/with_different_color.sql diff --git a/CHANGELOG.md b/CHANGELOG.md index 28a7f0f..54b0fa8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,6 +63,7 @@ Parts - Display if print of another part - Display prints using the same base - Damaged parts + - Display same parts using a different color - Sets - Add a flag to hide instructions in a set diff --git a/bricktracker/part_list.py b/bricktracker/part_list.py index 86ca34a..d0e7138 100644 --- a/bricktracker/part_list.py +++ b/bricktracker/part_list.py @@ -23,6 +23,7 @@ class BrickPartList(BrickRecordList[BrickPart]): # Queries all_query: str = 'part/list/all' + different_color_query = 'part/list/with_different_color' last_query: str = 'part/list/last' minifigure_query: str = 'part/list/from_minifigure' problem_query: str = 'part/list/problem' @@ -166,6 +167,35 @@ class BrickPartList(BrickRecordList[BrickPart]): return parameters + # Load generic parts with same base but different color + def with_different_color( + self, + brickpart: BrickPart, + /, + ) -> Self: + # Save the part + self.fields.part = brickpart.fields.part + self.fields.color = brickpart.fields.color + + # Load the parts from the database + for record in self.select( + override_query=self.different_color_query, + order=self.order + ): + part = BrickPart( + record=record, + ) + + if ( + current_app.config['SKIP_SPARE_PARTS'] and + part.fields.spare + ): + continue + + self.records.append(part) + + return self + # Import the parts from Rebrickable @staticmethod def download( diff --git a/bricktracker/sql/part/list/with_different_color.sql b/bricktracker/sql/part/list/with_different_color.sql new file mode 100644 index 0000000..d75501d --- /dev/null +++ b/bricktracker/sql/part/list/with_different_color.sql @@ -0,0 +1,17 @@ + +{% extends 'part/base/base.sql' %} + +{% block total_missing %}{% endblock %} + +{% block total_damaged %}{% endblock %} + +{% block where %} +WHERE "bricktracker_parts"."color" IS DISTINCT FROM :color +AND "bricktracker_parts"."part" IS NOT DISTINCT FROM :part +{% endblock %} + +{% block group %} +GROUP BY + "bricktracker_parts"."part", + "bricktracker_parts"."color" +{% endblock %} diff --git a/bricktracker/views/part.py b/bricktracker/views/part.py index 0bea4ab..7cbc1c8 100644 --- a/bricktracker/views/part.py +++ b/bricktracker/views/part.py @@ -62,5 +62,6 @@ def details(*, part: str, color: int) -> str: part, color ), - similar_prints=BrickPartList().from_print(brickpart) + different_color=BrickPartList().with_different_color(brickpart), + similar_prints=BrickPartList().from_print(brickpart), ) diff --git a/templates/part/card.html b/templates/part/card.html index 8a0d7aa..16f2103 100644 --- a/templates/part/card.html +++ b/templates/part/card.html @@ -29,6 +29,7 @@ {{ accordion.cards(minifigures_using, 'Minifigures using this part', 'minifigures-using-inventory', 'part-details', 'minifigure/card.html', icon='group-line') }} {{ accordion.cards(minifigures_missing, 'Minifigures missing this part', 'minifigures-missing-inventory', 'part-details', 'minifigure/card.html', icon='question-line') }} {{ accordion.cards(minifigures_damaged, 'Minifigures with this part damaged', 'minifigures-damaged-inventory', 'part-details', 'minifigure/card.html', icon='error-warning-line') }} + {{ accordion.cards(different_color, 'Same part with a different color', 'different-color', 'part-details', 'part/card.html', icon='palette-line') }} {{ accordion.cards(similar_prints, 'Prints using the same base', 'similar-prints', 'part-details', 'part/card.html', icon='paint-brush-line') }}