1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-31 14:42:10 +00:00

Fixed sending file shared link bug

This commit is contained in:
xiez
2012-09-15 21:16:34 +08:00
parent 2317ef5c60
commit fa447e729f
4 changed files with 54 additions and 59 deletions

View File

@@ -45,8 +45,11 @@ class FileLinkShareForm(forms.Form):
Form for sharing file shared link to emails.
"""
email = forms.CharField(max_length=512)
file_shared_link = forms.CharField(max_length=40)
email = forms.CharField(max_length=512, error_messages={
'required': '输入不能为空',
'max_length': '邮箱太长不超过512个字符'
})
file_shared_link = forms.CharField()
class FileCommentForm(forms.Form):
"""

View File

@@ -267,7 +267,7 @@ function apply_form_error(formid, error_msg) {
var form_err = $("#" + formid + " .error"),
container = $("#simplemodal-container");
form_err.html(error_msg).attr('class', 'error');
form_err.html(error_msg).attr('class', 'error').removeClass('hide');
container.css('height', $('#'+formid).height());
}

View File

@@ -77,10 +77,9 @@
<label>邮箱(多个邮箱以,分隔)</label><br />
<textarea id="email" name="email"></textarea><br />
<input type="hidden" name="file_shared_link" value="{{ file_shared_link }}" />
<p id="error" class="hide">输入不能为空。</p>
<input type="submit" value="提交" class="submit" />
<p id="sending" class="hide">发送中...</p>
<p id="success" class="hide"></p>
<p class="error hide"></p>
<p id="sending" class="hide">发送中...</p>
</form>
<div id="open-local-feedback" class="hide">
@@ -233,42 +232,36 @@ $('#send-shared-link').click(function() {
});
$("#link-send-form").submit(function(event) {
$('#error, #sending, #success').attr('class', 'hide');
$('#link-send-form .error').addClass('hide');
$('#sending').removeClass('hide');
var form = $(this),
file_shared_link = form.children('input[name="file_shared_link"]').val(),
email = $.trim(form.children('textarea[name="email"]').val());
if (!email) {
$('#error').attr('class', 'error');
$('#simplemodal-container').css('height', $('#link-send-form').height());
return false;
}
$('#sending').removeClass('hide');
$('#simplemodal-container').css('height', $('#link-send-form').height());
if (email.length <= 512) {
$.ajax({
type: "POST",
url: "{{ SITE_ROOT }}sharedlink/send/",
url: "{% url 'seahub.views.send_shared_link' %}",
dataType: 'json',
cache: false,
contentType: 'application/json; charset=utf-8',
beforeSend: prepareCSRFToken,
data: {file_shared_link: file_shared_link, email: email},
success: function(data) {
$('#sending').attr('class', 'hide');
$('#success').html(data[0]['msg']).removeClass('hide');
$('#simplemodal-container').css('height', $('#link-send-form').height());
location.reload(true);
},
error: function(xhr, ajaxOptions, thrownError) {
var jsonVal = jQuery.parseJSON(xhr.responseText);
$('#sending').attr('class', 'hide');
$('#error').html(jsonVal[0]['error']).attr('class','error');
$('#simplemodal-container').css('height', $('#link-send-form').height());
error: function(data, textStatus, jqXHR) {
$('#sending').addClass('hide');
var errors = $.parseJSON(data.responseText);
$.each(errors, function(index, value) {
if (index == 'error') {
apply_form_error('link-send-form', value);
} else {
apply_form_error('link-send-form', value[0]);
}
});
}
});
}
return false;
});

View File

@@ -2213,47 +2213,46 @@ def remove_shared_link(request):
@login_required
def send_shared_link(request):
"""
Handle ajax post request to share file shared link.
Handle ajax post request to send file shared link.
"""
if not request.is_ajax() and not request.method == 'POST':
raise Http404
result = {}
content_type = 'application/json; charset=utf-8'
form = FileLinkShareForm(request.POST)
if not form.is_valid():
err = '发送失败'
data = json.dumps([{'error':err}])
return HttpResponse(data, status=400, content_type=content_type)
if form.is_valid():
email = form.cleaned_data['email']
file_shared_link = form.cleaned_data['file_shared_link']
email = form.cleaned_data['email']
file_shared_link = form.cleaned_data['file_shared_link']
t = loader.get_template('shared_link_email.html')
to_email_list = string2list(email)
for to_email in to_email_list:
# Add email to contacts.
mail_sended.send(sender=None, user=request.user.username,
email=to_email)
t = loader.get_template('shared_link_email.html')
to_email_list = string2list(email)
for to_email in to_email_list:
# Add email to contacts
mail_sended.send(sender=None, user=request.user.username,
email=to_email)
c = {
'email': request.user.username,
'to_email': to_email,
'file_shared_link': file_shared_link,
}
c = {
'email': request.user.username,
'to_email': to_email,
'file_shared_link': file_shared_link,
}
try:
send_mail('您的好友通过SeaCloud分享了一个文件给您',
t.render(Context(c)), None, [to_email],
fail_silently=False)
except:
err = '发送失败'
data = json.dumps([{'error':err}])
return HttpResponse(data, status=500, content_type=content_type)
msg = '发送成功。'
data = json.dumps([{'msg': msg}])
return HttpResponse(data, status=200, content_type=content_type)
try:
send_mail('您的好友通过SeaCloud分享了一个文件给您',
t.render(Context(c)), None, [to_email],
fail_silently=False)
except:
data = json.dumps({'error':u'发送失败'})
return HttpResponse(data, status=500, content_type=content_type)
data = json.dumps("success")
messages.add_message(request, messages.INFO, u'发送成功')
return HttpResponse(data, status=200, content_type=content_type)
else:
return HttpResponseBadRequest(json.dumps(form.errors),
content_type=content_type)
def document_prepare(raw_path, obj_id, doctype):
curl = DOCUMENT_CONVERTOR_ROOT + 'convert'