def post(self, request): data = request.data email = Customer.objects.normalize_email(data['email']) try: customer = Customer.objects.get(email=email) password = Customer.objects.make_random_password() customer.set_password(password) try: send(u'Изменение пароля для пользователя %s' % customer.name, u''' Ваш новый пароль: %s <br /> Используйте этот адрес электронной почты в качестве логина ''' % password, [email]) customer.save() except: return Response({ '_error': 'Не удалось отправить письмо, попробуйте позже, возможно почтовый сервер недоступен' }, status=status.HTTP_406_NOT_ACCEPTABLE) except Customer.DoesNotExist: pass return Response({'_success': 'На указанный адрес выслан новый пароль'})
def check_post_feedback(instance, sender, created, **kwargs): html = render_to_string('feedback/feedback_fields.html', { 'feedback': instance, }) if created: send(_('Thanks for question'), html, [instance.email]) send(_('Received a complaint from') + ' %s' % instance.username, html, globals.config['admin_emails'])
def check_pre_feedback(instance, **kwargs): if instance.id and instance.admin_message and not instance.is_notified: instance.is_notified = True instance.answer_date = timezone.now() send(_('Answer on your question from site ') + globals.request.get_host(), render_to_string('feedback/feedback_fields.html', { 'feedback': instance, 'answer': True, }), [instance.email])