def email_share(self, user, email, type, id):
# Get our e-mail formatter
formatter = self.get_email_formatter(type)
instance = None
# Attempt to get the object instance we want to share
try:
instance = apps.get_model(self.AVAILABLE_TYPES[type]).objects.get(id=id)
except ObjectDoesNotExist:
# If it doesn't exist, respond with a 404
return Response({"message": f"Object with id {id} does not exist"}, status=status.HTTP_404_NOT_FOUND)
# Create our e-mail body
email_body = {
"to": email,
"subject": f"[TalentMAP] Shared {type}",
"body": formatter(instance)
}
# TODO: Implement actual e-mail sending here when avaiable e-mail servers are clarified
# Return a 202 ACCEPTED with a copy of the email body
return Response({"message": f"Position shared externally via email at {email}", "email_body": email_body}, status=status.HTTP_202_ACCEPTED)
评论列表
文章目录