Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Index(TemplateView):
- def get(self,request):
- form = OrderModelForm
- return render(request, 'index.html', {'form':form})
- def post(self,request):
- url = request.POST.get('url')
- user_mail = request.POST.get('email')
- current_order = OrderModel.objects.create(url = url, email=user_mail)
- current_order.save()
- post_dict = request.POST.copy()
- post_dict['order_number'] = current_order.pk
- print('мой номер', post_dict['order_number'])
- json_data = json.dumps(post_dict)
- start_parsing.delay(json_data)#url=url, user_mail=user_mail, order_number=current_order.pk)
- return render(request, 'thanks.html', {})
- @task
- def start_parsing(data):#url, user_mail, order_number):
- normal_data = json.loads(data)
- url = normal_data.get('url')
- email = normal_data.get('email')
- current_order_pk = normal_data.get('order_number')
- print('hi, my number is', str(current_order_pk))
- main_parse_process(url=url, order_number=current_order_pk) #Парсер должен сохранять изображения по нужному адресу с привязкой к объекту отчета
- send_notification(user_mail=email, order_number=current_order_pk)
- def send_notification(user_mail, order_number):
- mail_host = "oriflamesender@gmail.com"
- recipients= [user_mail,]
- url_in_letter = 'http://{}/show_result/{}/'.format('test',format(str(order_number)))
- message = '''Здравствуйте! Ваш запрос на сайте IRR Parser обработан. Вот ссылка на полученные графики:
- {}'''.format(url_in_letter)
- subject= 'Отчет с IRR Parser'
- send_mail(subject, message, mail_host, recipients, fail_silently=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement