From 552a17fbc938cc8fad5f9e9cf84f2986f916c0eb Mon Sep 17 00:00:00 2001
From: Mikei386 <44135113+Mikei386@users.noreply.github.com>
Date: Thu, 26 Nov 2026 21:50:29 +0100
Subject: [PATCH] Add article copy icons to individual order lists
---
filament/static/filament/app.css | 43 ++++++++++++++++++-
...shopping_list.js => order_article_copy.js} | 12 ++++--
filament/tests/test_catalog.py | 8 +++-
filament/tests/test_orders.py | 38 +++-------------
filament/views.py | 15 +------
templates/filament/order_article_number.html | 8 ++++
templates/filament/order_shopping_list.html | 21 +--------
templates/filament/orders.html | 7 ++-
8 files changed, 79 insertions(+), 73 deletions(-)
rename filament/static/filament/{order_shopping_list.js => order_article_copy.js} (66%)
create mode 100644 templates/filament/order_article_number.html
diff --git a/filament/static/filament/app.css b/filament/static/filament/app.css
index 81af973..03da4b7 100644
--- a/filament/static/filament/app.css
+++ b/filament/static/filament/app.css
@@ -325,8 +325,7 @@ main {
gap: 20px;
margin-bottom: clamp(22px, 3vw, 36px);
}
-.order-page-actions,
-.order-shop-links {
+.order-page-actions {
display: flex;
flex-wrap: wrap;
gap: 10px;
@@ -339,6 +338,46 @@ main {
.article-copy [hidden] {
display: none;
}
+.article-copy .article-copy-icon-button {
+ min-height: 30px;
+ min-width: 30px;
+ padding: 0;
+ border-radius: 6px;
+}
+.article-copy-icon {
+ position: relative;
+ width: 16px;
+ height: 16px;
+}
+.article-copy-icon::before,
+.article-copy-icon::after {
+ content: "";
+ position: absolute;
+ width: 8px;
+ height: 10px;
+ border: 1px solid currentColor;
+ border-radius: 2px;
+}
+.article-copy-icon::before {
+ top: 0;
+ left: 1px;
+}
+.article-copy-icon::after {
+ right: 1px;
+ bottom: 0;
+ background: var(--surface-solid);
+}
+.article-copy-icon-button[data-copy-state] {
+ background: var(--light);
+}
+.article-copy-icon-button[data-copy-state="copied"] .article-copy-icon::before {
+ content: "✓";
+ position: static;
+ border: 0;
+}
+.article-copy-icon-button[data-copy-state="copied"] .article-copy-icon::after {
+ display: none;
+}
.eyebrow {
letter-spacing: 2px;
font-size: 10px;
diff --git a/filament/static/filament/order_shopping_list.js b/filament/static/filament/order_article_copy.js
similarity index 66%
rename from filament/static/filament/order_shopping_list.js
rename to filament/static/filament/order_article_copy.js
index d97bff8..fbf2a7a 100644
--- a/filament/static/filament/order_shopping_list.js
+++ b/filament/static/filament/order_article_copy.js
@@ -3,16 +3,18 @@
const copyStatus = document.querySelector("[data-copy-status]");
for (const button of document.querySelectorAll("[data-copy-article]")) {
+ const article = button.closest(".article-copy").querySelector("[data-article-code]");
+ const label = button.querySelector("[data-copy-label]");
button.hidden = false;
let resetLabel;
button.addEventListener("click", async () => {
- const article = document.getElementById(button.dataset.copyArticle);
const code = article.textContent.trim();
clearTimeout(resetLabel);
copyStatus.textContent = "";
try {
await navigator.clipboard.writeText(code);
- button.textContent = "Kopiert";
+ button.dataset.copyState = "copied";
+ if (label) label.textContent = "Kopiert";
copyStatus.textContent = `Artikelnummer ${code} kopiert.`;
} catch {
const range = document.createRange();
@@ -20,11 +22,13 @@ for (const button of document.querySelectorAll("[data-copy-article]")) {
const selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
- button.textContent = "Markiert";
+ button.dataset.copyState = "selected";
+ if (label) label.textContent = "Markiert";
copyStatus.textContent = "Artikelnummer markiert. Kopiere die Auswahl.";
}
resetLabel = setTimeout(() => {
- button.textContent = "Kopieren";
+ delete button.dataset.copyState;
+ if (label) label.textContent = "Kopieren";
}, 2000);
});
}
diff --git a/filament/tests/test_catalog.py b/filament/tests/test_catalog.py
index fb3a4c2..cb1b1fd 100644
--- a/filament/tests/test_catalog.py
+++ b/filament/tests/test_catalog.py
@@ -53,8 +53,12 @@ class CatalogTests(CatalogTestCase):
self.assertContains(response, 'referrerpolicy="no-referrer"', count=1)
self.assertContains(response, 'title="Hersteller-Farbcode"')
self.assertContains(response, "Artikelnr.")
- self.assertContains(response, '
11200 ', count=1)
- self.assertContains(response, '– ', count=1)
+ if url == "/bestand/":
+ self.assertContains(response, '11200 ', count=1)
+ else:
+ self.assertContains(response, "11200 ", count=1)
+ self.assertContains(response, 'aria-label="Artikelnummer 11200 kopieren"', count=1)
+ self.assertContains(response, '– ', count=1, html=True)
self.assertIn("https://cdn.shopify.com", response["Content-Security-Policy"])
self.assertNotIn(
"https://cdn.shopify.com", self.client.get("/katalog/")["Content-Security-Policy"]
diff --git a/filament/tests/test_orders.py b/filament/tests/test_orders.py
index ae16908..c89318a 100644
--- a/filament/tests/test_orders.py
+++ b/filament/tests/test_orders.py
@@ -1,12 +1,11 @@
from datetime import UTC, datetime
from unittest.mock import patch
-from urllib.parse import parse_qs, urlsplit
from django.contrib.auth import get_user_model
from django.test import Client
from django.urls import reverse
-from filament.models import Color, InventoryItem, OrderItem, StockMovement, Variant
+from filament.models import InventoryItem, OrderItem, StockMovement, Variant
from filament.services import add_quantity
from .base import CatalogTestCase
@@ -32,7 +31,10 @@ class SharedOrderTests(CatalogTestCase):
OrderItem.objects.create(owner=self.bob, variant=self.spool, quantity=4, status=status)
self.client.force_login(self.alice)
- self.assertContains(self.client.get(reverse("orders")), url)
+ orders = self.client.get(reverse("orders"))
+ self.assertContains(orders, url)
+ self.assertContains(orders, 'class="article-copy-icon"', count=6)
+ self.assertContains(orders, 'aria-label="Artikelnummer 10100 kopieren"', count=5)
result = self.client.get(url, {"q": "10100"})
self.assertEqual(
{variant.pk: variant.order_quantity for variant in result.context["variants"]},
@@ -40,37 +42,11 @@ class SharedOrderTests(CatalogTestCase):
)
self.assertContains(result, 'aria-label="Artikelnummer 10100 kopieren"', count=2)
self.assertEqual(result.context["total"], 4)
- self.assertEqual(
- result.context["shop_searches"],
- ["https://eu.store.bambulab.com/search?q=10100"],
- )
+ self.assertNotContains(result, "Im Bambu-Shop suchen")
+ self.assertNotContains(result, 'class="article-copy-icon"')
self.assertEqual(self.client.get(url, {"q": "10100, 10101"}).context["total"], 5)
self.assertEqual(self.client.post(url).status_code, 405)
- def test_shopping_list_shop_search_batches_distinct_codes(self):
- codes = [str(10800 + offset) for offset in range(13)]
- for code in codes:
- variant = Variant.objects.create(
- product_type=self.product,
- color=Color.objects.create(name=code),
- spool_type=Variant.SpoolType.SPOOL,
- manufacturer_color_code=code,
- )
- OrderItem.objects.create(owner=self.alice, variant=variant, quantity=1)
- OrderItem.objects.create(
- owner=self.alice, variant=self.spool, quantity=2, status=OrderItem.Status.UNAVAILABLE
- )
- self.client.force_login(self.bob)
- url = reverse("order_shopping_list")
- result = self.client.get(url)
- batches = [
- parse_qs(urlsplit(link).query)["q"][0].split(", ")
- for link in result.context["shop_searches"]
- ]
- self.assertEqual(batches, [codes[:12], codes[12:]])
- self.assertContains(result, "Im Bambu-Shop suchen (2/2)")
- self.assertEqual(result.context["total"], 13)
-
def test_history_is_shared_and_records_order_and_handover_times(self):
url = reverse("order_history")
self.assertRedirects(self.client.get(url), f"/anmelden/?next={url}")
diff --git a/filament/views.py b/filament/views.py
index 4c50adc..f64c153 100644
--- a/filament/views.py
+++ b/filament/views.py
@@ -1,7 +1,6 @@
import re
-from itertools import batched, groupby
+from itertools import groupby
from pathlib import PurePosixPath
-from urllib.parse import urlencode
from uuid import UUID, uuid4
from django.contrib import messages
@@ -966,17 +965,6 @@ def order_shopping_list(request):
for variant in variants
if variant.manufacturer_color_code.strip().casefold() in codes
]
- bambu_codes = dict.fromkeys(
- variant.manufacturer_color_code.strip()
- for variant in variants
- if variant.manufacturer.name.casefold() == "bambu lab"
- and re.fullmatch(r"[0-9]{5}", variant.manufacturer_color_code.strip())
- )
- # The shop accepted a dozen codes in one search. A full order can exceed its limit.
- shop_searches = [
- "https://eu.store.bambulab.com/search?" + urlencode({"q": ", ".join(batch)})
- for batch in batched(bambu_codes, 12)
- ]
return render(
request,
"filament/order_shopping_list.html",
@@ -984,7 +972,6 @@ def order_shopping_list(request):
"variants": variants,
"total": sum(variant.order_quantity for variant in variants),
"search": search,
- "shop_searches": shop_searches,
},
)
diff --git a/templates/filament/order_article_number.html b/templates/filament/order_article_number.html
new file mode 100644
index 0000000..e1b02d1
--- /dev/null
+++ b/templates/filament/order_article_number.html
@@ -0,0 +1,8 @@
+{% if article %}
+
+ {{ article }}
+
+ {% if icon_only %} {% else %}Kopieren {% endif %}
+
+
+{% else %}–{% endif %}
diff --git a/templates/filament/order_shopping_list.html b/templates/filament/order_shopping_list.html
index afef75f..b47fdea 100644
--- a/templates/filament/order_shopping_list.html
+++ b/templates/filament/order_shopping_list.html
@@ -7,14 +7,6 @@
Konsolidierte Bestellliste Offene Bestellwünsche aller Personen, zusammengezählt pro Variante.
{% include "filament/list_search.html" with search_url="order_shopping_list" search_label="Nach einer oder mehreren Artikelnummern suchen" placeholder="Artikelnummern, z. B. 10100, 10604" %}
-{% if shop_searches %}
-
-Prüfe im Shop Farbe, Spulenausführung und Stückzahl anhand dieser Liste.
-{% endif %}
{% if variants %}
@@ -26,7 +18,6 @@
Stück Produktart Farbe Spulenausführung Artikelnr.
{% for variant in variants %}
- {% with article=variant.manufacturer_color_code.strip %}
{{ variant.order_quantity }}
{{ variant.product_type.name }}{{ variant.manufacturer }}
@@ -36,23 +27,15 @@
{% if variant.net_weight_g or variant.diameter_mm %}{% if variant.net_weight_g %}{{ variant.net_weight_g }} g{% endif %}{% if variant.net_weight_g and variant.diameter_mm %} · {% endif %}{% if variant.diameter_mm %}{{ variant.diameter_mm }} mm{% endif %} {% endif %}
{% if not variant.is_active %}Katalogvariante deaktiviert {% endif %}
-
- {% if article %}
-
- {{ article }}
- Kopieren
-
- {% else %}–{% endif %}
-
+ {% include "filament/order_article_number.html" with article=variant.manufacturer_color_code.strip only %}
- {% endwith %}
{% endfor %}
-
+
{% else %}
{% if search %}Keine offenen Wünsche zu diesen Artikelnummern{% else %}Keine offenen Bestellwünsche{% endif %}
{% endif %}
diff --git a/templates/filament/orders.html b/templates/filament/orders.html
index 74ce1ac..595876d 100644
--- a/templates/filament/orders.html
+++ b/templates/filament/orders.html
@@ -1,4 +1,5 @@
{% extends "base.html" %}
+{% load static %}
{% block title %}Sammelbestellung · Fil-A-Management{% endblock %}
{% block content %}
@@ -27,7 +28,7 @@
{{ entry.quantity }}
{{ entry.variant.product_type.name }}{{ entry.variant.manufacturer }}
{% include "filament/variant_thumbnail.html" with variant=entry.variant only %}{{ entry.variant.color_label }}
-
{{ entry.variant.manufacturer_color_code|default:"–" }}
+
{% include "filament/order_article_number.html" with article=entry.variant.manufacturer_color_code.strip icon_only=True only %}
{{ entry.variant.get_spool_type_display }} {% if not entry.variant.is_active %}Deaktiviert · Katalogvariante {% endif %}