Skip to content

Commit

Permalink
Merge pull request #39 from ZeusWPI/web_interface
Browse files Browse the repository at this point in the history
fix: fixed id's only containing characters we want
  • Loading branch information
tyboro2002 authored Dec 29, 2024
2 parents 049d33e + 284359e commit e13a852
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
6 changes: 3 additions & 3 deletions data_types/choice.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import Enum

from utils import only_keep_UTF_8_chars
from utils import only_keep_UTF_8_chars, sanitize_id


class ChoiceType(Enum):
Expand All @@ -16,7 +16,7 @@ def __init__(self, name: str = "", price: float = 0.0):

def __str__(self):
self.name = only_keep_UTF_8_chars(self.name.replace("€", " euro "))
display_name = only_keep_UTF_8_chars(self.name.lower().replace(
display_name = sanitize_id(self.name.lower().replace(
" ", "_"
).replace(
".", "_dot_"
Expand All @@ -37,7 +37,7 @@ def __init__(self, name: str = "", description: str = "", type: ChoiceType = Cho
choices = []
self.type: ChoiceType = type
self.choices = choices
self.name: str = name
self.name: str = sanitize_id(name)
self.description: str = description

def update_name(self, new_name: str):
Expand Down
3 changes: 3 additions & 0 deletions data_types/common_choice_lists.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from data_types.choice import ChoiceList, Choice, ChoiceType


############################
# metropol #
############################
Expand Down Expand Up @@ -85,6 +86,7 @@ def create_metropol_groenten_keuze_list():
]
return groenten_keuze_list


def create_metropol_extra_keuze_list():
extra_keuze_list = ChoiceList(name="extra", description="Welke extra's?", type=ChoiceType.MULTI)

Expand All @@ -97,6 +99,7 @@ def create_metropol_extra_keuze_list():
]
return extra_keuze_list


############################
# simpizza #
############################
Expand Down
4 changes: 2 additions & 2 deletions data_types/product.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re

from data_types.choice import ChoiceList, Choice, ChoiceType
from utils import only_keep_UTF_8_chars
from utils import only_keep_UTF_8_chars, sanitize_id
from typing import List


Expand All @@ -16,7 +16,7 @@ def __init__(self, name: str = "", description: str = "", price: float = 0.0):
def __str__(self):
output = ""
self.name = only_keep_UTF_8_chars(self.name.replace("€", " euro "))
self.display_name = only_keep_UTF_8_chars(self.name.lower().replace(
self.display_name = sanitize_id(self.name.lower().replace(
" ", "_"
).replace(
".", "_dot_"
Expand Down
9 changes: 8 additions & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
from selenium.common.exceptions import StaleElementReferenceException


def sanitize_id(input_str):
# Keep only characters matching the pattern [a-z0-9_-]
sanitized = re.sub(r'[^a-z0-9_-]', '', input_str.lower().replace(" ", "_"))
return sanitized


def timer(func: Callable) -> Callable:
"""Print the runtime of the decorated function"""

Expand Down Expand Up @@ -172,7 +178,8 @@ def parse_pdf_with_strip_split_enters(file_path: str, coords: Tuple[int, int, in
return output.strip().split("\n")


def parse_pdf_section(pdf_url: str, local_file_path: str, coords: Tuple[int, int, int, int], page_number: int = 1) -> List:
def parse_pdf_section(pdf_url: str, local_file_path: str, coords: Tuple[int, int, int, int],
page_number: int = 1) -> List:
"""
Downloads a PDF, retrieves its dimensions, and extracts text from a specified section.
Expand Down

0 comments on commit e13a852

Please sign in to comment.