def SUBJ(row, rowBack = True): # sanity check if row is None: return None node = tree.findNode(row.get("Categoria_Seccion", -1), row.get("Categoria_Grupo", -1), row.get("Categoria_Familia", -1), row.get("Categoria_Subfamilia", -1)) linkBase = "" if node is not None: linkBase = node["LinkBase"] else: path = [ row.get("Categoria_Seccion", -1), row.get("Categoria_Grupo", -1), row.get("Categoria_Familia", -1), row.get("Categoria_Subfamilia", -1) ] path = [ str(p) for p in path if p != -1 ] if len(path) == 0: path = [ -1 ] linkBase = ".".join(path) row["LinkBase"] = linkBase return row if rowBack else row["LinkBase"]
def SUBJ(row, rowBack = True): # find the nodes subtype = row["Subtype"] seccion = tree.findNode(row["Categoria_Seccion"], -1, -1, -1) grupo = tree.findNode(row["Categoria_Seccion"], row["Categoria_Grupo"], -1, -1) familia = tree.findNode(row["Categoria_Seccion"], row["Categoria_Grupo"], row["Categoria_Familia"], -1) subfamilia = tree.findNode(row["Categoria_Seccion"], row["Categoria_Grupo"], row["Categoria_Familia"], row["Categoria_Subfamilia"]) # prepare an empty URL url = "/" # FIRST PART - seccion or /catalogo/seccion - all cases if subtype in [ "Seccion", "Grupo", "Familia", "Subfamilia" ]: if subtype in _urlBases and seccion["id"] in _urlBases[subtype]: url += _urlBases[subtype][seccion["id"]] else: if subtype == "Seccion": url += tmklib.support.noDiacritics(seccion["Nombre"]) + "/" else: url += "catalogo/" + tmklib.support.noDiacritics(seccion["Nombre"]) + "/" # SECOND PART - seccion (group and bellow) if subtype in [ "Grupo", "Familia", "Subfamilia" ]: url += tmklib.support.alphaOnly( tmklib.support.noDiacritics( tmklib.support.capitalize( grupo["Nombre"]))).strip("_").lower() + \ "--" + str(grupo["id"]) + "/" # THIRD PART - seccion (family and bellow) if subtype in [ "Familia", "Subfamilia" ]: url += tmklib.support.alphaOnly( tmklib.support.noDiacritics( tmklib.support.capitalize( familia["Nombre"]))).strip("_").lower() + \ "--" + str(familia["id"]) + "/" # FOURT PART - seccion (subfamily and bellow) if subtype in [ "Subfamilia" ]: url += tmklib.support.alphaOnly( tmklib.support.noDiacritics( tmklib.support.capitalize( subfamilia["Nombre"]))).strip("_").lower() + \ "--" + str(subfamilia["id"]) + "/" # FILE EXTENSION (ONLY IF NOT "Seccion") if subtype in [ "Grupo", "Familia", "Subfamilia" ]: # remove the trailing "/" (if present) if url[-1] == "/": url = url[:-1] # append the file extension #####url += ".htm" # set the url row["LinkBase"] = url return row if rowBack else url
def PROD(row, rowBack = True, entityIdVar = "EntityId"): # find the nodes seccion = tree.findNode(row["Categoria_Seccion"], -1, -1, -1) grupo = tree.findNode(row["Categoria_Seccion"], row["Categoria_Grupo"], -1, -1) familia = tree.findNode(row["Categoria_Seccion"], row["Categoria_Grupo"], row["Categoria_Familia"], -1) subfamilia = tree.findNode(row["Categoria_Seccion"], row["Categoria_Grupo"], row["Categoria_Familia"], row["Categoria_Subfamilia"]) # FIRST PART - seccion url = "/" if seccion["id"] == 1: url += "libros/" elif seccion["id"] == 3: url += "pasatiempos/" elif seccion["id"] == 4: url += "cds/" elif seccion["id"] == 5: url += "dvds/" else: url += tmklib.support.noDiacritics(seccion["Nombre"]) + "/" # SECOND PART - grupo (if any) if grupo is not None and grupo["id"] != 0: url += tmklib.support.alphaOnly( tmklib.support.noDiacritics( tmklib.support.capitalize( grupo["Nombre"]))).strip("_").lower() + \ "--" + str(grupo["id"]) + "/" # THIRD PART - familia (if any) if familia is not None and familia["id"] != 0: url += tmklib.support.alphaOnly( tmklib.support.noDiacritics( tmklib.support.capitalize( familia["Nombre"]))).strip("_").lower() + \ "--" + str(familia["id"]) + "/" # FOURTH PART - subfamilia (if any) if subfamilia is not None and subfamilia["id"] != 0: url += tmklib.support.alphaOnly( tmklib.support.noDiacritics( tmklib.support.capitalize( subfamilia["Nombre"]))).strip("_").lower() + \ "--" + str(subfamilia["id"]) + "/" # FIFTH PART - title _title = row.get("_Title") if not _title: _title = row.get("Title") url += tmklib.support.smartStrip( tmklib.support.alphaOnly( tmklib.support.noDiacritics( tmklib.support.capitalize( _title, False)), True)).lower() # check length. NO MORE THAN 230 chars # # not exact science. Name can have multiple \\ or multiple // # depending on what's configured. Give some room for different # conditions if len(url) > 200: url = url[:200] # SIXTH PART - the "--<product id>" # # this is appended later, after we know for sure # file name length is not larger than 230 chars # url += "--" + str(row[entityIdVar]) # set the url row["LinkBase"] = url return row if rowBack else url