From a64a4ca58cedd0a8bec25a06e9e078408b5fc928 Mon Sep 17 00:00:00 2001 From: Deimos Date: Sat, 10 Aug 2019 11:20:12 -0600 Subject: [PATCH] GroupWikiPage: add slug property Not needed for much yet, but should be used here anyway to prevent "new_page" pages from being created inside folders (which isn't possible yet anyway). --- tildes/tildes/models/group/group_wiki_page.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tildes/tildes/models/group/group_wiki_page.py b/tildes/tildes/models/group/group_wiki_page.py index 18d8998..a44d7c4 100644 --- a/tildes/tildes/models/group/group_wiki_page.py +++ b/tildes/tildes/models/group/group_wiki_page.py @@ -61,7 +61,7 @@ class GroupWikiPage(DatabaseModel): self.path = convert_to_url_slug(page_name) # prevent possible conflict with url for creating a new page - if self.path == "new_page": + if self.slug == "new_page": raise ValueError("Invalid page name") if self.file_path.exists(): @@ -99,6 +99,11 @@ class GroupWikiPage(DatabaseModel): """Return a relative path to the page's file.""" return Path(str(self.group.path), f"{self.path}.md") + @property + def slug(self) -> str: + """Return the page's slug, which is also its filename with no extension.""" + return self.file_path.stem + @property def history_url(self) -> str: """Return a url to the page's edit history."""