Diff between 56c30ed7bdcbcae5c2663c09971cc173222f8424 and d0889c4c705495aac5d22616c2d21281282d70f1

Changed Files

File Additions Deletions Status
app.py +14 -0 modified
git/blame.py +1 -0 modified
templates/blame.html +1 -1 modified
templates/commit.html +1 -1 modified
templates/commits.html +1 -1 modified

Full Patch

diff --git a/app.py b/app.py
index 7823067..79af3c8 100644
--- a/app.py
+++ b/app.py
@@ -1,4 +1,5 @@
 from flask import Flask, render_template, request
+from datetime import datetime
 
 from git.repo import get_bare_repos
 from git.commit import get_commits, get_commit
@@ -11,6 +12,19 @@ from git.blame import get_blame
 
 app = Flask(__name__)
 
+def datetime_filter(value, format='%Y-%m-%d %H:%M:%S'):
+    if isinstance(value, datetime):
+        # format regular datetime 
+        return value.strftime(format)
+    elif isinstance(value, (int, float)):
+        # if not datetime, but number, try to convert
+        # just assume its unix timestamp, git uses that
+        dt = datetime.fromtimestamp(value)
+        return dt.strftime(format)
+    return value
+
+app.jinja_env.filters['datetime'] = datetime_filter
+
 repo_path = "/home/lhietala/git-webview/repos-example"
 @app.route("/")
 def index():
diff --git a/git/blame.py b/git/blame.py
index a230b63..8ec663d 100644
--- a/git/blame.py
+++ b/git/blame.py
@@ -5,6 +5,7 @@ import pygit2 as git
 def get_blame(repo_path, ref="HEAD", file_path=""):
     repo = git.Repository(repo_path)
     obj = repo.revparse_single(ref)
+    # TODO: doesnt work with tree refs
     if obj.type == git.GIT_OBJECT_COMMIT:
         commit = obj
     else:
diff --git a/templates/blame.html b/templates/blame.html
index 7987724..663eafe 100644
--- a/templates/blame.html
+++ b/templates/blame.html
@@ -18,7 +18,7 @@
             {% if line.blame %}
             <td><a href="{{ url_for('commit_detail', repo_name=repo_name, commit_id=line.blame.commit_id) }}">{{ line.blame.commit_id[:8] }}</a></td>
             <td>{{ line.blame.author.name }}</td>
-            <td>{{ line.blame.author.time }}</td>
+            <td>{{ line.blame.author.time | datetime }}</td>
             {% else %}
             <td></td>
             <td></td>
diff --git a/templates/commit.html b/templates/commit.html
index cec9e77..29d753a 100644
--- a/templates/commit.html
+++ b/templates/commit.html
@@ -3,7 +3,7 @@
     <p>Message: {{ commit.message }}</p>
     <p>Author: {{ commit.author.name }} &lt;{{ commit.author.email }}&gt;</p>
     <p>Committer: {{ commit.committer.name }} &lt;{{ commit.committer.email }}&gt;</p>
-    <p>Date: {{ commit.date }}</p>
+    <p>Date: {{ commit.date | datetime }}</p>
     {% if commit.parent_id %}
     <p>Parent: <a href="{{ url_for('commit_detail', repo_name=repo_name, commit_id=commit.parent_id) }}">{{ commit.parent_id }}</a></p>
     {% endif %}
diff --git a/templates/commits.html b/templates/commits.html
index d766dc6..98ec25f 100644
--- a/templates/commits.html
+++ b/templates/commits.html
@@ -4,7 +4,7 @@
     <ul>
         {% for commit in commits %}
             <li>
-            <a href="{{ url_for('commit_detail', repo_name=repo_name, commit_id=commit.id) }}">{{ commit.id }}</a> - {{ commit.message }} - {{ commit.author.name }} - {{ commit.date }} {{ commit.diff_stats.files_changed }} files changed, {{ commit.diff_stats.insertions }} insertions, {{ commit.diff_stats.deletions }} deletions
+            <a href="{{ url_for('commit_detail', repo_name=repo_name, commit_id=commit.id) }}">{{ commit.id }}</a> - {{ commit.message }} - {{ commit.author.name }} - {{ commit.date | datetime }} {{ commit.diff_stats.files_changed }} files changed, {{ commit.diff_stats.insertions }} insertions, {{ commit.diff_stats.deletions }} deletions
             </li>
         {% endfor %}
     </ul>