init
This commit is contained in:
50
home/views.py
Normal file
50
home/views.py
Normal file
@@ -0,0 +1,50 @@
|
||||
from django.views.generic import TemplateView, FormView
|
||||
from django.http import HttpResponse
|
||||
|
||||
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
|
||||
|
||||
|
||||
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("")
|
||||
|
||||
Reference in New Issue
Block a user