added views and admin security

This commit is contained in:
DerTyp187
2021-11-18 08:48:26 +01:00
parent 1c11ebbfcc
commit 74d8f41426
10 changed files with 147 additions and 7 deletions

View File

@@ -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