mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-02 15:38:15 +00:00
Modified group recommend
This commit is contained in:
@@ -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)
|
||||
|
Binary file not shown.
@@ -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 <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\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 <a href=\"%(url)s\" target=\"_blank\">%(name)s</a> success。"
|
||||
msgstr "推荐到<a href=\"%(url)s\" target=\"_blank\">%(name)s</a>成功"
|
||||
|
||||
#: views.py:738
|
||||
msgid "Recommend failed"
|
||||
msgstr "推荐失败"
|
||||
|
@@ -690,48 +690,37 @@ 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)
|
||||
|
||||
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,
|
||||
gm = GroupMessage(group_id=group_id, from_email=username,
|
||||
message=message)
|
||||
gm.save()
|
||||
|
||||
# send signal
|
||||
grpmsg_added.send(sender=GroupMessage, group_id=group.id,
|
||||
grpmsg_added.send(sender=GroupMessage, group_id=group_id,
|
||||
from_email=request.user.username)
|
||||
|
||||
# save attachment
|
||||
@@ -740,18 +729,13 @@ def group_recommend(request):
|
||||
src='recommend')
|
||||
ma.save()
|
||||
|
||||
group_url = reverse('group_info', args=[group.id])
|
||||
msg = u'推荐到 <a href="%s" target="_blank">%s</a> 成功。' %\
|
||||
(group_url, group_name)
|
||||
group_url = reverse('group_info', args=[group_id])
|
||||
msg = _(u'Recommend to <a href="%(url)s" target="_blank">%(name)s</a> success。') %\
|
||||
{'url':group_url, 'name':group.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
|
||||
|
@@ -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*/
|
||||
|
@@ -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;
|
||||
|
@@ -6,12 +6,16 @@
|
||||
{{ name }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
到群组
|
||||
到群组:
|
||||
</h3>
|
||||
<label>群组名称:</label><br />
|
||||
<input type="input" name="groups" id="recommend-groups" value="" /><br />
|
||||
<div>
|
||||
{% for group in groups %}
|
||||
<input type="checkbox" name="groups" value="{{ group.id }}" {% if forloop.first and forloop.last %} checked {% endif %}>{{ group.group_name }}<br>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<label>推荐语:</label><br />
|
||||
<textarea name="message" id="recommend-msg"></textarea><br />
|
||||
<textarea name="message" id="recommend-msg">看一看~</textarea><br />
|
||||
<input type="hidden" name="repo_id" value="{{ repo.id }}" />
|
||||
<input type="hidden" name="path" value="{{ path }}" />
|
||||
<input type="hidden" name="attach_type" value="{{ attach_type }}" />
|
||||
|
Reference in New Issue
Block a user