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" __tablename__ = "group_wiki_pages"
BASE_PATH = "/var/lib/tildes-wiki" BASE_PATH = "/var/lib/tildes-wiki"
GITLAB_REPO_URL = "https://gitlab.com/tildes/tildes-wiki"
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
@ -89,7 +90,22 @@ class GroupWikiPage(DatabaseModel):
@property @property
def file_path(self) -> Path: def file_path(self) -> Path:
"""Return the full path to the page's file.""" """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 @property
def markdown(self) -> Optional[str]: def markdown(self) -> Optional[str]:

4
tildes/tildes/templates/group_wiki_page.jinja2

@ -29,6 +29,10 @@
<dl> <dl>
<dt>Last edited</dt> <dt>Last edited</dt>
<dd>{{ adaptive_date_responsive(page.last_edited_time) }}</dd> <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> </dl>
{% if request.has_permission("edit", page) %} {% if request.has_permission("edit", page) %}

Loading…
Cancel
Save