Improve projects order

This commit is contained in:
allegroai 2021-01-05 16:46:23 +02:00
parent 29ef134b79
commit e12fd8f3df
2 changed files with 18 additions and 11 deletions

View File

@ -1,8 +1,13 @@
# Order of featured projects, by name or ID
featured_order: [
# {id: "<project-id>"}
# OR
# {name: "<project-name>"}
# OR
# {name_regex: "<python-regex>"}
]
featured {
order: [
# {id: "<project-id>"}
# OR
# {name: "<project-name>"}
# OR
# {name_regex: "<python-regex>"}
]
# default featured index for public projects not specified in the order
public_default: 9999
}

View File

@ -363,19 +363,21 @@ class PrePopulate:
@classmethod
def update_featured_projects_order(cls):
featured_order = config.get("services.projects.featured_order", [])
if not featured_order:
order = config.get("services.projects.featured.order", [])
if not order:
return
public_default = config.get("services.projects.featured.public_default", 9999)
def get_index(p: Project):
for index, entry in enumerate(featured_order):
for index, entry in enumerate(order):
if (
entry.get("id", None) == p.id
or entry.get("name", None) == p.name
or ("name_regex" in entry and re.match(entry["name_regex"], p.name))
):
return index
return 999
return public_default
for project in Project.get_many_public(projection=["id", "name"]):
featured_index = get_index(project)