diff options
| author | 2021-11-05 10:09:35 +0530 | |
|---|---|---|
| committer | 2021-11-05 10:09:35 +0530 | |
| commit | 747a7b9cb465c85a064ac6e1a0444bcf8a81ec65 (patch) | |
| tree | 1bb529b764bed5c727a3956b7bb432a18ec82d43 /pydis_site/apps/events/urls.py | |
| parent | Merge branch 'main' into otn_softdel (diff) | |
| parent | Merge pull request #617 from python-discord/mbaruh-patch-1 (diff) | |
Pull from upstream/main and resolve conflicts.
Diffstat (limited to 'pydis_site/apps/events/urls.py')
| -rw-r--r-- | pydis_site/apps/events/urls.py | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/pydis_site/apps/events/urls.py b/pydis_site/apps/events/urls.py index 9a65cf1f..7ea65a31 100644 --- a/pydis_site/apps/events/urls.py +++ b/pydis_site/apps/events/urls.py @@ -1,9 +1,38 @@ -from django.urls import path +import typing +from pathlib import Path + +from django_distill import distill_path from pydis_site.apps.events.views import IndexView, PageView app_name = "events" + + +def __get_all_files(root: Path, folder: typing.Optional[Path] = None) -> list[str]: + """Find all folders and HTML files recursively starting from `root`.""" + if not folder: + folder = root + + results = [] + + for sub_folder in folder.iterdir(): + results.append( + sub_folder.relative_to(root).__str__().replace("\\", "/").replace(".html", "") + ) + + if sub_folder.is_dir(): + results.extend(__get_all_files(root, sub_folder)) + + return results + + +def get_all_events() -> typing.Iterator[dict[str, str]]: + """Yield a dict of all event pages.""" + for file in __get_all_files(Path("pydis_site", "templates", "events", "pages")): + yield {"path": file} + + urlpatterns = [ - path("", IndexView.as_view(), name="index"), - path("<path:path>/", PageView.as_view(), name="page"), + distill_path("", IndexView.as_view(), name="index"), + distill_path("<path:path>/", PageView.as_view(), name="page", distill_func=get_all_events), ] |