def send_invitation(invitation): """ """ try: user = User.objects.get(email=invitation.email) message = "{0} added you to his contacts".format( invitation.sender.username) contact = Contact(owner=invitation.sender, user=user) contact.save() invitation.delete() return HttpResponseRedirect(contact.get_absolute_url()) except User.DoesNotExist: message = """ {0} Invites you to join his contacts. You can register on http://{1}/user/create_account/ \ if you want to accept his invitation""".format( invitation.sender.username, Site.objects.get_current().domain ) send_mail('An invitation sent to you', message, invitation.sender, [invitation.email], fail_silently=False ) return HttpResponseRedirect(invitation.get_absolute_url())