-
Notifications
You must be signed in to change notification settings - Fork 3
Issues 78-80, 25 #81
base: master
Are you sure you want to change the base?
Issues 78-80, 25 #81
Changes from 66 commits
83cb9cc
3ad8517
69855ec
62b42e1
652e5b4
c450a00
23a2341
f1f6012
263c1d8
447f01c
f9b1b39
ef1eddb
93220e9
a788600
9c82e5b
aae73d2
e467d68
140e84c
f2fa2ff
52a1b9c
8fe387a
d644c3e
eafcdfe
5135258
382434a
c20008e
302e734
11cb19e
b3fcb5d
90c2a4f
a282a02
fa1681d
d590c31
5ed344b
0a4a1d4
a4a2d2d
dec0bb1
8651e63
870a305
8adc66e
df096eb
bf5c080
20a6590
3ad61a4
e988169
d596a6c
c8ea21b
539698c
f115332
366f0b9
81b39f5
3ce08e7
c79b3a2
41f1ded
9385621
8ce0381
ee9c098
0fba5fb
a7fc457
d030827
5b761f7
56bb645
dfd8763
72d81e5
36f5ee8
db1c91e
de04840
f1c95ae
615b2ac
93a3ba9
a1141bb
442381b
a8190ec
f30995d
31c0537
3f9090c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
"""Wiki controller module""" | ||
from tg import expose | ||
|
||
from acmwebsite.lib.base import BaseController | ||
|
||
from pygit2 import Repository,init_repository | ||
from pygit2 import Tree | ||
from pygit2 import Signature | ||
import pygit2 as pg | ||
|
||
from docutils.core import publish_parts | ||
|
||
import os | ||
import tg | ||
|
||
__all__ = ['WikiController'] | ||
|
||
class WikiController(BaseController): | ||
"""Controls the wiki""" | ||
|
||
def _before(self, *args, **kw): | ||
try: | ||
repo_path = tg.config.get('wiki.repo') | ||
if not repo_path: | ||
tg.abort(400, "Wiki not enabled") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 404 |
||
self.repo = Repository(repo_path) | ||
except pg.GitError: | ||
self._init_wiki_repo() | ||
|
||
def _init_wiki_repo(self): | ||
self.repo = init_repository(tg.config.get('wiki.repo'), True) | ||
signature = Signature("Example McPersonson", "[email protected]") #TODO: Replace me | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Explain? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Explain what - the TODO? If so - I just mean that this Signature can be replaced if need be, though it is only used for the inital commit. Presumably page commits using the web editor (once implemented) will pull signature details from the logged in profile. |
||
|
||
tb = self.repo.TreeBuilder() | ||
|
||
# Create blob from frontpage content and insert into tree | ||
from pkg_resources import resource_filename | ||
filename = "FrontPage.rst" | ||
filepath = resource_filename('acmwebsite', 'wiki-assets/FrontPage.rst') | ||
blobid = self.repo.create_blob_fromdisk(filepath) | ||
tb.insert(filename, blobid, pg.GIT_FILEMODE_BLOB) | ||
tree = tb.write() | ||
|
||
# Commit the change | ||
branch_commit = self.repo.create_commit( | ||
'HEAD', | ||
signature, | ||
signature, | ||
"Initial commit", | ||
tree, | ||
[] | ||
) | ||
|
||
@expose('acmwebsite.templates.wiki_view') | ||
def _default(self, pagename): | ||
"""Display a specific page""" | ||
settings = {'initial_header_level': 2, | ||
'file_insertion_enabled': 0, | ||
'raw_enabled': 0, | ||
'disable_config': 1, | ||
} | ||
|
||
tb = self.repo.TreeBuilder(self.repo.head.peel(Tree)) | ||
if not tb.get(pagename + '.rst'): | ||
tg.abort(404, "Page not found") | ||
blob = self.repo.get(self.repo.head.peel(Tree)[pagename + '.rst'].id) | ||
document = publish_parts(blob.data, writer_name='html5', settings_overrides=settings) | ||
return dict(pagename=pagename, parts=document) | ||
|
||
@expose('acmwebsite.templates.wiki_history') | ||
def history(self, pagename): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we do in OO-manner like user profile controller? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See f30995d - I attempted to follow the style of the user controller but it still seems a little dirty to me. Let me know what you think. I moved the repo check/initialization logic from WikiController to WikiPagesController, but I had to change _before to init as it seems WikiPagesController wasn't calling _before like WikiController did. |
||
filename = pagename + ".rst" | ||
revision_list = [] | ||
last_id = None | ||
|
||
#Get a list of commits that include the queried file | ||
for commit in self.repo.walk(self.repo.head.target, pg.GIT_SORT_TIME): | ||
if filename in commit.tree: | ||
entry = commit.tree[filename] | ||
if entry.id != last_id: #Only add to history if it file chnaged. | ||
revision_list.append({"author": commit.author, | ||
"time": commit.commit_time, | ||
"message": commit.message}) | ||
last_id = entry.id | ||
|
||
if not revision_list: #No commits include file - possibly faulty? | ||
tg.abort(404, "Page not found") | ||
return dict(page=pagename, revisions=revision_list) | ||
|
||
@expose('acmwebsite.templates.wiki_pagelist') | ||
def pagelist(self): | ||
pages = [entry.name[:-4] for entry in self.repo.head.peel(Tree)] | ||
return dict(pages=pages) | ||
|
||
|
||
@expose() | ||
def index(self): | ||
"""Display the wiki frontpage""" | ||
tg.redirect('/wiki/FrontPage') |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,14 +9,15 @@ | |
<link id='bs-css' rel="stylesheet" type="text/css" media="screen" href="${tg.url('/css/bootstrap.dark.min.css') if tg.session.get('theme', None) == 'dark' else tg.url('/css/bootstrap.light.min.css')}" /> | ||
<link rel="stylesheet" type="text/css" media="screen" href="${tg.url('/css/style.css')}" /> | ||
<link rel="stylesheet" type="text/css" media="screen" href="${tg.url('/css/font-awesome.min.css')}" /> | ||
<link rel="stylesheet" type="text/css" media="screen" href="${tg.url('/css/site.css')}" /> | ||
</head> | ||
|
||
<body> | ||
<!-- Navbar --> | ||
<div class="container"> | ||
<div class="header-logo"> | ||
<a href="${tg.url('/')}"> | ||
<img src="${tg.url('/img/full.svg')}" alt="Mines ACM" class="acm-logo" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Careful ... Was css class adjusted as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed acm-logo to logo in style.css |
||
<img src="/img/full.svg" alt="${tg.config.get('site.name')}" class="logo" /> | ||
</a> | ||
</div> | ||
</div> | ||
|
@@ -38,6 +39,7 @@ | |
<li class="${('', 'active')[value_of('page') == 'projects']}"><a href="${tg.url('/projects')}">Projects</a></li> | ||
<li class="${('', 'active')[value_of('page') == 'mailinglist']}"><a href="${tg.url('/mailinglist')}">Mailing List</a></li> | ||
<li class="${('', 'active')[value_of('page') == 'contact']}"><a href="${tg.url('/contact')}">Contact</a></li> | ||
<li class="${('', 'active')[value_of('page') == 'wiki']}"><a href="${tg.url('/wiki')}">Wiki</a></li> | ||
</ul> | ||
|
||
<ul py:if="not value_of('luser')" class="nav navbar-nav navbar-right"> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<html py:strip="" | ||
xmlns:py="http://genshi.edgewall.org/" | ||
xmlns:xi="http://www.w3.org/2001/XInclude"> | ||
|
||
<py:extends href="master.xhtml" /> | ||
|
||
<head py:block="head" py:strip="True"> | ||
<title>${tg.config.get('site.name')} Wiki - $page History</title> | ||
</head> | ||
|
||
<body py:block="body" py:strip="True"> | ||
<py:def function="revision(item)"> | ||
<td> | ||
${item["message"]} | ||
</td> | ||
<td> | ||
${item["author"].name} | ||
</td> | ||
<td> | ||
${item["time"]} | ||
</td> | ||
</py:def> | ||
|
||
|
||
<h1 class="page-header">History: <a href="${tg.url('/wiki/%s' % page)}">$page</a></h1> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not use oldstyle string formatting |
||
|
||
<table class="table table-striped"> | ||
<thead> | ||
<tr> | ||
<th>Commit Message</th> | ||
<th>Author</th> | ||
<th>Commit time</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr py:for="entry in revisions">${revision(entry)}</tr> | ||
</tbody> | ||
</table> | ||
</body> | ||
</html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import modules before from import