mirror of
https://github.com/DerTyp7/tealcode-django-python.git
synced 2025-10-29 04:22:08 +01:00
bug fixes
This commit is contained in:
@@ -23,7 +23,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
SECRET_KEY = 'django-insecure-84w$au&)%5rl8ud!82e%&)e&r+c0f9z%zlr4m9(76mebvx-r2@'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
DEBUG = False
|
||||
|
||||
ALLOWED_HOSTS = ['code.tealfire.de']
|
||||
|
||||
@@ -42,6 +42,7 @@ INSTALLED_APPS = [
|
||||
'django.contrib.staticfiles',
|
||||
'main.apps.MainConfig',
|
||||
'analytics.apps.AnalyticsConfig',
|
||||
'ipware',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
||||
@@ -79,8 +79,11 @@
|
||||
|
||||
</div>
|
||||
|
||||
<div class="col col-10 pt-5">
|
||||
{{ read_more }}
|
||||
<div class="col col-10 pt-5 text-center" style="letter-spacing: 1.5px">
|
||||
<h4>Read More</h4>
|
||||
<p>
|
||||
{{ read_more | safe }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="col">
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ from .models import Category, Topic, Rating
|
||||
from analytics.models import View
|
||||
|
||||
def index(req):
|
||||
view = View(ip=get_client_ip(req), home=True)
|
||||
view = View(ip=get_ip(req), home=True)
|
||||
view.save()
|
||||
categorys_obj = Category.objects.all()
|
||||
return render(req, "main/index.html", {'categorys': categorys_obj})
|
||||
@@ -20,13 +20,13 @@ def topic(req, category, topic):
|
||||
helpful_count = 0
|
||||
notHelpful_count = 0
|
||||
|
||||
for rating in Rating.objects.all():
|
||||
for rating in Rating.objects.filter(topic=topic_obj):
|
||||
if rating.is_positive == 1:
|
||||
helpful_count = helpful_count+1
|
||||
else:
|
||||
notHelpful_count = notHelpful_count +1
|
||||
|
||||
if topic_obj:
|
||||
if topic_obj:# topic_obj.title
|
||||
context = {
|
||||
'title': topic_obj.title,
|
||||
'code': topic_obj.code_text,
|
||||
@@ -42,7 +42,7 @@ def topic(req, category, topic):
|
||||
}
|
||||
|
||||
|
||||
view = View(ip=get_client_ip(req), topic=topic_obj)
|
||||
view = View(ip=get_ip(req), topic=topic_obj)
|
||||
view.save()
|
||||
return render(req, "main/topic.html", context)
|
||||
|
||||
@@ -57,7 +57,7 @@ def category(req, category):
|
||||
if category_obj:
|
||||
topics_obj = Topic.objects.filter(category=category_obj)
|
||||
|
||||
view = View(ip=get_client_ip(req), category=category_obj)
|
||||
view = View(ip=get_ip(req), category=category_obj)
|
||||
view.save()
|
||||
|
||||
context = {
|
||||
@@ -100,26 +100,28 @@ def privacy(req):
|
||||
return render(req, "main/privacy.html", {'current': 'privacy'})
|
||||
|
||||
def rating(req, topic_title, is_positive):
|
||||
if(Rating.objects.filter(ip=get_client_ip(req))):
|
||||
return redirect("main-index")
|
||||
|
||||
|
||||
topic = Topic.objects.filter(title=topic_title).first()
|
||||
|
||||
|
||||
if(Rating.objects.filter(ip=get_ip(req), topic=topic)):
|
||||
return redirect("main-index")
|
||||
|
||||
if is_positive == 1:
|
||||
is_positive = True
|
||||
else:
|
||||
is_positive = False
|
||||
|
||||
rating = Rating(topic=topic, is_positive=is_positive, ip=get_client_ip(req))
|
||||
rating = Rating(topic=topic, is_positive=is_positive, ip=get_ip(req))
|
||||
|
||||
rating.save()
|
||||
return redirect("main-index")
|
||||
|
||||
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]
|
||||
def get_ip(req):
|
||||
ip = req.META.get('HTTP_X_REAL_IP')
|
||||
if ip is None:
|
||||
return "x.x.x.x"
|
||||
else:
|
||||
ip = req.META.get("REMOTE_ADDR")
|
||||
return ip
|
||||
# We got the client's IP address
|
||||
return ip
|
||||
|
||||
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
Django==3.2.9
|
||||
mysqlclient
|
||||
mysqlclient
|
||||
django-ipware
|
||||
Reference in New Issue
Block a user