diff --git a/tildes/alembic/versions/f20ce28b1d5c_rename_group_wiki_pages_slug_to_path.py b/tildes/alembic/versions/f20ce28b1d5c_rename_group_wiki_pages_slug_to_path.py new file mode 100644 index 0000000..bc99525 --- /dev/null +++ b/tildes/alembic/versions/f20ce28b1d5c_rename_group_wiki_pages_slug_to_path.py @@ -0,0 +1,24 @@ +"""Rename group_wiki_pages.slug to path + +Revision ID: f20ce28b1d5c +Revises: cddd7d7ed0ea +Create Date: 2019-08-10 04:40:04.657360 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = "f20ce28b1d5c" +down_revision = "cddd7d7ed0ea" +branch_labels = None +depends_on = None + + +def upgrade(): + op.alter_column("group_wiki_pages", "slug", new_column_name="path") + + +def downgrade(): + op.alter_column("group_wiki_pages", "path", new_column_name="slug") diff --git a/tildes/tildes/models/group/group_wiki_page.py b/tildes/tildes/models/group/group_wiki_page.py index fd710a7..18d8998 100644 --- a/tildes/tildes/models/group/group_wiki_page.py +++ b/tildes/tildes/models/group/group_wiki_page.py @@ -38,7 +38,7 @@ class GroupWikiPage(DatabaseModel): group_id: int = Column( Integer, ForeignKey("groups.group_id"), nullable=False, primary_key=True ) - slug: str = Column(CIText, nullable=False, primary_key=True) + path: str = Column(CIText, nullable=False, primary_key=True) page_name: str = Column( Text, CheckConstraint( @@ -58,10 +58,10 @@ class GroupWikiPage(DatabaseModel): """Create a new wiki page.""" self.group = group self.page_name = page_name - self.slug = convert_to_url_slug(page_name) + self.path = convert_to_url_slug(page_name) # prevent possible conflict with url for creating a new page - if self.slug == "new_page": + if self.path == "new_page": raise ValueError("Invalid page name") if self.file_path.exists(): @@ -97,7 +97,7 @@ class GroupWikiPage(DatabaseModel): @property def relative_path(self) -> Path: """Return a relative path to the page's file.""" - return Path(str(self.group.path), f"{self.slug}.md") + return Path(str(self.group.path), f"{self.path}.md") @property def history_url(self) -> str: @@ -143,9 +143,9 @@ class GroupWikiPage(DatabaseModel): repo.index.add(str(self.file_path.relative_to(self.BASE_PATH))) repo.index.write() - # Prepend the group name and page slug to the edit message - if you change the + # Prepend the group name and page path to the edit message - if you change the # format of this, make sure to also change the page-editing template to match - edit_message = f"~{self.group.path}/{self.slug}: {edit_message}" + edit_message = f"~{self.group.path}/{self.path}: {edit_message}" repo.create_commit( repo.head.name, diff --git a/tildes/tildes/resources/group.py b/tildes/tildes/resources/group.py index ef0172a..5d35ba7 100644 --- a/tildes/tildes/resources/group.py +++ b/tildes/tildes/resources/group.py @@ -35,13 +35,13 @@ def group_by_path(request: Request, path: str) -> Group: return get_resource(request, query) -@use_kwargs({"wiki_page_slug": String()}, locations=("matchdict",)) -def group_wiki_page_by_slug(request: Request, wiki_page_slug: str) -> GroupWikiPage: - """Get a group's wiki page by its url slug (or 404).""" +@use_kwargs({"wiki_page_path": String()}, locations=("matchdict",)) +def group_wiki_page_by_path(request: Request, wiki_page_path: str) -> GroupWikiPage: + """Get a group's wiki page by its path (or 404).""" group = group_by_path(request) # pylint: disable=no-value-for-parameter query = request.query(GroupWikiPage).filter( - GroupWikiPage.group == group, GroupWikiPage.slug == wiki_page_slug + GroupWikiPage.group == group, GroupWikiPage.path == wiki_page_path ) return get_resource(request, query) diff --git a/tildes/tildes/routes.py b/tildes/tildes/routes.py index 2d9ce14..4118d5e 100644 --- a/tildes/tildes/routes.py +++ b/tildes/tildes/routes.py @@ -10,7 +10,7 @@ from pyramid.request import Request from pyramid.security import Allow, Authenticated from tildes.resources.comment import comment_by_id36, notification_by_comment_id36 -from tildes.resources.group import group_by_path, group_wiki_page_by_slug +from tildes.resources.group import group_by_path, group_wiki_page_by_path from tildes.resources.message import message_conversation_by_id36 from tildes.resources.topic import topic_by_id36 from tildes.resources.user import user_by_username @@ -46,14 +46,14 @@ def includeme(config: Configurator) -> None: config.add_route( "group_wiki_edit_page", - "/wiki/{wiki_page_slug:.*?}/edit", - factory=group_wiki_page_by_slug, + "/wiki/{wiki_page_path:.*?}/edit", + factory=group_wiki_page_by_path, ) config.add_route( "group_wiki_page", - "/wiki/{wiki_page_slug:.*}", - factory=group_wiki_page_by_slug, + "/wiki/{wiki_page_path:.*}", + factory=group_wiki_page_by_path, ) # these routes need to remain last inside this block diff --git a/tildes/tildes/templates/group_wiki.jinja2 b/tildes/tildes/templates/group_wiki.jinja2 index 0783abf..7cc5a3c 100644 --- a/tildes/tildes/templates/group_wiki.jinja2 +++ b/tildes/tildes/templates/group_wiki.jinja2 @@ -18,7 +18,7 @@