Browse Source

Rename GroupWikiPage.slug to path

"Path" is more correct now if there can be folders involved. I'll
probably want to add a slug property back, which can be parsed out of
the path.
merge-requests/76/merge
Deimos 5 years ago
parent
commit
52c7cb1586
  1. 24
      tildes/alembic/versions/f20ce28b1d5c_rename_group_wiki_pages_slug_to_path.py
  2. 12
      tildes/tildes/models/group/group_wiki_page.py
  3. 8
      tildes/tildes/resources/group.py
  4. 10
      tildes/tildes/routes.py
  5. 2
      tildes/tildes/templates/group_wiki.jinja2
  6. 6
      tildes/tildes/templates/group_wiki_edit_page.jinja2
  7. 6
      tildes/tildes/templates/group_wiki_page.jinja2
  8. 4
      tildes/tildes/templates/topic_listing.jinja2
  9. 12
      tildes/tildes/views/group_wiki_page.py
  10. 6
      tildes/tildes/views/topic.py

24
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")

12
tildes/tildes/models/group/group_wiki_page.py

@ -38,7 +38,7 @@ class GroupWikiPage(DatabaseModel):
group_id: int = Column( group_id: int = Column(
Integer, ForeignKey("groups.group_id"), nullable=False, primary_key=True 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( page_name: str = Column(
Text, Text,
CheckConstraint( CheckConstraint(
@ -58,10 +58,10 @@ class GroupWikiPage(DatabaseModel):
"""Create a new wiki page.""" """Create a new wiki page."""
self.group = group self.group = group
self.page_name = page_name 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 # 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") raise ValueError("Invalid page name")
if self.file_path.exists(): if self.file_path.exists():
@ -97,7 +97,7 @@ class GroupWikiPage(DatabaseModel):
@property @property
def relative_path(self) -> Path: def relative_path(self) -> Path:
"""Return a relative path to the page's file.""" """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 @property
def history_url(self) -> str: 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.add(str(self.file_path.relative_to(self.BASE_PATH)))
repo.index.write() 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 # 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.create_commit(
repo.head.name, repo.head.name,

8
tildes/tildes/resources/group.py

@ -35,13 +35,13 @@ def group_by_path(request: Request, path: str) -> Group:
return get_resource(request, query) 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 group = group_by_path(request) # pylint: disable=no-value-for-parameter
query = request.query(GroupWikiPage).filter( 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) return get_resource(request, query)

10
tildes/tildes/routes.py

@ -10,7 +10,7 @@ from pyramid.request import Request
from pyramid.security import Allow, Authenticated from pyramid.security import Allow, Authenticated
from tildes.resources.comment import comment_by_id36, notification_by_comment_id36 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.message import message_conversation_by_id36
from tildes.resources.topic import topic_by_id36 from tildes.resources.topic import topic_by_id36
from tildes.resources.user import user_by_username from tildes.resources.user import user_by_username
@ -46,14 +46,14 @@ def includeme(config: Configurator) -> None:
config.add_route( config.add_route(
"group_wiki_edit_page", "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( config.add_route(
"group_wiki_page", "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 # these routes need to remain last inside this block

2
tildes/tildes/templates/group_wiki.jinja2

@ -18,7 +18,7 @@
<ul> <ul>
{% for page in page_list %} {% for page in page_list %}
<li> <li>
<a href="{{ request.route_url("group_wiki_page", group_path=group.path, wiki_page_slug=page.slug) }}">{{ page.page_name }}</a>
<a href="{{ request.route_url("group_wiki_page", group_path=group.path, wiki_page_path=page.path) }}">{{ page.page_name }}</a>
<div class="text-small text-secondary">Last edited: {{ adaptive_date_responsive(page.last_edited_time) }}</div> <div class="text-small text-secondary">Last edited: {{ adaptive_date_responsive(page.last_edited_time) }}</div>
</li> </li>
{% endfor %} {% endfor %}

6
tildes/tildes/templates/group_wiki_edit_page.jinja2

@ -17,8 +17,8 @@
<form <form
method="post" method="post"
autocomplete="off" autocomplete="off"
action="/~{{ page.group.path }}/wiki/{{ page.slug }}"
data-ic-post-to="/~{{ page.group.path }}/wiki/{{ page.slug }}"
action="/~{{ page.group.path }}/wiki/{{ page.path }}"
data-ic-post-to="/~{{ page.group.path }}/wiki/{{ page.path }}"
data-js-prevent-double-submit data-js-prevent-double-submit
data-js-confirm-leave-page-unsaved data-js-confirm-leave-page-unsaved
> >
@ -31,7 +31,7 @@
<div class="form-group"> <div class="form-group">
<label class="form-label" for="edit_message">Short edit summary</label> <label class="form-label" for="edit_message">Short edit summary</label>
<div class="input-group"> <div class="input-group">
<span class="input-group-addon">~{{ page.group.path }}/{{ page.slug }}:</span>
<span class="input-group-addon">~{{ page.group.path }}/{{ page.path }}:</span>
<input class="form-input" id="edit_message" name="edit_message" type="text" placeholder="Edit summary" maxlength="80" required> <input class="form-input" id="edit_message" name="edit_message" type="text" placeholder="Edit summary" maxlength="80" required>
</div> </div>
</div> </div>

6
tildes/tildes/templates/group_wiki_page.jinja2

@ -36,17 +36,17 @@
</dl> </dl>
{% if request.has_permission("edit", page) %} {% if request.has_permission("edit", page) %}
<a href="{{ request.route_url("group_wiki_edit_page", group_path=page.group.path, wiki_page_slug=page.slug) }}" class="btn btn-primary">Edit this page</a>
<a href="{{ request.route_url("group_wiki_edit_page", group_path=page.group.path, wiki_page_path=page.path) }}" class="btn btn-primary">Edit this page</a>
{% endif %} {% endif %}
<ul class="nav"> <ul class="nav">
<li>Page list</li> <li>Page list</li>
<ul class="nav"> <ul class="nav">
{% if has_index_page %} {% if has_index_page %}
<li class="nav-item"><a href="{{ request.route_url("group_wiki_page", group_path=page.group.path, wiki_page_slug="index") }}" class="text-bold">index</a></li>
<li class="nav-item"><a href="{{ request.route_url("group_wiki_page", group_path=page.group.path, wiki_page_path="index") }}" class="text-bold">index</a></li>
{% endif %} {% endif %}
{% for other_page in page_list %} {% for other_page in page_list %}
<li class="nav-item"><a href="{{ request.route_url("group_wiki_page", group_path=other_page.group.path, wiki_page_slug=other_page.slug) }}">{{ other_page.page_name }}</a></li>
<li class="nav-item"><a href="{{ request.route_url("group_wiki_page", group_path=other_page.group.path, wiki_page_path=other_page.path) }}">{{ other_page.page_name }}</a></li>
{% endfor %} {% endfor %}
</ul> </ul>
</ul> </ul>

4
tildes/tildes/templates/topic_listing.jinja2

@ -229,10 +229,10 @@
<li>Group wiki pages</li> <li>Group wiki pages</li>
<ul class="nav"> <ul class="nav">
{% if wiki_has_index %} {% if wiki_has_index %}
<li class="nav-item"><a href="{{ request.route_url("group_wiki_page", group_path=group.path, wiki_page_slug="index") }}" class="text-bold">index</a></li>
<li class="nav-item"><a href="{{ request.route_url("group_wiki_page", group_path=group.path, wiki_page_path="index") }}" class="text-bold">index</a></li>
{% endif %} {% endif %}
{% for page in wiki_pages %} {% for page in wiki_pages %}
<li class="nav-item"><a href="{{ request.route_url("group_wiki_page", group_path=group.path, wiki_page_slug=page.slug) }}">{{ page.page_name }}</a></li>
<li class="nav-item"><a href="{{ request.route_url("group_wiki_page", group_path=group.path, wiki_page_path=page.path) }}">{{ page.page_name }}</a></li>
{% endfor %} {% endfor %}
</ul> </ul>
</ul> </ul>

12
tildes/tildes/views/group_wiki_page.py

@ -21,7 +21,7 @@ def get_group_wiki(request: Request) -> dict:
page_list = ( page_list = (
request.query(GroupWikiPage) request.query(GroupWikiPage)
.filter(GroupWikiPage.group == group) .filter(GroupWikiPage.group == group)
.order_by(GroupWikiPage.slug)
.order_by(GroupWikiPage.path)
.all() .all()
) )
@ -36,14 +36,14 @@ def get_group_wiki_page(request: Request) -> dict:
page_list = ( page_list = (
request.query(GroupWikiPage) request.query(GroupWikiPage)
.filter(GroupWikiPage.group == page.group) .filter(GroupWikiPage.group == page.group)
.order_by(GroupWikiPage.slug)
.order_by(GroupWikiPage.path)
.all() .all()
) )
# remove the index from the page list, we'll output it separately # remove the index from the page list, we'll output it separately
if any(page.slug == "index" for page in page_list):
if any(page.path == "index" for page in page_list):
has_index_page = True has_index_page = True
page_list = [page for page in page_list if page.slug != "index"]
page_list = [page for page in page_list if page.path != "index"]
else: else:
has_index_page = False has_index_page = False
@ -76,7 +76,7 @@ def post_group_wiki(request: Request, page_name: str, markdown: str) -> HTTPFoun
raise HTTPFound( raise HTTPFound(
location=request.route_url( location=request.route_url(
"group_wiki_page", group_path=group.path, wiki_page_slug=new_page.slug
"group_wiki_page", group_path=group.path, wiki_page_path=new_page.path
) )
) )
@ -104,6 +104,6 @@ def post_group_wiki_page(request: Request, markdown: str, edit_message: str) ->
raise HTTPFound( raise HTTPFound(
location=request.route_url( location=request.route_url(
"group_wiki_page", group_path=page.group.path, wiki_page_slug=page.slug
"group_wiki_page", group_path=page.group.path, wiki_page_path=page.path
) )
) )

6
tildes/tildes/views/topic.py

@ -211,14 +211,14 @@ def get_group_topics(
wiki_pages = ( wiki_pages = (
request.query(GroupWikiPage) request.query(GroupWikiPage)
.filter(GroupWikiPage.group == request.context) .filter(GroupWikiPage.group == request.context)
.order_by(GroupWikiPage.slug)
.order_by(GroupWikiPage.path)
.all() .all()
) )
# remove the index from the page list, we'll output it separately # remove the index from the page list, we'll output it separately
if any(page.slug == "index" for page in wiki_pages):
if any(page.path == "index" for page in wiki_pages):
wiki_has_index = True wiki_has_index = True
wiki_pages = [page for page in wiki_pages if page.slug != "index"]
wiki_pages = [page for page in wiki_pages if page.path != "index"]
else: else:
wiki_has_index = False wiki_has_index = False
else: else:

Loading…
Cancel
Save