1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-06-27 07:28:42 +00:00

Clean code

This commit is contained in:
xiez 2012-09-11 10:11:44 +08:00
parent d4ea5ad792
commit 51da061d8e
2 changed files with 24 additions and 48 deletions

View File

@ -13,7 +13,7 @@ from django.utils.translation import ugettext as _
from auth.decorators import login_required from auth.decorators import login_required
from seaserv import ccnet_rpc, ccnet_threaded_rpc, seafserv_threaded_rpc, \ from seaserv import ccnet_rpc, ccnet_threaded_rpc, seafserv_threaded_rpc, \
get_repo, get_group_repos, check_group_staff, get_commits, \ get_repo, get_group_repos, check_group_staff, get_commits, is_group_user, \
get_personal_groups, get_group, get_group_members, create_org_repo, \ get_personal_groups, get_group, get_group_members, create_org_repo, \
get_org_group_repos get_org_group_repos
from pysearpc import SearpcError from pysearpc import SearpcError
@ -153,12 +153,9 @@ def render_group_info(request, group_id, form):
msg_type='group_msg', msg_type='group_msg',
detail=str(group_id)).delete() detail=str(group_id)).delete()
# Check whether user belong to the group or admin # Check whether user belongs to the group.
joined = False joined = is_group_user(group_id_int, request.user.username)
groups = ccnet_threaded_rpc.get_groups(request.user.username)
for group in groups:
if group.id == group_id_int:
joined = True
if not joined and not request.user.is_staff: if not joined and not request.user.is_staff:
return render_error(request, u'未加入该小组') return render_error(request, u'未加入该小组')
@ -169,10 +166,7 @@ def render_group_info(request, group_id, form):
if not group: if not group:
return HttpResponseRedirect(reverse('group_list', args=[])) return HttpResponseRedirect(reverse('group_list', args=[]))
if check_group_staff(group.id, request.user): is_staff = True if check_group_staff(group.id, request.user) else False
is_staff = True
else:
is_staff = False
members = get_group_members(group_id_int) members = get_group_members(group_id_int)
managers = [] managers = []
@ -212,10 +206,8 @@ def render_group_info(request, group_id, form):
group_msgs = msgs_plus_one[:per_page] group_msgs = msgs_plus_one[:per_page]
attachments = MessageAttachment.objects.filter(group_message__in=group_msgs) attachments = MessageAttachment.objects.filter(group_message__in=group_msgs)
reply_to_list = []
msg_replies = MessageReply.objects.filter(reply_to__in=group_msgs) msg_replies = MessageReply.objects.filter(reply_to__in=group_msgs)
for r in msg_replies: reply_to_list = [ r.reply_to_id for r in msg_replies ]
reply_to_list.append(r.reply_to_id)
for msg in group_msgs: for msg in group_msgs:
msg.reply_cnt = reply_to_list.count(msg.id) msg.reply_cnt = reply_to_list.count(msg.id)
@ -307,11 +299,9 @@ def msg_reply(request, msg_id):
@login_required @login_required
def msg_reply_new(request): def msg_reply_new(request):
grpmsg_reply_list = []
notes = UserNotification.objects.filter(to_user=request.user.username) notes = UserNotification.objects.filter(to_user=request.user.username)
for n in notes: grpmsg_reply_list = [ n.detail for n in notes if \
if n.msg_type == 'grpmsg_reply': n.msg_type == 'grpmsg_reply']
grpmsg_reply_list.append(n.detail)
group_msgs = [] group_msgs = []
for msg_id in grpmsg_reply_list: for msg_id in grpmsg_reply_list:
@ -503,12 +493,9 @@ def group_share_repo(request, repo_id, group_id, from_email):
if not group: if not group:
return render_error(request, u'共享失败:小组不存在') return render_error(request, u'共享失败:小组不存在')
# Check whether user belong to the group # Check whether user belongs to the group.
joined = False joined = is_group_user(group_id_int, request.user.username)
groups = ccnet_threaded_rpc.get_groups(request.user.username)
for group in groups:
if group.props.id == group_id:
joined = True
if not joined: if not joined:
return render_error(request, u'共享失败:未加入该小组') return render_error(request, u'共享失败:未加入该小组')
@ -525,12 +512,9 @@ def group_unshare_repo(request, repo_id, group_id, from_email):
if not group: if not group:
return render_error(request, u'取消共享失败:小组不存在') return render_error(request, u'取消共享失败:小组不存在')
# Check whether user belong to the group # Check whether user belongs to the group.
joined = False joined = is_group_user(group_id_int, request.user.username)
groups = ccnet_threaded_rpc.get_groups(from_email)
for group in groups:
if group.props.id == group_id:
joined = True
if not joined: if not joined:
return render_error(request, u'取消共享失败:未加入该小组') return render_error(request, u'取消共享失败:未加入该小组')
@ -626,12 +610,8 @@ def create_group_repo(request, group_id):
if not get_group(group_id): if not get_group(group_id):
return json_error(u'创建失败:小组不存在') return json_error(u'创建失败:小组不存在')
# Check whether user belong to the group # Check whether user belongs to the group.
groups = ccnet_threaded_rpc.get_groups(request.user.username) if not is_group_user(group_id, request.user.username):
for group in groups:
if group.props.id == group_id:
break
else:
return json_error(u"创建失败:未加入该小组") return json_error(u"创建失败:未加入该小组")
form = RepoCreateForm(request.POST) form = RepoCreateForm(request.POST)
@ -697,3 +677,4 @@ def create_group_repo(request, group_id):
result = {'success': True} result = {'success': True}
return HttpResponse(json.dumps(result), return HttpResponse(json.dumps(result),
content_type=content_type) content_type=content_type)

View File

@ -201,16 +201,14 @@ def render_repo(request, repo_id, error=''):
zipped = gen_path_link(path, repo.name) zipped = gen_path_link(path, repo.name)
# get groups this repo is shared # get groups this repo is shared
groups = []
if request.user.org: if request.user.org:
org_id = request.user.org['org_id'] org_id = request.user.org['org_id']
repo_shared_groups = get_org_groups_by_repo(org_id, repo_id) repo_shared_groups = get_org_groups_by_repo(org_id, repo_id)
else: else:
repo_shared_groups = get_shared_groups_by_repo(repo_id) repo_shared_groups = get_shared_groups_by_repo(repo_id)
for group in repo_shared_groups: # Filter out groups that user is joined.
# check whether user joined this group groups = [ x for x in repo_shared_groups if \
if is_group_user(group.id, request.user.username): is_group_user(x.id, request.user.username)]
groups.append(group)
return render_to_response('repo.html', { return render_to_response('repo.html', {
"repo": repo, "repo": repo,
@ -887,14 +885,11 @@ def repo_view_file(request, repo_id):
# my constacts # my constacts
contacts = Contact.objects.filter(user_email=request.user.username) contacts = Contact.objects.filter(user_email=request.user.username)
# get groups this repo is shared # Get groups this repo is shared.
groups = []
repo_shared_groups = get_shared_groups_by_repo(repo_id) repo_shared_groups = get_shared_groups_by_repo(repo_id)
for group in repo_shared_groups: # Filter out groups that user in joined.
# check whether user joined this group groups = [ x for x in repo_shared_groups if \
if is_group_user(group.id, request.user.username): is_group_user(x.id, request.user.username)]
groups.append(group)
"""file comments""" """file comments"""
# Make sure page request is an int. If not, deliver first page. # Make sure page request is an int. If not, deliver first page.
try: try: