mirror of
https://github.com/DerTyp7/tealcode-django-python.git
synced 2025-10-29 12:32:09 +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@'
|
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!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = True
|
DEBUG = False
|
||||||
|
|
||||||
ALLOWED_HOSTS = ['code.tealfire.de']
|
ALLOWED_HOSTS = ['code.tealfire.de']
|
||||||
|
|
||||||
@@ -42,6 +42,7 @@ INSTALLED_APPS = [
|
|||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'main.apps.MainConfig',
|
'main.apps.MainConfig',
|
||||||
'analytics.apps.AnalyticsConfig',
|
'analytics.apps.AnalyticsConfig',
|
||||||
|
'ipware',
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
|||||||
@@ -79,8 +79,11 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col col-10 pt-5">
|
<div class="col col-10 pt-5 text-center" style="letter-spacing: 1.5px">
|
||||||
{{ read_more }}
|
<h4>Read More</h4>
|
||||||
|
<p>
|
||||||
|
{{ read_more | safe }}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from .models import Category, Topic, Rating
|
|||||||
from analytics.models import View
|
from analytics.models import View
|
||||||
|
|
||||||
def index(req):
|
def index(req):
|
||||||
view = View(ip=get_client_ip(req), home=True)
|
view = View(ip=get_ip(req), home=True)
|
||||||
view.save()
|
view.save()
|
||||||
categorys_obj = Category.objects.all()
|
categorys_obj = Category.objects.all()
|
||||||
return render(req, "main/index.html", {'categorys': categorys_obj})
|
return render(req, "main/index.html", {'categorys': categorys_obj})
|
||||||
@@ -20,13 +20,13 @@ def topic(req, category, topic):
|
|||||||
helpful_count = 0
|
helpful_count = 0
|
||||||
notHelpful_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:
|
if rating.is_positive == 1:
|
||||||
helpful_count = helpful_count+1
|
helpful_count = helpful_count+1
|
||||||
else:
|
else:
|
||||||
notHelpful_count = notHelpful_count +1
|
notHelpful_count = notHelpful_count +1
|
||||||
|
|
||||||
if topic_obj:
|
if topic_obj:# topic_obj.title
|
||||||
context = {
|
context = {
|
||||||
'title': topic_obj.title,
|
'title': topic_obj.title,
|
||||||
'code': topic_obj.code_text,
|
'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()
|
view.save()
|
||||||
return render(req, "main/topic.html", context)
|
return render(req, "main/topic.html", context)
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ def category(req, category):
|
|||||||
if category_obj:
|
if category_obj:
|
||||||
topics_obj = Topic.objects.filter(category=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()
|
view.save()
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
@@ -100,26 +100,28 @@ def privacy(req):
|
|||||||
return render(req, "main/privacy.html", {'current': 'privacy'})
|
return render(req, "main/privacy.html", {'current': 'privacy'})
|
||||||
|
|
||||||
def rating(req, topic_title, is_positive):
|
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()
|
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:
|
if is_positive == 1:
|
||||||
is_positive = True
|
is_positive = True
|
||||||
else:
|
else:
|
||||||
is_positive = False
|
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()
|
rating.save()
|
||||||
return redirect("main-index")
|
return redirect("main-index")
|
||||||
|
|
||||||
def get_client_ip(req):
|
def get_ip(req):
|
||||||
x_forwarded_for = req.META.get("HTTP_X_FORWARDED_FOR")
|
ip = req.META.get('HTTP_X_REAL_IP')
|
||||||
if x_forwarded_for:
|
if ip is None:
|
||||||
ip = x_forwarded_for.split[","][0]
|
return "x.x.x.x"
|
||||||
else:
|
else:
|
||||||
ip = req.META.get("REMOTE_ADDR")
|
# We got the client's IP address
|
||||||
return ip
|
return ip
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
Django==3.2.9
|
Django==3.2.9
|
||||||
mysqlclient
|
mysqlclient
|
||||||
|
django-ipware
|
||||||
Reference in New Issue
Block a user