fietsboek.pages module¶
Module containing logic to support “static” pages.
- class fietsboek.pages.Page(slug, title, content, link_name, locale_filter=None, user_filter=UserFilter.EVERYONE, menu_index=0)¶
Bases:
object
Represents a loaded page.
- Variables:
slug (str) – The page’s slug (URL identifier)
content (str) – The page’s content as HTML.
link_name (str) – The name of the site to show in the menu.
locale_filter (Optional[List[re.Pattern]]) – An (optional) pattern that determines whether the page should be shown to certain locales only.
user_filter (UserFilter) – A filter that determines if the page should be shown to certain users only.
menu_index (int) – The index in the menu.
- matches(request)¶
Checks whether the page matches the given request regarding the locale and user filters.
- classmethod parse(text)¶
Parses a
Page
from the given textual source.This populates all metadata with the metadata from the file.
- Raises:
PageException – If there are missing metadata fields.
- Parameters:
text (
str
) – Source to parse.- Return type:
- Returns:
The parsed page.
- exception fietsboek.pages.PageException¶
Bases:
Exception
Exception that is raised when parsing a
Page
fails.
- class fietsboek.pages.Pages¶
Bases:
object
A class that loads static pages from paths and providing easy access for other parts of Fietsboek.
- find(slug, request=None)¶
Finds the page matching the given slug.
If a request is given, the filtering based on locale/logged in state is applied.
If multiple pages are found, the first found one is returned. If no page is found,
None
is returned.
- load_directory(path)¶
Load a directory full of pages.
This attemps to load and file in the given directory ending with “.md”.
- Parameters:
path (
Path
) – The path of the directory to load.- Raises:
PageException – If a page is malformed.
- load_file(path)¶
Load a page from a file.
- Parameters:
path (
Path
) – The path of the file to load.- Raises:
PageException – If the page is malformed.
Return all items that should appear after Fietsboek’s main menu.
- class fietsboek.pages.UserFilter(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)¶
Bases:
Enum
Filter that determines to which users a page should be shown.
- EVERYONE = 3¶
Shows the page to everyone.
- LOGGED_IN = 1¶
Shows the page only to logged in users.
- LOGGED_OUT = 2¶
Shows the page only to logged in users.