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.
|
A form used to recommend a file or directory.
|
||||||
"""
|
"""
|
||||||
groups = forms.CharField()
|
|
||||||
repo_id = forms.CharField(max_length=40)
|
repo_id = forms.CharField(max_length=40)
|
||||||
path = forms.CharField()
|
path = forms.CharField()
|
||||||
attach_type = forms.CharField(max_length=5)
|
attach_type = forms.CharField(max_length=5)
|
||||||
|
Binary file not shown.
@@ -8,7 +8,7 @@ msgid ""
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: PACKAGE VERSION\n"
|
"Project-Id-Version: PACKAGE VERSION\n"
|
||||||
"Report-Msgid-Bugs-To: \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"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
@@ -49,3 +49,22 @@ msgstr "群组已满,无法再添加成员。"
|
|||||||
#: error_msg.py:18
|
#: error_msg.py:18
|
||||||
msgid "Failed to add member to group"
|
msgid "Failed to add member to group"
|
||||||
msgstr "添加成员失败。"
|
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,68 +690,52 @@ def group_recommend(request):
|
|||||||
|
|
||||||
form = GroupRecommendForm(request.POST)
|
form = GroupRecommendForm(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
groups = form.cleaned_data['groups']
|
|
||||||
repo_id = form.cleaned_data['repo_id']
|
repo_id = form.cleaned_data['repo_id']
|
||||||
attach_type = form.cleaned_data['attach_type']
|
attach_type = form.cleaned_data['attach_type']
|
||||||
path = form.cleaned_data['path']
|
path = form.cleaned_data['path']
|
||||||
message = form.cleaned_data['message']
|
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
|
username = request.user.username
|
||||||
|
|
||||||
group_list = string2list(groups)
|
# Check group id format
|
||||||
for e in group_list:
|
for group_id in groups:
|
||||||
group_name = e.split(' ')[0]
|
|
||||||
try:
|
try:
|
||||||
group_creator = e.split(' ')[1]
|
group_id = int(group_id)
|
||||||
except IndexError:
|
except ValueError:
|
||||||
messages.add_message(request, messages.ERROR,
|
messages.error(request, _(u'Recommend error: wrong group id'))
|
||||||
u'推荐到 %s 失败,请检查群组名称。' % \
|
return HttpResponseRedirect(next)
|
||||||
group_name)
|
|
||||||
|
# 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
|
continue
|
||||||
|
|
||||||
# Check whether this repo is org repo.
|
# save message to group
|
||||||
org, base_template = check_and_get_org_by_repo(repo_id, username)
|
gm = GroupMessage(group_id=group_id, from_email=username,
|
||||||
if org:
|
message=message)
|
||||||
org_id = org.org_id
|
gm.save()
|
||||||
groups = get_org_groups_by_user(org_id, username)
|
|
||||||
|
|
||||||
else:
|
# send signal
|
||||||
groups = get_personal_groups_by_user(request.user.username)
|
grpmsg_added.send(sender=GroupMessage, group_id=group_id,
|
||||||
|
from_email=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)
|
|
||||||
|
|
||||||
# save attachment
|
# save attachment
|
||||||
ma = MessageAttachment(group_message=gm, repo_id=repo_id,
|
ma = MessageAttachment(group_message=gm, repo_id=repo_id,
|
||||||
attach_type=attach_type, path=path,
|
attach_type=attach_type, path=path,
|
||||||
src='recommend')
|
src='recommend')
|
||||||
ma.save()
|
ma.save()
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
group_url = reverse('group_info', args=[group.id])
|
|
||||||
msg = u'推荐到 <a href="%s" target="_blank">%s</a> 成功。' %\
|
|
||||||
(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:
|
else:
|
||||||
# TODO: need more clear error message
|
messages.add_message(request, messages.ERROR, _(u'Recommend failed'))
|
||||||
messages.add_message(request, messages.ERROR, '推荐失败')
|
|
||||||
return HttpResponseRedirect(next)
|
return HttpResponseRedirect(next)
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
@@ -50,6 +50,7 @@ button {
|
|||||||
}
|
}
|
||||||
input[type=checkbox] {
|
input[type=checkbox] {
|
||||||
height:auto;
|
height:auto;
|
||||||
|
margin-right: 5px;
|
||||||
}
|
}
|
||||||
input::-webkit-outer-spin-button,
|
input::-webkit-outer-spin-button,
|
||||||
input::-webkit-inner-spin-button {/*for input type="number" in chrome: to hide up/download arrow*/
|
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() {
|
$('#recommend-submit').click(function() {
|
||||||
if (!$.trim($('#recommend-groups').val())) {
|
|
||||||
apply_form_error('recommend-form', '群组名称不能为空。');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!$.trim($('#recommend-msg').val())) {
|
if (!$.trim($('#recommend-msg').val())) {
|
||||||
apply_form_error('recommend-form', '推荐语不能为空。');
|
apply_form_error('recommend-form', '推荐语不能为空。');
|
||||||
return false;
|
return false;
|
||||||
|
@@ -6,12 +6,16 @@
|
|||||||
{{ name }}
|
{{ name }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
到群组
|
到群组:
|
||||||
</h3>
|
</h3>
|
||||||
<label>群组名称:</label><br />
|
<div>
|
||||||
<input type="input" name="groups" id="recommend-groups" value="" /><br />
|
{% 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 />
|
<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="repo_id" value="{{ repo.id }}" />
|
||||||
<input type="hidden" name="path" value="{{ path }}" />
|
<input type="hidden" name="path" value="{{ path }}" />
|
||||||
<input type="hidden" name="attach_type" value="{{ attach_type }}" />
|
<input type="hidden" name="attach_type" value="{{ attach_type }}" />
|
||||||
|
Reference in New Issue
Block a user