From 83c631104a2956caff29799718d4813ed580c37c Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 7 Aug 2021 18:44:25 +0100 Subject: [PATCH] Currency field as dropdown --- content.py | 58 ++------------------------------------- utils.py | 63 +++++++++++++++++++++++++++++++++++++++++++ webapp_create_post.py | 18 ++++++++++--- 3 files changed, 80 insertions(+), 59 deletions(-) diff --git a/content.py b/content.py index aba27be6d..b6c631981 100644 --- a/content.py +++ b/content.py @@ -22,6 +22,7 @@ from utils import isPGPEncrypted from utils import containsPGPPublicKey from utils import acctDir from utils import isfloat +from utils import getCurrencies from petnames import getPetName @@ -1092,62 +1093,7 @@ def limitRepeatedWords(text: str, maxRepeats: int) -> str: def getPriceFromString(priceStr: str) -> (str, str): """Returns the item price and currency """ - currencies = { - "J$": "JMD", - "£": "GBP", - "€": "EUR", - "؋": "AFN", - "ƒ": "AWG", - "₼": "AZN", - "Br": "BYN", - "BZ$": "BZD", - "$b": "BOB", - "KM": "BAM", - "P": "BWP", - "лв": "BGN", - "R$": "BRL", - "៛": "KHR", - "$U": "UYU", - "RD$": "DOP", - "$": "USD", - "₡": "CRC", - "kn": "HRK", - "₱": "CUP", - "Kč": "CZK", - "kr": "NOK", - "¢": "GHS", - "Q": "GTQ", - "L": "HNL", - "Ft": "HUF", - "Rp": "IDR", - "﷼": "IRR", - "₪": "ILS", - "¥": "JPY", - "₩": "KRW", - "₭": "LAK", - "ден": "MKD", - "RM": "MYR", - "₨": "MUR", - "₮": "MNT", - "MT": "MZN", - "C$": "NIO", - "₦": "NGN", - "Gs": "PYG", - "zł": "PLN", - "lei": "RON", - "₽": "RUB", - "Дин": "RSD", - "S": "SOS", - "R": "ZAR", - "CHF": "CHF", - "NT$": "TWD", - "฿": "THB", - "TT$": "TTD", - "₴": "UAH", - "Bs": "VEF", - "₫": "VND", - "Z$": "ZQD" - } + currencies = getCurrencies() for symbol, name in currencies.items(): if symbol in priceStr: price = priceStr.replace(symbol, '') diff --git a/utils.py b/utils.py index a2014a5c2..8381ef109 100644 --- a/utils.py +++ b/utils.py @@ -2730,3 +2730,66 @@ def isGroupActor(baseDir: str, actor: str, personCache: {}, print('Group type found in ' + cachedActorFilename) return True return False + + +def getCurrencies() -> {}: + """Returns a dictionary of currencies + """ + return { + "CA$": "CAD", + "J$": "JMD", + "£": "GBP", + "€": "EUR", + "؋": "AFN", + "ƒ": "AWG", + "₼": "AZN", + "Br": "BYN", + "BZ$": "BZD", + "$b": "BOB", + "KM": "BAM", + "P": "BWP", + "лв": "BGN", + "R$": "BRL", + "៛": "KHR", + "$U": "UYU", + "RD$": "DOP", + "$": "USD", + "₡": "CRC", + "kn": "HRK", + "₱": "CUP", + "Kč": "CZK", + "kr": "NOK", + "¢": "GHS", + "Q": "GTQ", + "L": "HNL", + "Ft": "HUF", + "Rp": "IDR", + "₹": "INR", + "﷼": "IRR", + "₪": "ILS", + "¥": "JPY", + "₩": "KRW", + "₭": "LAK", + "ден": "MKD", + "RM": "MYR", + "₨": "MUR", + "₮": "MNT", + "MT": "MZN", + "C$": "NIO", + "₦": "NGN", + "Gs": "PYG", + "zł": "PLN", + "lei": "RON", + "₽": "RUB", + "Дин": "RSD", + "S": "SOS", + "R": "ZAR", + "CHF": "CHF", + "NT$": "TWD", + "฿": "THB", + "TT$": "TTD", + "₴": "UAH", + "Bs": "VEF", + "₫": "VND", + "Z$": "ZQD" + } diff --git a/webapp_create_post.py b/webapp_create_post.py index 097234457..f9927d1b8 100644 --- a/webapp_create_post.py +++ b/webapp_create_post.py @@ -14,6 +14,7 @@ from utils import getDomainFromActor from utils import getMediaFormats from utils import getConfigParam from utils import acctDir +from utils import getCurrencies from webapp_utils import getBannerFile from webapp_utils import htmlHeaderWithExternalStyle from webapp_utils import htmlFooter @@ -364,6 +365,7 @@ def htmlNewPost(cssCache: {}, mediaInstance: bool, translate: {}, categoryTypes = ("food", "clothes", "tool") catStr = translate['Category of shared item. eg. clothing'] extraFields += '
\n' + extraFields += ' ' + for symbol, currName in currencies.items(): + extraFields += ' ' + extraFields += '\n' citationsStr = ''