Browse Source

Wiki page sidebar: add GitLab history/blame links

merge-requests/70/head
Deimos 6 years ago
parent
commit
edda04afdd
  1. 18
      tildes/tildes/models/group/group_wiki_page.py
  2. 4
      tildes/tildes/templates/group_wiki_page.jinja2

18
tildes/tildes/models/group/group_wiki_page.py

@ -31,6 +31,7 @@ class GroupWikiPage(DatabaseModel):
__tablename__ = "group_wiki_pages"
BASE_PATH = "/var/lib/tildes-wiki"
GITLAB_REPO_URL = "https://gitlab.com/tildes/tildes-wiki"
group_id: int = Column(
Integer, ForeignKey("groups.group_id"), nullable=False, primary_key=True
@ -89,7 +90,22 @@ class GroupWikiPage(DatabaseModel):
@property
def file_path(self) -> Path:
"""Return the full path to the page's file."""
return Path(self.BASE_PATH, str(self.group.path), f"{self.slug}.md")
return Path(self.BASE_PATH, self.relative_path)
@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")
@property
def history_url(self) -> str:
"""Return a url to the page's edit history."""
return f"{self.GITLAB_REPO_URL}/commits/master/{self.relative_path}"
@property
def blame_url(self) -> str:
"""Return a url to the page's blame view."""
return f"{self.GITLAB_REPO_URL}/blame/master/{self.relative_path}"
@property
def markdown(self) -> Optional[str]:

4
tildes/tildes/templates/group_wiki_page.jinja2

@ -29,6 +29,10 @@
<dl>
<dt>Last edited</dt>
<dd>{{ adaptive_date_responsive(page.last_edited_time) }}</dd>
<dt>Edit history (on GitLab)</dt>
<dd><a href="{{ page.history_url }}" target="_blank">Full edit history</a></dd>
<dd><a href="{{ page.blame_url }}" target="_blank">Line-by-line ("blame") view</a></dd>
</dl>
{% if request.has_permission("edit", page) %}

Loading…
Cancel
Save