Change domain for assigned share ids

merge-requests/30/head
Bob Mottram 2021-09-12 18:10:15 +01:00
parent d9696c1568
commit 654c3b861b
1 changed files with 19 additions and 8 deletions

View File

@ -47,7 +47,8 @@ from blocking import isBlocked
def _loadDfcIds(baseDir: str, systemLanguage: str, def _loadDfcIds(baseDir: str, systemLanguage: str,
productType: str) -> {}: productType: str,
httpPrefix: str, domainFull: str) -> {}:
"""Loads the product types ontology """Loads the product types ontology
This is used to add an id to shared items This is used to add an id to shared items
""" """
@ -92,7 +93,10 @@ def _loadDfcIds(baseDir: str, systemLanguage: str,
if not label.get('@value'): if not label.get('@value'):
continue continue
if label['@language'] == systemLanguage: if label['@language'] == systemLanguage:
dfcIds[label['@value'].lower()] = item['@id'] itemId = \
item['@id'].replace('http://static.datafoodconsortium.org',
httpPrefix + '://' + domainFull)
dfcIds[label['@value'].lower()] = itemId
break break
return dfcIds return dfcIds
@ -196,7 +200,9 @@ def _dfcProductTypeFromCategory(baseDir: str,
def _getshareDfcId(baseDir: str, systemLanguage: str, def _getshareDfcId(baseDir: str, systemLanguage: str,
itemType: str, itemCategory: str, itemType: str, itemCategory: str,
translate: {}, dfcIds: {} = None) -> str: translate: {},
httpPrefix: str, domainFull: str,
dfcIds: {} = None) -> str:
"""Attempts to obtain a DFC Id for the shared item, """Attempts to obtain a DFC Id for the shared item,
based upon productTypes ontology. based upon productTypes ontology.
See https://github.com/datafoodconsortium/ontology See https://github.com/datafoodconsortium/ontology
@ -210,7 +216,8 @@ def _getshareDfcId(baseDir: str, systemLanguage: str,
itemType = itemType.replace('.', '') itemType = itemType.replace('.', '')
return 'epicyon#' + itemType return 'epicyon#' + itemType
if not dfcIds: if not dfcIds:
dfcIds = _loadDfcIds(baseDir, systemLanguage, matchedProductType) dfcIds = _loadDfcIds(baseDir, systemLanguage, matchedProductType,
httpPrefix, domainFull)
if not dfcIds: if not dfcIds:
return '' return ''
itemTypeLower = itemType.lower() itemTypeLower = itemType.lower()
@ -319,7 +326,8 @@ def addShare(baseDir: str,
actor = localActorUrl(httpPrefix, nickname, domainFull) actor = localActorUrl(httpPrefix, nickname, domainFull)
itemID = _getValidSharedItemID(actor, displayName) itemID = _getValidSharedItemID(actor, displayName)
dfcId = _getshareDfcId(baseDir, systemLanguage, dfcId = _getshareDfcId(baseDir, systemLanguage,
itemType, itemCategory, translate) itemType, itemCategory, translate,
httpPrefix, domainFull)
# has an image for this share been uploaded? # has an image for this share been uploaded?
imageUrl = None imageUrl = None
@ -1576,7 +1584,8 @@ def _updateFederatedSharesCache(session, sharedItemsFederatedDomains: [],
if saveJson(catalogJson, catalogFilename): if saveJson(catalogJson, catalogFilename):
print('Downloaded shared items catalog for ' + federatedDomainFull) print('Downloaded shared items catalog for ' + federatedDomainFull)
sharesJson = _dfcToSharesFormat(catalogJson, sharesJson = _dfcToSharesFormat(catalogJson,
baseDir, systemLanguage) baseDir, systemLanguage,
httpPrefix, domainFull)
if sharesJson: if sharesJson:
sharesFilename = \ sharesFilename = \
catalogsDir + '/' + federatedDomainFull + '.' + \ catalogsDir + '/' + federatedDomainFull + '.' + \
@ -1735,7 +1744,8 @@ def runFederatedSharesDaemon(baseDir: str, httpd, httpPrefix: str,
def _dfcToSharesFormat(catalogJson: {}, def _dfcToSharesFormat(catalogJson: {},
baseDir: str, systemLanguage: str) -> {}: baseDir: str, systemLanguage: str,
httpPrefix: str, domainFull: str) -> {}:
"""Converts DFC format into the internal formal used to store shared items. """Converts DFC format into the internal formal used to store shared items.
This simplifies subsequent search and display This simplifies subsequent search and display
""" """
@ -1746,7 +1756,8 @@ def _dfcToSharesFormat(catalogJson: {},
dfcIds = {} dfcIds = {}
productTypesList = getCategoryTypes(baseDir) productTypesList = getCategoryTypes(baseDir)
for productType in productTypesList: for productType in productTypesList:
dfcIds[productType] = _loadDfcIds(baseDir, systemLanguage, productType) dfcIds[productType] = _loadDfcIds(baseDir, systemLanguage, productType,
httpPrefix, domainFull)
currTime = int(time.time()) currTime = int(time.time())
for item in catalogJson['DFC:supplies']: for item in catalogJson['DFC:supplies']: