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:
@@ -42,6 +42,8 @@ class FileContributors(models.Model):
|
|||||||
file_path = models.TextField()
|
file_path = models.TextField()
|
||||||
file_path_hash = models.CharField(max_length=12)
|
file_path_hash = models.CharField(max_length=12)
|
||||||
|
|
||||||
|
last_modified = models.IntegerField()
|
||||||
|
|
||||||
# email addresses seperated by comma
|
# email addresses seperated by comma
|
||||||
emails = models.TextField()
|
emails = models.TextField()
|
||||||
|
|
||||||
|
@@ -58,7 +58,7 @@
|
|||||||
|
|
||||||
{% if not view_history %}
|
{% if not view_history %}
|
||||||
<div id="file-commit-info">
|
<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">
|
<p class="contributors">
|
||||||
<span>{{ contributors|length }} 个贡献者</span>
|
<span>{{ contributors|length }} 个贡献者</span>
|
||||||
{% for user in contributors %}
|
{% for user in contributors %}
|
||||||
|
20
utils.py
20
utils.py
@@ -354,27 +354,29 @@ def get_file_contributors_from_revisions(repo_id, file_path):
|
|||||||
if user not in ret:
|
if user not in ret:
|
||||||
ret.append(user)
|
ret.append(user)
|
||||||
|
|
||||||
return ret
|
return ret, commits[0].ctime
|
||||||
|
|
||||||
def get_file_contributors(repo_id, file_path, file_path_hash, file_id):
|
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,
|
"""Get file contributors list and last modfied time from database cache.
|
||||||
try to get it from seaf-server.
|
If not found in cache, try to get it from seaf-server.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
contributors = []
|
contributors = []
|
||||||
|
last_modified = 0
|
||||||
try:
|
try:
|
||||||
fc = FileContributors.objects.get(repo_id=repo_id,
|
fc = FileContributors.objects.get(repo_id=repo_id,
|
||||||
file_path_hash=file_path_hash)
|
file_path_hash=file_path_hash)
|
||||||
except FileContributors.DoesNotExist:
|
except FileContributors.DoesNotExist:
|
||||||
# has no cache yet
|
# 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:
|
if not contributors:
|
||||||
return []
|
return [], 0
|
||||||
emails = ','.join(contributors)
|
emails = ','.join(contributors)
|
||||||
file_contributors = FileContributors(repo_id=repo_id,
|
file_contributors = FileContributors(repo_id=repo_id,
|
||||||
file_id=file_id,
|
file_id=file_id,
|
||||||
file_path=file_path,
|
file_path=file_path,
|
||||||
file_path_hash=file_path_hash,
|
file_path_hash=file_path_hash,
|
||||||
|
last_modified=last_modified,
|
||||||
emails=emails)
|
emails=emails)
|
||||||
file_contributors.save()
|
file_contributors.save()
|
||||||
else:
|
else:
|
||||||
@@ -382,14 +384,15 @@ def get_file_contributors(repo_id, file_path, file_path_hash, file_id):
|
|||||||
if fc.file_id != file_id:
|
if fc.file_id != file_id:
|
||||||
# but cache is outdated
|
# but cache is outdated
|
||||||
fc.delete()
|
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:
|
if not contributors:
|
||||||
return []
|
return [], 0
|
||||||
emails = ','.join(contributors)
|
emails = ','.join(contributors)
|
||||||
file_contributors = FileContributors(repo_id=repo_id,
|
file_contributors = FileContributors(repo_id=repo_id,
|
||||||
file_id=file_id,
|
file_id=file_id,
|
||||||
file_path=file_path,
|
file_path=file_path,
|
||||||
file_path_hash=file_path_hash,
|
file_path_hash=file_path_hash,
|
||||||
|
last_modified=last_modified,
|
||||||
emails=emails)
|
emails=emails)
|
||||||
file_contributors.save()
|
file_contributors.save()
|
||||||
else:
|
else:
|
||||||
@@ -398,5 +401,6 @@ def get_file_contributors(repo_id, file_path, file_path_hash, file_id):
|
|||||||
contributors = fc.emails.split(',')
|
contributors = fc.emails.split(',')
|
||||||
else:
|
else:
|
||||||
contributors = []
|
contributors = []
|
||||||
|
last_modified = fc.last_modified
|
||||||
|
|
||||||
return contributors
|
return contributors, last_modified
|
||||||
|
3
views.py
3
views.py
@@ -1112,7 +1112,7 @@ def repo_view_file(request, repo_id):
|
|||||||
file_path_hash = md5_constructor(urllib2.quote(path.encode('utf-8'))).hexdigest()[:12]
|
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)
|
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]
|
latest_contributor = contributors[0]
|
||||||
|
|
||||||
return render_to_response('repo_view_file.html', {
|
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,
|
'DOCUMENT_CONVERTOR_ROOT': DOCUMENT_CONVERTOR_ROOT,
|
||||||
'contributors': contributors,
|
'contributors': contributors,
|
||||||
'latest_contributor': latest_contributor,
|
'latest_contributor': latest_contributor,
|
||||||
|
'last_modified': last_modified,
|
||||||
'read_only': read_only,
|
'read_only': read_only,
|
||||||
'page_from': page_from,
|
'page_from': page_from,
|
||||||
}, context_instance=RequestContext(request))
|
}, context_instance=RequestContext(request))
|
||||||
|
Reference in New Issue
Block a user