import requests
from django.http import HttpResponse
from django.shortcuts import render

from core.settings import API_URL
from webservice_running.apps import api
from webservice_running.forms import OrderLocalForm


from django.utils.translation import gettext as _
from django.views.generic import TemplateView

from sharix_admin.views import MainView


class MainLocalView(MainView):
    page_title = 'Добро пожаловать!'
    page_name = 'main_local'
    template_name = 'webservice_running/local/main_local.html'

def order_reg(request):
    if request.method == 'POST':
        form = OrderLocalForm(request.POST)
        if form.is_valid():
            data = request.POST
            responce = requests.post(f'{API_URL}/webservice/api/webservice/', data=data, headers=api.headers)
            return HttpResponse(responce.text)
    else:
        form = OrderRegForm()
    return render(request, 'webservice_running/order_reg.html', {'form': form})
