Implemented filtering and ordering for projects and tools
Update app.py, circuitpython-ebyte-e32.yml, and 9 more files...
This commit is contained in:
9
app.py
9
app.py
@@ -9,7 +9,8 @@ from flask import render_template
|
|||||||
from werkzeug.exceptions import HTTPException
|
from werkzeug.exceptions import HTTPException
|
||||||
|
|
||||||
from website.content import get_projects, get_tools, sanitize_input_tags, load_content_items, get_content, \
|
from website.content import get_projects, get_tools, sanitize_input_tags, load_content_items, get_content, \
|
||||||
get_applets, get_projects_languages, get_projects_by_languages
|
get_applets, get_projects_languages, get_projects_by_languages, get_sorted_tools_by_tags, \
|
||||||
|
get_sorted_projects_by_tags
|
||||||
from website.contributors import reload_contributors_data
|
from website.contributors import reload_contributors_data
|
||||||
from website.domains import ALLOWED_DOMAINS
|
from website.domains import ALLOWED_DOMAINS
|
||||||
from website.l10n.utils import get_user_lang, localize, reload_strings, l10n_url_abs, l10n_url_switch, DEFAULT_LANG
|
from website.l10n.utils import get_user_lang, localize, reload_strings, l10n_url_abs, l10n_url_switch, DEFAULT_LANG
|
||||||
@@ -119,9 +120,11 @@ def inject_processors():
|
|||||||
get_applets=get_applets,
|
get_applets=get_applets,
|
||||||
# get_articles=get_articles,
|
# get_articles=get_articles,
|
||||||
get_projects=get_projects,
|
get_projects=get_projects,
|
||||||
get_projects_by_languages=get_projects_by_languages,
|
# get_projects_by_languages=get_projects_by_languages,
|
||||||
get_projects_languages=get_projects_languages,
|
# get_projects_languages=get_projects_languages,
|
||||||
get_tools=get_tools,
|
get_tools=get_tools,
|
||||||
|
get_sorted_projects_by_tags=get_sorted_projects_by_tags,
|
||||||
|
get_sorted_tools_by_tags=get_sorted_tools_by_tags,
|
||||||
|
|
||||||
# Renderers
|
# Renderers
|
||||||
render_button=render_button,
|
render_button=render_button,
|
||||||
|
@@ -16,7 +16,7 @@ projects:
|
|||||||
title_key: "meta.title"
|
title_key: "meta.title"
|
||||||
description_key: "meta.description"
|
description_key: "meta.description"
|
||||||
index:
|
index:
|
||||||
priority: 105
|
priority: 3000
|
||||||
enable: true
|
enable: true
|
||||||
title_key: "meta.title"
|
title_key: "meta.title"
|
||||||
preamble_key: "meta.description"
|
preamble_key: "meta.description"
|
||||||
|
@@ -16,7 +16,7 @@ projects:
|
|||||||
title_key: "meta.title"
|
title_key: "meta.title"
|
||||||
description_key: "meta.description"
|
description_key: "meta.description"
|
||||||
index:
|
index:
|
||||||
priority: 105
|
priority: 1000
|
||||||
enable: true
|
enable: true
|
||||||
title_key: "meta.title"
|
title_key: "meta.title"
|
||||||
preamble_key: "meta.description"
|
preamble_key: "meta.description"
|
||||||
|
@@ -16,7 +16,7 @@ projects:
|
|||||||
title_key: "meta.title"
|
title_key: "meta.title"
|
||||||
description_key: "meta.description"
|
description_key: "meta.description"
|
||||||
index:
|
index:
|
||||||
priority: 105
|
priority: 2000
|
||||||
enable: true
|
enable: true
|
||||||
title_key: "meta.title"
|
title_key: "meta.title"
|
||||||
preamble_key: "meta.description"
|
preamble_key: "meta.description"
|
||||||
|
@@ -14,29 +14,35 @@
|
|||||||
#
|
#
|
||||||
#-
|
#-
|
||||||
|
|
||||||
- title_key: text.applications
|
- title_key: text.projects
|
||||||
abs_href: "/content/?tags=application;web"
|
abs_href: "/content/?tags="
|
||||||
icon: fad fa-browser
|
icon: fad fa-briefcase
|
||||||
active_id: application
|
active_id: projects
|
||||||
has_new_until_utc: 0
|
has_new_until_utc: 0
|
||||||
|
|
||||||
- title_key: text.libraries
|
#- title_key: text.applications
|
||||||
abs_href: "/content/?tags=library"
|
# abs_href: "/content/?tags=application;web"
|
||||||
icon: fad fa-puzzle-piece
|
# icon: fad fa-browser
|
||||||
active_id: library
|
# active_id: application
|
||||||
has_new_until_utc: 0
|
# has_new_until_utc: 0
|
||||||
|
#
|
||||||
|
#- title_key: text.libraries
|
||||||
|
# abs_href: "/content/?tags=library"
|
||||||
|
# icon: fad fa-puzzle-piece
|
||||||
|
# active_id: library
|
||||||
|
# has_new_until_utc: 0
|
||||||
|
#
|
||||||
|
#- title_key: text.electronics
|
||||||
|
# abs_href: "/content/?tags=electronic"
|
||||||
|
# icon: fad fa-microchip
|
||||||
|
# active_id: electronic
|
||||||
|
# has_new_until_utc: 0
|
||||||
|
|
||||||
- title_key: text.electronics
|
#- title_key: text.experiments
|
||||||
abs_href: "/content/?tags=electronic"
|
# abs_href: "/content/?tags=experiments"
|
||||||
icon: fad fa-microchip
|
# icon: fad fa-flask-vial
|
||||||
active_id: electronic
|
# active_id: electronic
|
||||||
has_new_until_utc: 0
|
# has_new_until_utc: 0
|
||||||
|
|
||||||
- title_key: text.experiments
|
|
||||||
abs_href: "/content/?tags=experiments"
|
|
||||||
icon: fad fa-flask-vial
|
|
||||||
active_id: electronic
|
|
||||||
has_new_until_utc: 0
|
|
||||||
|
|
||||||
- title_key: text.tools
|
- title_key: text.tools
|
||||||
abs_href: "/tools"
|
abs_href: "/tools"
|
||||||
|
@@ -17,7 +17,7 @@ tools:
|
|||||||
title_key: "meta.title"
|
title_key: "meta.title"
|
||||||
description_key: "meta.description"
|
description_key: "meta.description"
|
||||||
index:
|
index:
|
||||||
priority: 100
|
priority: 2000
|
||||||
enable: true
|
enable: true
|
||||||
title_key: "meta.title"
|
title_key: "meta.title"
|
||||||
preamble_key: "meta.description"
|
preamble_key: "meta.description"
|
||||||
|
@@ -17,7 +17,7 @@ tools:
|
|||||||
title_key: "meta.title"
|
title_key: "meta.title"
|
||||||
description_key: "meta.description"
|
description_key: "meta.description"
|
||||||
index:
|
index:
|
||||||
priority: 100
|
priority: 3000
|
||||||
enable: true
|
enable: true
|
||||||
title_key: "meta.title"
|
title_key: "meta.title"
|
||||||
preamble_key: "meta.description"
|
preamble_key: "meta.description"
|
||||||
|
@@ -17,7 +17,7 @@ tools:
|
|||||||
title_key: "meta.title"
|
title_key: "meta.title"
|
||||||
description_key: "meta.description"
|
description_key: "meta.description"
|
||||||
index:
|
index:
|
||||||
priority: 100
|
priority: 1000
|
||||||
enable: true
|
enable: true
|
||||||
title_key: "meta.title"
|
title_key: "meta.title"
|
||||||
preamble_key: "meta.description"
|
preamble_key: "meta.description"
|
||||||
|
@@ -14,21 +14,21 @@
|
|||||||
|
|
||||||
{% block content_listing %}
|
{% block content_listing %}
|
||||||
|
|
||||||
{% for project_id, project_data in get_projects().items() %}
|
{% for project_data in get_sorted_projects_by_tags(requested_tags) %}
|
||||||
|
|
||||||
<hr class="subtle">
|
<hr class="subtle">
|
||||||
|
|
||||||
<!--<div class="p-s border r-m">-->
|
<!--<div class="p-s border r-m">-->
|
||||||
<div class="p-xs r-m">
|
<div class="p-xs r-m">
|
||||||
<a href="{{ l10n_url_abs('/content/' + project_id, raw_lang) }}" class="a-hidden">
|
<a href="{{ l10n_url_abs('/content/' + project_data.id, raw_lang) }}" class="a-hidden">
|
||||||
<div class="content-search-entry">
|
<div class="content-search-entry">
|
||||||
<img class="content-search-image mr-s r-l"
|
<img class="content-search-image mr-s r-l"
|
||||||
src="{{ url_for("static", filename=project_data.metadata.index.image_url) }}"
|
src="{{ url_for("static", filename=project_data.metadata.index.image_url) }}"
|
||||||
alt="TODO">
|
alt="TODO">
|
||||||
<h3 class="mb-xs">
|
<h3 class="mb-xs">
|
||||||
{{ l10n(project_data.metadata.index.title_key, project_id, user_lang) }}
|
{{ l10n(project_data.metadata.index.title_key, project_data.id, user_lang) }}
|
||||||
</h3>
|
</h3>
|
||||||
<p>{{ l10n(project_data.metadata.index.preamble_key, project_id, user_lang) }}</p>
|
<p>{{ l10n(project_data.metadata.index.preamble_key, project_data.id, user_lang) }}</p>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
@@ -14,20 +14,20 @@
|
|||||||
|
|
||||||
{% block content_listing %}
|
{% block content_listing %}
|
||||||
|
|
||||||
{% for tool_id, tool_data in get_tools().items() %}
|
{% for tool_data in get_sorted_tools_by_tags(requested_tags) %}
|
||||||
<hr class="subtle">
|
<hr class="subtle">
|
||||||
|
|
||||||
<!--<div class="p-s border r-m">-->
|
<!--<div class="p-s border r-m">-->
|
||||||
<div class="p-xs r-m">
|
<div class="p-xs r-m">
|
||||||
<a href="{{ l10n_url_abs('/tools/' + tool_id, raw_lang) }}" class="a-hidden">
|
<a href="{{ l10n_url_abs('/tools/' + tool_data.id, raw_lang) }}" class="a-hidden">
|
||||||
<div class="content-search-entry">
|
<div class="content-search-entry">
|
||||||
<img class="content-search-image mr-s r-l"
|
<img class="content-search-image mr-s r-l"
|
||||||
src="{{ url_for("static", filename=tool_data.metadata.index.image_url) }}"
|
src="{{ url_for("static", filename=tool_data.metadata.index.image_url) }}"
|
||||||
alt="TODO">
|
alt="TODO">
|
||||||
<h3 class="mb-xs">
|
<h3 class="mb-xs">
|
||||||
{{ l10n(tool_data.metadata.index.title_key, tool_id, user_lang) }}
|
{{ l10n(tool_data.metadata.index.title_key, tool_data.id, user_lang) }}
|
||||||
</h3>
|
</h3>
|
||||||
<p>{{ l10n(tool_data.metadata.index.preamble_key, tool_id, user_lang) }}</p>
|
<p>{{ l10n(tool_data.metadata.index.preamble_key, tool_data.id, user_lang) }}</p>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
@@ -25,12 +25,17 @@ def get_projects() -> LockedDict[str, ContentProject]:
|
|||||||
return __CONTENT.projects
|
return __CONTENT.projects
|
||||||
|
|
||||||
|
|
||||||
def get_projects_by_tags(tags: list[str]) -> dict[Any, ContentProject]:
|
def get_sorted_projects_by_tags(tags: Optional[list[str]]) -> list[ContentProject]:
|
||||||
project_obj: ContentProject
|
if tags is None:
|
||||||
return {
|
return sorted(__CONTENT.projects.values(), key=lambda x: x.metadata.index.priority, reverse=True)
|
||||||
project_key: project_value for project_key, project_value in __CONTENT.projects.items()
|
elif len(tags) == 0:
|
||||||
if any(tag in project_value.metadata.general.tags for tag in tags)
|
return sorted(__CONTENT.projects.values(), key=lambda x: x.metadata.index.priority, reverse=True)
|
||||||
}
|
else:
|
||||||
|
returned_list = [
|
||||||
|
x for x in __CONTENT.projects.values()
|
||||||
|
if any(tag in x.metadata.general.tags for tag in tags)
|
||||||
|
]
|
||||||
|
return sorted(returned_list, key=lambda x: x.metadata.index.priority, reverse=True)
|
||||||
|
|
||||||
|
|
||||||
def get_projects_by_languages(languages: list[str]) -> dict[Any, ContentProject]:
|
def get_projects_by_languages(languages: list[str]) -> dict[Any, ContentProject]:
|
||||||
@@ -49,12 +54,17 @@ def get_tools() -> LockedDict[str, ContentTool]:
|
|||||||
return __CONTENT.tools
|
return __CONTENT.tools
|
||||||
|
|
||||||
|
|
||||||
def get_tools_by_tags(tags: list[str]) -> dict[Any, ContentProject]:
|
def get_sorted_tools_by_tags(tags: Optional[list[str]]) -> list[ContentProject]:
|
||||||
tool_obj: ContentTool
|
if tags is None:
|
||||||
return {
|
return sorted(__CONTENT.tools.values(), key=lambda x: x.metadata.index.priority, reverse=True)
|
||||||
tool_key: tool_value for tool_key, tool_value in __CONTENT.tools.items()
|
elif len(tags) == 0:
|
||||||
if any(tag in tool_value.metadata.general.tags for tag in tags)
|
return sorted(__CONTENT.tools.values(), key=lambda x: x.metadata.index.priority, reverse=True)
|
||||||
}
|
else:
|
||||||
|
returned_list = [
|
||||||
|
x for x in __CONTENT.tools.values()
|
||||||
|
if any(tag in x.metadata.general.tags for tag in tags)
|
||||||
|
]
|
||||||
|
return sorted(returned_list, key=lambda x: x.metadata.index.priority, reverse=True)
|
||||||
|
|
||||||
|
|
||||||
def sanitize_input_tags(input_tags: str) -> list[str]:
|
def sanitize_input_tags(input_tags: str) -> list[str]:
|
||||||
@@ -108,30 +118,7 @@ def load_content_items() -> None:
|
|||||||
__CONTENT.projects[_project.id] = _project
|
__CONTENT.projects[_project.id] = _project
|
||||||
#print(_project)
|
#print(_project)
|
||||||
|
|
||||||
"""for project_item in os.listdir(os.path.join(os.getcwd(), "data/projects")):
|
# Loading tools definition files
|
||||||
project_item_path = os.path.join(os.getcwd(), "data/projects/", project_item)
|
|
||||||
if not os.path.isfile(project_item_path) or project_item.startswith("."):
|
|
||||||
continue
|
|
||||||
|
|
||||||
project_id = Path(project_item_path).stem
|
|
||||||
project_page_path = os.path.join(os.getcwd(), f"templates/projects/{project_id}.jinja")
|
|
||||||
|
|
||||||
if not all(os.path.isfile(project_file) for project_file in
|
|
||||||
[project_item_path, project_page_path]):
|
|
||||||
print(f"Unable to load project '{project_item}' due to missing files !")
|
|
||||||
continue
|
|
||||||
|
|
||||||
try:
|
|
||||||
__CONTENT_PROJECTS[project_id] = ContentProject(
|
|
||||||
id=project_id,
|
|
||||||
metadata=ContentMetadata(**yaml.safe_load(open(project_item_path))),
|
|
||||||
# strings=json.load(open(project_strings_path)) # Deprecated
|
|
||||||
)
|
|
||||||
print(f"Loaded project '{project_id}'")
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Unable to load project '{project_id}' due to an exception !")
|
|
||||||
print(e)"""
|
|
||||||
|
|
||||||
for tools_file in os.listdir(os.path.join(os.getcwd(), "data/tools")):
|
for tools_file in os.listdir(os.path.join(os.getcwd(), "data/tools")):
|
||||||
tools_file_path = os.path.join(os.getcwd(), "data/tools", tools_file)
|
tools_file_path = os.path.join(os.getcwd(), "data/tools", tools_file)
|
||||||
if not os.path.isfile(tools_file_path) or tools_file.startswith("."):
|
if not os.path.isfile(tools_file_path) or tools_file.startswith("."):
|
||||||
|
Reference in New Issue
Block a user