From b4ab4809c6c93e77542cab3f8bfe06d1416aeea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Tue, 21 Nov 2023 23:20:22 +0100 Subject: [PATCH] handling special chars in solution --- Ideen.md | 2 +- api/advent22_api/core/config.py | 12 +++++++++++- api/advent22_api/routers/admin.py | 2 ++ ui/src/components/admin/ConfigView.vue | 7 +++++++ ui/src/lib/api.ts | 1 + 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Ideen.md b/Ideen.md index 37f6fdf..3da3c3b 100644 --- a/Ideen.md +++ b/Ideen.md @@ -7,7 +7,6 @@ - api/ui: Türchen mit Tag "0" einem zufälligen Tag zuweisen - api/?: Option "custom Zuordnung Buchstaben" (standard leer) -- api: `config.solution` - whitespace="IGNORE"->"REMOVE" umbenennen, +Sonderzeichen - ui: `confirm` durch bulma Komponente(n) ersetzen # Erledigt @@ -20,3 +19,4 @@ - Nach einigen Sekunden: Meldung "Türchen anzeigen?" - `alert` durch bulma Komponente(n) ersetzen - api: admin Login case sensitivity (username "admin" == "AdMiN") +- api: `config.solution` - whitespace="IGNORE"->"REMOVE" umbenennen, +Sonderzeichen diff --git a/api/advent22_api/core/config.py b/api/advent22_api/core/config.py index ebc1ac9..97b5461 100644 --- a/api/advent22_api/core/config.py +++ b/api/advent22_api/core/config.py @@ -29,7 +29,12 @@ class TransformedString(BaseModel): # whitespace entfernen REMOVE = "REMOVE" - # special chars + class __SpecialChars(str, Enum): + # unverändert + KEEP = "KEEP" + + # Sonderzeichen entfernen + REMOVE = "REMOVE" class __Case(str, Enum): # unverändert @@ -47,6 +52,7 @@ class TransformedString(BaseModel): value: str whitespace: __Whitespace = __Whitespace.REMOVE + special_chars: __SpecialChars = __SpecialChars.REMOVE case: __Case = __Case.UPPER @field_validator("whitespace", "case", mode="before") @@ -67,6 +73,10 @@ class TransformedString(BaseModel): elif self.whitespace is TransformedString.__Whitespace.REMOVE: result = re.sub(string=result, pattern=r"\s+", repl="") + # Sonderzeichen verarbeiten + if self.special_chars is TransformedString.__SpecialChars.REMOVE: + result = re.sub(string=result, pattern=r"[^a-zA-Z0-9\s]+", repl="") + # Groß-/Kleinschreibung verarbeiten if self.case is TransformedString.__Case.UPPER: result = result.upper() diff --git a/api/advent22_api/routers/admin.py b/api/advent22_api/routers/admin.py index e1b6496..45dc83a 100644 --- a/api/advent22_api/routers/admin.py +++ b/api/advent22_api/routers/admin.py @@ -31,6 +31,7 @@ class AdminConfigModel(BaseModel): class __Solution(BaseModel): value: str whitespace: str + special_chars: str case: str clean: str @@ -81,6 +82,7 @@ async def get_config_model( "solution": { "value": cfg.solution.value, "whitespace": cfg.solution.whitespace, + "special_chars": cfg.solution.special_chars, "case": cfg.solution.case, "clean": cfg.solution.clean, }, diff --git a/ui/src/components/admin/ConfigView.vue b/ui/src/components/admin/ConfigView.vue index 4acddb1..eb0e9e4 100644 --- a/ui/src/components/admin/ConfigView.vue +++ b/ui/src/components/admin/ConfigView.vue @@ -27,6 +27,12 @@ {{ admin_config_model.solution.whitespace }} +
+ Sonderzeichen: + + {{ admin_config_model.solution.special_chars }} + +
Buchstaben: @@ -184,6 +190,7 @@ export default class extends Vue { solution: { value: "ABCDEFGHIJKLMNOPQRSTUVWXYZ", whitespace: "KEEP", + special_chars: "KEEP", case: "KEEP", clean: "ABCDEFGHIJKLMNOPQRSTUVWXYZ", }, diff --git a/ui/src/lib/api.ts b/ui/src/lib/api.ts index a67e080..f7a1874 100644 --- a/ui/src/lib/api.ts +++ b/ui/src/lib/api.ts @@ -2,6 +2,7 @@ export interface AdminConfigModel { solution: { value: string; whitespace: string; + special_chars: string; case: string; clean: string; };