53 lines
1.3 KiB
Python
53 lines
1.3 KiB
Python
from django.views.generic import TemplateView, FormView
|
|
from django.http import HttpResponse
|
|
from django.urls import reverse_lazy
|
|
|
|
from ipware import get_client_ip
|
|
from urllib import parse
|
|
|
|
from .forms import ContactForm
|
|
from .models import Hit
|
|
|
|
|
|
class IndexView(TemplateView):
|
|
template_name = 'home/index.html'
|
|
|
|
|
|
class CVView(TemplateView):
|
|
template_name = 'home/cv.html'
|
|
|
|
|
|
class ServiceView(TemplateView):
|
|
template_name = "home/service.html"
|
|
|
|
|
|
class ContactView(FormView):
|
|
template_name = 'home/contact.html'
|
|
form_class = ContactForm
|
|
success_url = reverse_lazy("home:contact_valid")
|
|
|
|
|
|
class ContactValidView(TemplateView):
|
|
template_name = "home/contact_success.html"
|
|
|
|
|
|
def hit(request):
|
|
if request.method == "POST":
|
|
ip_address, _ = get_client_ip(request)
|
|
ip_address = '.'.join(ip_address.split('.')[:-1]+["0"])
|
|
path_parser = parse.urlsplit(request.headers["referer"])
|
|
path = path_parser.path
|
|
parameters = dict(parse.parse_qsl(path_parser.query))
|
|
user_agent = request.headers["user-agent"]
|
|
session_id = request.session.session_key
|
|
|
|
Hit.objects.create(
|
|
path=path_parser.path,
|
|
parameters=parameters,
|
|
session_id=session_id,
|
|
ip_address=ip_address,
|
|
user_agent=user_agent,
|
|
)
|
|
return HttpResponse("")
|
|
|