mirror of
https://github.com/DerTyp7/tealcode-django-python.git
synced 2025-10-30 12:57:07 +01:00
added views and admin security
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
from django.shortcuts import render, redirect
|
||||
from .models import Category, Topic
|
||||
from analytics.models import View
|
||||
|
||||
def index(req):
|
||||
|
||||
view = View(ip=get_client_ip(req), home=True)
|
||||
view.save()
|
||||
categorys_obj = Category.objects.all()
|
||||
return render(req, "main/index.html", {'categorys': categorys_obj})
|
||||
|
||||
@@ -26,6 +28,9 @@ def topic(req, category, topic):
|
||||
'output': topic_obj.output,
|
||||
}
|
||||
|
||||
|
||||
view = View(ip=get_client_ip(req), topic=topic_obj)
|
||||
view.save()
|
||||
return render(req, "main/topic.html", context)
|
||||
|
||||
return redirect("main-index")
|
||||
@@ -38,6 +43,10 @@ def category(req, category):
|
||||
category_obj = Category.objects.filter(title = category).first()
|
||||
if category_obj:
|
||||
topics_obj = Topic.objects.filter(category=category_obj)
|
||||
|
||||
view = View(ip=get_client_ip(req), category=category_obj)
|
||||
view.save()
|
||||
|
||||
return render(req, "main/category.html", {'category_obj': category_obj, 'topics': topics_obj})
|
||||
|
||||
|
||||
@@ -55,3 +64,11 @@ def about(req):
|
||||
|
||||
def privacy(req):
|
||||
return render(req, "main/privacy.html")
|
||||
|
||||
def get_client_ip(req):
|
||||
x_forwarded_for = req.META.get("HTTP_X_FORWARDED_FOR")
|
||||
if x_forwarded_for:
|
||||
ip = x_forwarded_for.split[","][0]
|
||||
else:
|
||||
ip = req.META.get("REMOTE_ADDR")
|
||||
return ip
|
||||
Reference in New Issue
Block a user