1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-16 07:08:55 +00:00

show file last modifed time in repo_view_file

This commit is contained in:
lins05
2012-09-25 16:51:00 +08:00
parent dc60691e93
commit 2960b68b26
4 changed files with 17 additions and 10 deletions

View File

@@ -42,6 +42,8 @@ class FileContributors(models.Model):
file_path = models.TextField()
file_path_hash = models.CharField(max_length=12)
last_modified = models.IntegerField()
# email addresses seperated by comma
emails = models.TextField()

View File

@@ -58,7 +58,7 @@
{% if not view_history %}
<div id="file-commit-info">
<p class="latest-commit">{% avatar latest_contributor 20 %} <a href="{% url 'user_profile' latest_contributor %}" class="name">{{ latest_contributor|email2nickname }}</a> <span>做了最新修改</span></p>
<p class="latest-commit">{% avatar latest_contributor 20 %} <a href="{% url 'user_profile' latest_contributor %}" class="name">{{ latest_contributor|email2nickname }}</a> <span class="time">{{ last_modified|translate_commit_time}}</span><span> 做了最新修改</span></p>
<p class="contributors">
<span>{{ contributors|length }} 个贡献者</span>
{% for user in contributors %}

View File

@@ -354,27 +354,29 @@ def get_file_contributors_from_revisions(repo_id, file_path):
if user not in ret:
ret.append(user)
return ret
return ret, commits[0].ctime
def get_file_contributors(repo_id, file_path, file_path_hash, file_id):
"""Get file contributors list from database cache. If not found in cache,
try to get it from seaf-server.
"""Get file contributors list and last modfied time from database cache.
If not found in cache, try to get it from seaf-server.
"""
contributors = []
last_modified = 0
try:
fc = FileContributors.objects.get(repo_id=repo_id,
file_path_hash=file_path_hash)
except FileContributors.DoesNotExist:
# has no cache yet
contributors = get_file_contributors_from_revisions (repo_id, file_path)
contributors, last_modified = get_file_contributors_from_revisions (repo_id, file_path)
if not contributors:
return []
return [], 0
emails = ','.join(contributors)
file_contributors = FileContributors(repo_id=repo_id,
file_id=file_id,
file_path=file_path,
file_path_hash=file_path_hash,
last_modified=last_modified,
emails=emails)
file_contributors.save()
else:
@@ -382,14 +384,15 @@ def get_file_contributors(repo_id, file_path, file_path_hash, file_id):
if fc.file_id != file_id:
# but cache is outdated
fc.delete()
contributors = get_file_contributors_from_revisions (repo_id, file_path)
contributors, last_modified = get_file_contributors_from_revisions (repo_id, file_path)
if not contributors:
return []
return [], 0
emails = ','.join(contributors)
file_contributors = FileContributors(repo_id=repo_id,
file_id=file_id,
file_path=file_path,
file_path_hash=file_path_hash,
last_modified=last_modified,
emails=emails)
file_contributors.save()
else:
@@ -398,5 +401,6 @@ def get_file_contributors(repo_id, file_path, file_path_hash, file_id):
contributors = fc.emails.split(',')
else:
contributors = []
last_modified = fc.last_modified
return contributors
return contributors, last_modified

View File

@@ -1112,7 +1112,7 @@ def repo_view_file(request, repo_id):
file_path_hash = md5_constructor(urllib2.quote(path.encode('utf-8'))).hexdigest()[:12]
comments = FileComment.objects.filter(file_path_hash=file_path_hash, repo_id=repo_id)
contributors = get_file_contributors(repo_id, path.encode('utf-8'), file_path_hash, obj_id)
contributors, last_modified = get_file_contributors(repo_id, path.encode('utf-8'), file_path_hash, obj_id)
latest_contributor = contributors[0]
return render_to_response('repo_view_file.html', {
@@ -1144,6 +1144,7 @@ def repo_view_file(request, repo_id):
'DOCUMENT_CONVERTOR_ROOT': DOCUMENT_CONVERTOR_ROOT,
'contributors': contributors,
'latest_contributor': latest_contributor,
'last_modified': last_modified,
'read_only': read_only,
'page_from': page_from,
}, context_instance=RequestContext(request))