diff --git a/shares.py b/shares.py
index 52d141689..a30270f61 100644
--- a/shares.py
+++ b/shares.py
@@ -35,18 +35,13 @@ from utils import removeDomainPort
from utils import isAccountDir
from utils import acctDir
from utils import isfloat
+from utils import getCategoryTypes
from media import processMetaData
from filters import isFilteredGlobally
from siteactive import siteIsActive
from content import getPriceFromString
-def _dfcProductTypes() -> []:
- # this list should match the ontology json files
- # eg. ontology/foodTypes.json
- return ['food', 'tool', 'clothes', 'medical']
-
-
def _loadDfcIds(baseDir: str, systemLanguage: str,
productType: str) -> {}:
"""Loads the product types ontology
@@ -168,13 +163,14 @@ def _addShareDurationSec(duration: str, published: int) -> int:
return 0
-def _dfcProductTypeFromCategory(itemCategory: str, translate: {}) -> str:
+def _dfcProductTypeFromCategory(baseDir: str,
+ itemCategory: str, translate: {}) -> str:
"""Does the shared item category match a DFC product type?
If so then return the product type.
This will be used to select an appropriate ontology file
such as ontology/foodTypes.json
"""
- productTypesList = _dfcProductTypes()
+ productTypesList = getCategoryTypes(baseDir)
categoryLower = itemCategory.lower()
for productType in productTypesList:
if translate.get(productType):
@@ -195,7 +191,8 @@ def _getshareDfcId(baseDir: str, systemLanguage: str,
"""
# does the category field match any prodyct type ontology
# files in the ontology subdirectory?
- matchedProductType = _dfcProductTypeFromCategory(itemCategory, translate)
+ matchedProductType = \
+ _dfcProductTypeFromCategory(baseDir, itemCategory, translate)
if not matchedProductType:
itemType = itemType.replace(' ', '_')
itemType = itemType.replace('.', '')
@@ -1452,7 +1449,7 @@ def _dfcToSharesFormat(catalogJson: {},
sharesJson = {}
dfcIds = {}
- productTypesList = _dfcProductTypes()
+ productTypesList = getCategoryTypes(baseDir)
for productType in productTypesList:
dfcIds[productType] = _loadDfcIds(baseDir, systemLanguage, productType)
diff --git a/tests.py b/tests.py
index d36cc1b5a..54c253220 100644
--- a/tests.py
+++ b/tests.py
@@ -42,6 +42,7 @@ from follow import clearFollowers
from follow import sendFollowRequestViaServer
from follow import sendUnfollowRequestViaServer
from siteactive import siteIsActive
+from utils import getCategoryTypes
from utils import getSupportedLanguages
from utils import setConfigParam
from utils import isGroupActor
@@ -5190,7 +5191,8 @@ def _testGetPriceFromString() -> None:
def _translateOntology() -> None:
- ontologyTypes = ('food', 'clothes', 'tool', 'medical')
+ baseDir = os.getcwd()
+ ontologyTypes = getCategoryTypes(baseDir)
url = 'https://translate.astian.org'
apiKey = None
ltLangList = libretranslateLanguages(url, apiKey)
diff --git a/utils.py b/utils.py
index ef736db09..bd00247df 100644
--- a/utils.py
+++ b/utils.py
@@ -2810,3 +2810,19 @@ def getSupportedLanguages(baseDir: str) -> []:
languagesStr.append(lang)
break
return languagesStr
+
+
+def getCategoryTypes(baseDir: str) -> []:
+ """Returns the list of ontologies
+ """
+ ontologyDir = baseDir + '/ontology'
+ categories = []
+ for subdir, dirs, files in os.walk(ontologyDir):
+ for f in files:
+ if not f.endswith('.json'):
+ continue
+ ontologyFilename = f.split('.')[0]
+ if 'Types' in ontologyFilename:
+ categories.append(ontologyFilename.replace('Types', ''))
+ break
+ return categories
diff --git a/webapp_create_post.py b/webapp_create_post.py
index 8737d1e1a..8b9c1700a 100644
--- a/webapp_create_post.py
+++ b/webapp_create_post.py
@@ -15,6 +15,7 @@ from utils import getMediaFormats
from utils import getConfigParam
from utils import acctDir
from utils import getCurrencies
+from utils import getCategoryTypes
from webapp_utils import getBannerFile
from webapp_utils import htmlHeaderWithExternalStyle
from webapp_utils import htmlFooter
@@ -363,7 +364,7 @@ def htmlNewPost(cssCache: {}, mediaInstance: bool, translate: {},
extraFields += '
' + \
editTextField(translate['Type of shared item. eg. hat'] + ':',
'itemType', '', '', True)
- categoryTypes = ("food", "clothes", "tool", "medical")
+ categoryTypes = getCategoryTypes()
catStr = translate['Category of shared item. eg. clothing']
extraFields += '
\n'