From 672856e9af57bc4356c8d10d9c23832e2409c06e Mon Sep 17 00:00:00 2001 From: Matthew Scragg Date: Thu, 9 Oct 2014 15:47:12 -0500 Subject: [PATCH] Add index page resolves #23 and #8 --- bower.json | 4 +++- manage.py | 15 +++++++++++++-- realms/__init__.py | 3 +++ realms/modules/wiki/models.py | 34 +++++++++++++++++++++++++++------- realms/modules/wiki/views.py | 5 +++++ realms/templates/layout.html | 3 +++ 6 files changed, 54 insertions(+), 10 deletions(-) diff --git a/bower.json b/bower.json index 2c0846e..e1d2699 100644 --- a/bower.json +++ b/bower.json @@ -14,6 +14,8 @@ "js-yaml": "~3.2.1", "store-js": "~1.3.16", "bootswatch-dist": "3.2.0-flatly", - "bootbox": "4.3.0" + "bootbox": "4.3.0", + "datatables": "1.10.3", + "datatables-plugins": "latest" } } \ No newline at end of file diff --git a/manage.py b/manage.py index 161f9ee..67b8736 100755 --- a/manage.py +++ b/manage.py @@ -81,11 +81,15 @@ def setup_redis(**kw): install_redis() +def get_prefix(): + import sys + return sys.prefix + + def get_pip(): """ Get virtualenv path for pip """ - import sys - return sys.prefix + '/bin/pip' + return get_prefix() + '/bin/pip' @cli.command() @@ -173,6 +177,13 @@ def drop_db(): db.drop_all() +@cli.command() +def test(): + """ Run tests + """ + call([get_prefix() + "/bin/nosetests", config.APP_PATH]) + + @cli.command() def version(): """ Output version diff --git a/realms/__init__.py b/realms/__init__.py index de30b1b..c16d4e4 100644 --- a/realms/__init__.py +++ b/realms/__init__.py @@ -206,6 +206,8 @@ assets.register('main.js', 'js/html-sanitizer-minified.js', # don't minify? 'vendor/highlightjs/highlight.pack.js', 'vendor/parsleyjs/dist/parsley.js', + 'vendor/datatables/media/js/jquery.dataTables.js', + 'vendor/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.js', 'js/hbs-helpers.js', 'js/mdr.js') @@ -213,6 +215,7 @@ assets.register('main.css', 'vendor/bootswatch-dist/css/bootstrap.css', 'vendor/components-font-awesome/css/font-awesome.css', 'vendor/highlightjs/styles/github.css', + 'vendor/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.css', 'css/style.css') app.discover() diff --git a/realms/modules/wiki/models.py b/realms/modules/wiki/models.py index 3545666..6f87a20 100644 --- a/realms/modules/wiki/models.py +++ b/realms/modules/wiki/models.py @@ -13,6 +13,16 @@ from realms import cache from realms.lib.hook import HookMixin +def cname_to_filename(cname): + return cname.lower() + ".md" + + +def filename_to_cname(filename): + """ It's assumed filename is already cname format + """ + return os.path.splitext(filename)[0] + + class Wiki(HookMixin): path = None base_path = '/' @@ -87,7 +97,7 @@ class Wiki(HookMixin): content = re.sub(r"```(.*?)```", unescape_repl, content, flags=re.DOTALL) - filename = self.cname_to_filename(cname) + filename = cname_to_filename(cname) with open(self.path + "/" + filename, 'w') as f: f.write(content) @@ -113,7 +123,7 @@ class Wiki(HookMixin): return ret def rename_page(self, old_name, new_name, user=None): - old_filename, new_filename = map(self.cname_to_filename, [old_name, new_name]) + old_filename, new_filename = map(cname_to_filename, [old_name, new_name]) if old_filename not in self.gittle.index: # old doesn't exist return None @@ -140,7 +150,7 @@ class Wiki(HookMixin): return cached # commit = gittle.utils.git.commit_info(self.repo[sha]) - filename = self.cname_to_filename(name).encode('latin-1') + filename = cname_to_filename(name).encode('latin-1') sha = sha.encode('latin-1') try: @@ -177,8 +187,21 @@ class Wiki(HookMixin): new = self.get_page(name, sha=new_sha) return ghdiff.diff(old['data'], new['data']) + def get_index(self): + rv = [] + index = self.repo.open_index() + for name in index: + rv.append(dict(name=filename_to_cname(name), + filename=name, + ctime=index[name].ctime[0], + mtime=index[name].mtime[0], + sha=index[name].sha, + size=index[name].size)) + + return rv + def get_history(self, name, limit=100): - file_path = self.cname_to_filename(name) + file_path = cname_to_filename(name) versions = [] walker = self.repo.get_walker(paths=[file_path], max_entries=limit) for entry in walker: @@ -198,6 +221,3 @@ class Wiki(HookMixin): return versions - @staticmethod - def cname_to_filename(cname): - return cname.lower() + ".md" \ No newline at end of file diff --git a/realms/modules/wiki/views.py b/realms/modules/wiki/views.py index e1247d0..503dd7b 100644 --- a/realms/modules/wiki/views.py +++ b/realms/modules/wiki/views.py @@ -121,6 +121,11 @@ def create(name): info={}) +@blueprint.route("/_index") +def index(): + return render_template('wiki/index.html', index=g.current_wiki.get_index()) + + @blueprint.route("/", defaults={'name': 'home'}) @blueprint.route("/") def page(name): diff --git a/realms/templates/layout.html b/realms/templates/layout.html index 51c20c3..665ba8b 100644 --- a/realms/templates/layout.html +++ b/realms/templates/layout.html @@ -40,6 +40,9 @@