Currency field as dropdown

merge-requests/30/head
Bob Mottram 2021-08-07 18:44:25 +01:00
parent 3fe41d6c85
commit 83c631104a
3 changed files with 80 additions and 59 deletions

View File

@ -22,6 +22,7 @@ from utils import isPGPEncrypted
from utils import containsPGPPublicKey from utils import containsPGPPublicKey
from utils import acctDir from utils import acctDir
from utils import isfloat from utils import isfloat
from utils import getCurrencies
from petnames import getPetName from petnames import getPetName
@ -1092,62 +1093,7 @@ def limitRepeatedWords(text: str, maxRepeats: int) -> str:
def getPriceFromString(priceStr: str) -> (str, str): def getPriceFromString(priceStr: str) -> (str, str):
"""Returns the item price and currency """Returns the item price and currency
""" """
currencies = { currencies = getCurrencies()
"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",
"": "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",
"": "PLN",
"lei": "RON",
"": "RUB",
"Дин": "RSD",
"S": "SOS",
"R": "ZAR",
"CHF": "CHF",
"NT$": "TWD",
"฿": "THB",
"TT$": "TTD",
"": "UAH",
"Bs": "VEF",
"": "VND",
"Z$": "ZQD"
}
for symbol, name in currencies.items(): for symbol, name in currencies.items():
if symbol in priceStr: if symbol in priceStr:
price = priceStr.replace(symbol, '') price = priceStr.replace(symbol, '')

View File

@ -2730,3 +2730,66 @@ def isGroupActor(baseDir: str, actor: str, personCache: {},
print('Group type found in ' + cachedActorFilename) print('Group type found in ' + cachedActorFilename)
return True return True
return False 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",
"": "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",
"": "PLN",
"lei": "RON",
"": "RUB",
"Дин": "RSD",
"S": "SOS",
"R": "ZAR",
"CHF": "CHF",
"NT$": "TWD",
"฿": "THB",
"TT$": "TTD",
"": "UAH",
"Bs": "VEF",
"": "VND",
"Z$": "ZQD"
}

View File

@ -14,6 +14,7 @@ from utils import getDomainFromActor
from utils import getMediaFormats from utils import getMediaFormats
from utils import getConfigParam from utils import getConfigParam
from utils import acctDir from utils import acctDir
from utils import getCurrencies
from webapp_utils import getBannerFile from webapp_utils import getBannerFile
from webapp_utils import htmlHeaderWithExternalStyle from webapp_utils import htmlHeaderWithExternalStyle
from webapp_utils import htmlFooter from webapp_utils import htmlFooter
@ -364,6 +365,7 @@ def htmlNewPost(cssCache: {}, mediaInstance: bool, translate: {},
categoryTypes = ("food", "clothes", "tool") categoryTypes = ("food", "clothes", "tool")
catStr = translate['Category of shared item. eg. clothing'] catStr = translate['Category of shared item. eg. clothing']
extraFields += '<label class="labels">' + catStr + '</label><br>\n' extraFields += '<label class="labels">' + catStr + '</label><br>\n'
extraFields += ' <select id="themeDropdown" ' + \ extraFields += ' <select id="themeDropdown" ' + \
'name="category" class="theme">' 'name="category" class="theme">'
for category in categoryTypes: for category in categoryTypes:
@ -373,6 +375,7 @@ def htmlNewPost(cssCache: {}, mediaInstance: bool, translate: {},
extraFields += ' <option value="' + \ extraFields += ' <option value="' + \
translatedCategory + '">' + \ translatedCategory + '">' + \
translatedCategory + '</option>' translatedCategory + '</option>'
extraFields += '<br>' extraFields += '<br>'
extraFields += \ extraFields += \
editNumberField(translate['Duration of listing in days'], editNumberField(translate['Duration of listing in days'],
@ -386,9 +389,18 @@ def htmlNewPost(cssCache: {}, mediaInstance: bool, translate: {},
extraFields += \ extraFields += \
editCurrencyField(translate['Price'] + ':', 'itemPrice', '0.00', editCurrencyField(translate['Price'] + ':', 'itemPrice', '0.00',
'0.00', True) '0.00', True)
extraFields += '<br>' + \ extraFields += '<br>'
editTextField(translate['Currency'] + ':', 'itemCurrency', 'EUR', extraFields += \
'EUR / GBP / USD ...', True) '<label class="labels">' + translate['Currency'] + '</label><br>\n'
currencies = getCurrencies()
currencies.sort()
extraFields += ' <select id="themeDropdown" ' + \
'name="itemCurrency" class="theme">'
for symbol, currName in currencies.items():
extraFields += ' <option value="' + \
currName + '">' + \
currName + ' ' + symbol + '</option>'
extraFields += '</div>\n' extraFields += '</div>\n'
citationsStr = '' citationsStr = ''