1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-05-12 01:45:04 +00:00

Fix post office connection and handle invitation error

This commit is contained in:
zhengxie 2018-10-13 15:08:35 +08:00
parent eb2d38c8f8
commit a306737700
4 changed files with 18 additions and 8 deletions
requirements.txt
seahub
api2/endpoints
invitations
utils

View File

@ -5,7 +5,7 @@ six==1.11.0
Pillow==4.3.0
Django==1.11.15
django-compressor==2.2
django-post-office==3.0.4
git+git://github.com/haiwen/django-post_office.git@2312cf240363721f737b5ac8eb86ab8cb255938f#egg=django-post_office
django-statici18n==1.7.0
djangorestframework==3.3.3
git+git://github.com/haiwen/django-constance.git@8508ff29141732190faff51d5c2b5474da297732#egg=django-constance[database]

View File

@ -6,6 +6,7 @@ from rest_framework.authentication import SessionAuthentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView
from post_office.models import STATUS
from seahub.api2.authentication import TokenAuthentication
from seahub.api2.permissions import CanInviteGuest
@ -69,9 +70,12 @@ class InvitationsView(APIView):
i = Invitation.objects.add(inviter=request.user.username,
accepter=accepter)
i.send_to(email=accepter)
return Response(i.to_dict(), status=201)
m = i.send_to(email=accepter)
if m.status == STATUS.sent:
return Response(i.to_dict(), status=201)
else:
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR,
_('Internal Server Error'))
class InvitationsBatchView(APIView):
@ -132,7 +136,13 @@ class InvitationsBatchView(APIView):
except User.DoesNotExist:
i = Invitation.objects.add(inviter=request.user.username,
accepter=accepter)
i.send_to(email=accepter)
result['success'].append(i.to_dict())
m = i.send_to(email=accepter)
if m.status == STATUS.sent:
result['success'].append(i.to_dict())
else:
result['failed'].append({
'email': accepter,
'error_msg': _('Internal Server Error'),
})
return Response(result)

View File

@ -89,7 +89,7 @@ class Invitation(models.Model):
# context).rstrip()
subject = _('%(user)s invited you to join %(site_name)s.') % {
'user': self.inviter, 'site_name': get_site_name()}
send_html_email_with_dj_template(
return send_html_email_with_dj_template(
email, dj_template='invitations/invitation_email.html',
context=context,
subject=subject,

View File

@ -42,7 +42,7 @@ def send_html_email_with_dj_template(recipients, subject, dj_template,
t = loader.get_template(dj_template)
html_message = t.render(context)
mail.send(recipients, sender=sender, template=template, context=context,
return mail.send(recipients, sender=sender, template=template, context=context,
subject=subject, message=message,
html_message=html_message, headers=headers, priority=priority,
backend=backend)