From 05a4cc9d0a8e8fb181276fe02669ef7ac887148a Mon Sep 17 00:00:00 2001 From: xiez Date: Thu, 28 Jun 2012 16:58:09 +0800 Subject: [PATCH] Add repo last modify time --- base/templatetags/seahub_tags.py | 9 ++++++--- group/templates/group/group_info.html | 8 +++++++- group/views.py | 8 +++++++- templates/myhome.html | 18 +++++++++++++++--- utils.py | 15 +++++++++++++++ views.py | 8 +++++++- 6 files changed, 57 insertions(+), 9 deletions(-) diff --git a/base/templatetags/seahub_tags.py b/base/templatetags/seahub_tags.py index 2a41e2d216..8ded8a2a02 100644 --- a/base/templatetags/seahub_tags.py +++ b/base/templatetags/seahub_tags.py @@ -45,12 +45,15 @@ def translate_commit_desc(value): @register.filter(name='translate_commit_time') def translate_commit_time(value): """Translate commit time to human frindly format instead of timestamp""" - limit = 14 * 24 * 60 * 60 # Timestamp with in two weeks will be translated - if hasattr(value, 'strftime'): + + if type(value) == type(1): # check whether value is int + val = datetime.fromtimestamp(value) + elif isinstance(value, dt): val = datetime.fromtimestamp(int(value.strftime("%s"))) else: - val = datetime.fromtimestamp(value) + return value + limit = 14 * 24 * 60 * 60 # Timestamp with in two weeks will be translated now = datetime.now() delta = now - (val - dt.timedelta(0, 0, val.microsecond)) diff --git a/group/templates/group/group_info.html b/group/templates/group/group_info.html index 8306914938..4b4e8fddf8 100644 --- a/group/templates/group/group_info.html +++ b/group/templates/group/group_info.html @@ -43,7 +43,8 @@ - + + @@ -52,6 +53,11 @@ + {% if repo.latest_modify %} + + {% else %} + + {% endif %}
名字描述描述最后更新时间 共享来源 操作
{{ repo.props.name }} {{ repo.props.desc }}{{ repo.latest_modify|translate_commit_time }}—— ——{{ repo.share_from }} 下载 diff --git a/group/views.py b/group/views.py index 0c6860ef72..5b3b98abcd 100644 --- a/group/views.py +++ b/group/views.py @@ -7,7 +7,7 @@ from django.template import RequestContext from auth.decorators import login_required from seaserv import ccnet_rpc, ccnet_threaded_rpc, seafserv_threaded_rpc, get_repo, \ - get_group_repoids, check_group_staff + get_group_repoids, check_group_staff, get_commits from pysearpc import SearpcError from models import GroupMessage, MessageReply @@ -139,6 +139,12 @@ def render_group_info(request, group_id, form): repo.share_from_me = True else: repo.share_from_me = False + try: + repo.latest_modify = get_commits(repo.id, 0, 1)[0].ctime + except: + repo.latest_modify = None + continue + repos.append(repo) # remove user notifications diff --git a/templates/myhome.html b/templates/myhome.html index 2c115ed2d3..cdaf389e1f 100644 --- a/templates/myhome.html +++ b/templates/myhome.html @@ -1,5 +1,5 @@ {% extends "myhome_base.html" %} -{% load avatar_tags %} +{% load seahub_tags avatar_tags %} {% block nav_myhome_class %}class="cur"{% endblock %} {% block left_panel %} @@ -94,7 +94,8 @@ - + + @@ -102,6 +103,11 @@ + {% if repo.latest_modify %} + + {% else %} + + {% endif %} - + + @@ -129,6 +136,11 @@ + {% if repo.latest_modify %} + + {% else %} + + {% endif %}
名字描述描述最后更新时间 操作
{{ repo.props.name }} {{ repo.props.desc }}{{ repo.latest_modify|translate_commit_time }}—— —— 下载 共享 @@ -120,7 +126,8 @@
名字 共享来源描述描述最后更新时间 操作
{{ repo.props.name }} {{ repo.props.shared_email }} {{ repo.props.desc }}{{ repo.latest_modify|translate_commit_time }}—— —— 下载 取消共享 diff --git a/utils.py b/utils.py index b42b9e54c2..a499ffbfd3 100644 --- a/utils.py +++ b/utils.py @@ -7,6 +7,8 @@ from django.shortcuts import render_to_response from django.template import RequestContext from django.utils.hashcompat import sha_constructor +from seaserv import get_commits + def go_permission_error(request, msg=None): """ Return permisson error page. @@ -72,3 +74,16 @@ def validate_group_name(group_name): """ return re.match('^\w+$', group_name, re.U) + +def calculate_repo_last_modify(repo_list): + """ + Get last modify time for repo. + + """ + for repo in repo_list: + try: + repo.latest_modify = get_commits(repo.id, 0, 1)[0].ctime + except: + repo.latest_modify = None + continue + diff --git a/views.py b/views.py index dd8195bd9e..02410611ac 100644 --- a/views.py +++ b/views.py @@ -29,7 +29,8 @@ from seahub.contacts.models import Contact from seahub.notifications.models import UserNotification from forms import AddUserForm from utils import go_permission_error, go_error, list_to_string, \ - get_httpserver_root, get_ccnetapplet_root, gen_token + get_httpserver_root, get_ccnetapplet_root, gen_token, \ + calculate_repo_last_modify from seahub.profile.models import Profile @login_required @@ -536,11 +537,15 @@ def myhome(request): email = request.user.username quota_usage = seafserv_threaded_rpc.get_user_quota_usage(email) + + # Repos that I own owned_repos = seafserv_threaded_rpc.list_owned_repos(email) + calculate_repo_last_modify(owned_repos) # Repos that are share to me in_repos = seafserv_threaded_rpc.list_share_repos(request.user.username, 'to_email', -1, -1) + calculate_repo_last_modify(in_repos) # my contacts contacts = Contact.objects.filter(user_email=email) @@ -1133,3 +1138,4 @@ def org_info(request): 'org_users': org_members, 'groups': groups, }, context_instance=RequestContext(request)) +