diff --git a/group/forms.py b/group/forms.py index 476a109bf8..d9ac8bc167 100644 --- a/group/forms.py +++ b/group/forms.py @@ -15,7 +15,6 @@ class GroupRecommendForm(MessageForm): """ A form used to recommend a file or directory. """ - groups = forms.CharField() repo_id = forms.CharField(max_length=40) path = forms.CharField() attach_type = forms.CharField(max_length=5) diff --git a/group/locale/zh_CN/LC_MESSAGES/django.mo b/group/locale/zh_CN/LC_MESSAGES/django.mo index 6dd8c37108..fbb1ffd173 100644 Binary files a/group/locale/zh_CN/LC_MESSAGES/django.mo and b/group/locale/zh_CN/LC_MESSAGES/django.mo differ diff --git a/group/locale/zh_CN/LC_MESSAGES/django.po b/group/locale/zh_CN/LC_MESSAGES/django.po index 22a6741276..88b609b328 100644 --- a/group/locale/zh_CN/LC_MESSAGES/django.po +++ b/group/locale/zh_CN/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2012-09-07 16:11+0800\n" +"POT-Creation-Date: 2012-10-20 14:58+0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -49,3 +49,22 @@ msgstr "群组已满,无法再添加成员。" #: error_msg.py:18 msgid "Failed to add member to group" msgstr "添加成员失败。" + +#: views.py:705 +msgid "Recommend error: wrong group id" +msgstr "推荐失败:群组id不正确" + +#: views.py:713 +#, python-format +msgid "Recommend to %s error: you are not in that group" +msgstr "推荐到 %s 失败:未参加该群组" + +#: views.py:733 +#, python-format +msgid "" +"Recommend to %(name)s success。" +msgstr "推荐到%(name)s成功" + +#: views.py:738 +msgid "Recommend failed" +msgstr "推荐失败" diff --git a/group/views.py b/group/views.py index 1e2ca21f2b..753d9d4936 100644 --- a/group/views.py +++ b/group/views.py @@ -690,68 +690,52 @@ def group_recommend(request): form = GroupRecommendForm(request.POST) if form.is_valid(): - groups = form.cleaned_data['groups'] repo_id = form.cleaned_data['repo_id'] attach_type = form.cleaned_data['attach_type'] path = form.cleaned_data['path'] message = form.cleaned_data['message'] + groups = request.POST.getlist('groups') # groups is a group_id list, e.g. [u'1', u'7'] username = request.user.username - - group_list = string2list(groups) - for e in group_list: - group_name = e.split(' ')[0] + + # Check group id format + for group_id in groups: try: - group_creator = e.split(' ')[1] - except IndexError: - messages.add_message(request, messages.ERROR, - u'推荐到 %s 失败,请检查群组名称。' % \ - group_name) + group_id = int(group_id) + except ValueError: + messages.error(request, _(u'Recommend error: wrong group id')) + return HttpResponseRedirect(next) + + # Get that group + group = get_group(group_id) + + # TODO: Check whether repo is in the group and Im in the group + if not is_group_user(group_id, username): + err_msg = _(u'Recommend to %s error: you are not in that group') + messages.error(request, err_msg % group.group_name) continue - # Check whether this repo is org repo. - org, base_template = check_and_get_org_by_repo(repo_id, username) - if org: - org_id = org.org_id - groups = get_org_groups_by_user(org_id, username) + # save message to group + gm = GroupMessage(group_id=group_id, from_email=username, + message=message) + gm.save() - else: - groups = get_personal_groups_by_user(request.user.username) - - find = False - for group in groups: - # for every group that user joined, if group name and - # group creator matchs, then has find the group - if group.group_name == group_name and \ - group_creator.find(group.creator_name) >= 0: - find = True - # save message to group - gm = GroupMessage(group_id=int(group.id), - from_email=request.user.username, - message=message) - gm.save() - - # send signal - grpmsg_added.send(sender=GroupMessage, group_id=group.id, - from_email=request.user.username) + # send signal + grpmsg_added.send(sender=GroupMessage, group_id=group_id, + from_email=request.user.username) - # save attachment - ma = MessageAttachment(group_message=gm, repo_id=repo_id, - attach_type=attach_type, path=path, - src='recommend') - ma.save() + # save attachment + ma = MessageAttachment(group_message=gm, repo_id=repo_id, + attach_type=attach_type, path=path, + src='recommend') + ma.save() + + group_url = reverse('group_info', args=[group_id]) + msg = _(u'Recommend to %(name)s success。') %\ + {'url':group_url, 'name':group.group_name} + messages.add_message(request, messages.INFO, msg) - group_url = reverse('group_info', args=[group.id]) - msg = u'推荐到 %s 成功。' %\ - (group_url, group_name) - messages.add_message(request, messages.INFO, msg) - break - if not find: - messages.add_message(request, messages.ERROR, - u'推荐到 %s 失败,请检查是否参加了该群组。' % \ - group_name) else: - # TODO: need more clear error message - messages.add_message(request, messages.ERROR, '推荐失败') + messages.add_message(request, messages.ERROR, _(u'Recommend failed')) return HttpResponseRedirect(next) @login_required diff --git a/media/css/seahub.css b/media/css/seahub.css index e707de1c42..78a468684f 100644 --- a/media/css/seahub.css +++ b/media/css/seahub.css @@ -50,6 +50,7 @@ button { } input[type=checkbox] { height:auto; + margin-right: 5px; } input::-webkit-outer-spin-button, input::-webkit-inner-spin-button {/*for input type="number" in chrome: to hide up/download arrow*/ diff --git a/templates/snippets/bottom_bar.html b/templates/snippets/bottom_bar.html index 4ec6f97eb1..10303fd659 100644 --- a/templates/snippets/bottom_bar.html +++ b/templates/snippets/bottom_bar.html @@ -28,10 +28,6 @@ $('#click-into-group').click(function() { }); $('#recommend-submit').click(function() { - if (!$.trim($('#recommend-groups').val())) { - apply_form_error('recommend-form', '群组名称不能为空。'); - return false; - } if (!$.trim($('#recommend-msg').val())) { apply_form_error('recommend-form', '推荐语不能为空。'); return false; diff --git a/templates/snippets/group_recommend_form.html b/templates/snippets/group_recommend_form.html index 631f09e7b3..332a11c806 100644 --- a/templates/snippets/group_recommend_form.html +++ b/templates/snippets/group_recommend_form.html @@ -6,12 +6,16 @@ {{ name }} {% endif %} {% endfor %} - 到群组 + 到群组: -
-
+
+ {% for group in groups %} + {{ group.group_name }}
+ {% endfor %} +
+
-
+