diff --git a/app.py b/app.py
index 7823067..79af3c8 100644
--- a/app.py
+++ b/app.py
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
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
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
{% 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
<p>Message: {{ commit.message }}</p>
<p>Author: {{ commit.author.name }} <{{ commit.author.email }}></p>
<p>Committer: {{ commit.committer.name }} <{{ commit.committer.email }}></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
<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>