This commit is contained in:
DerTyp187
2021-11-23 18:59:31 +01:00
parent c6ae46342e
commit 073c79bad5
17 changed files with 5 additions and 174 deletions

View File

@@ -41,8 +41,6 @@ INSTALLED_APPS = [
'django.contrib.messages',
'django.contrib.staticfiles',
'main.apps.MainConfig',
'analytics.apps.AnalyticsConfig',
'ipware',
]
MIDDLEWARE = [

View File

@@ -19,7 +19,6 @@ from django.views.generic.base import TemplateView
urlpatterns = [
path('', include('main.urls')),
path('analytics/', include('analytics.urls')),
path("robots.txt", TemplateView.as_view(template_name="robots.txt", content_type="text/plain")),
path('AD/SDGFOLKJASDNVASDFASDFSLAKDF/', admin.site.urls),
]

View File

@@ -1,5 +0,0 @@
from django.contrib import admin
from analytics.models import View
admin.site.register(View)

View File

@@ -1,6 +0,0 @@
from django.apps import AppConfig
class AnalyticsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'analytics'

View File

@@ -1,29 +0,0 @@
# Generated by Django 3.2.9 on 2021-11-22 18:23
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
class Migration(migrations.Migration):
initial = True
dependencies = [
('main', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='View',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('ip', models.CharField(max_length=200)),
('date', models.DateTimeField(default=django.utils.timezone.now)),
('admin', models.BooleanField(default=False)),
('home', models.BooleanField(default=False)),
('category', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='main.category')),
('topic', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='main.topic')),
],
),
]

View File

@@ -1,31 +0,0 @@
# Generated by Django 3.2.9 on 2021-11-23 13:15
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('analytics', '0001_initial'),
]
operations = [
migrations.RemoveField(
model_name='view',
name='admin',
),
migrations.RemoveField(
model_name='view',
name='home',
),
migrations.AddField(
model_name='view',
name='country',
field=models.CharField(blank=True, max_length=250),
),
migrations.AddField(
model_name='view',
name='custom_title',
field=models.CharField(blank=True, max_length=250),
),
]

View File

@@ -1,23 +0,0 @@
# Generated by Django 3.2.9 on 2021-11-23 13:20
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('analytics', '0002_auto_20211123_1415'),
]
operations = [
migrations.AddField(
model_name='view',
name='city',
field=models.CharField(blank=True, max_length=250),
),
migrations.AddField(
model_name='view',
name='state',
field=models.CharField(blank=True, max_length=250),
),
]

View File

@@ -1,35 +0,0 @@
from django.db import models
from django.utils import timezone
from main.models import Topic, Category
class View(models.Model):
ip = models.CharField(max_length=200)
date = models.DateTimeField(default=timezone.now)
country = models.CharField(max_length=250, blank=True)
state = models.CharField(max_length=250, blank=True)
city = models.CharField(max_length=250, blank=True)
topic = models.ForeignKey(Topic, on_delete=models.CASCADE, blank=True, null=True)
category = models.ForeignKey(Category, on_delete=models.CASCADE, blank=True, null=True)
custom_title = models.CharField(max_length=250, blank=True)
def __str__(self):
a = self.ip
if self.country:
a = a + " - " + self.country
if self.topic:
a = a + " - " + self.topic.title
if self.category:
a = a + " - " + self.category.title
if self.custom_title:
a = a + " - " + self.custom_title
a = a + " - " + str(self.date.day) + "." + str(self.date.month) + "." + str(self.date.year)
return a

View File

@@ -1,5 +0,0 @@
{% extends "base.html" %}
{% block content %}
<h2>Analytics</h2>
{% endblock content %}

View File

@@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View File

@@ -1,6 +0,0 @@
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name="analytics-index"),
]

View File

@@ -1,6 +0,0 @@
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
@login_required
def index(req):
return render(req, 'analytics/index.html')

View File

@@ -1,4 +1,4 @@
# Generated by Django 3.2.9 on 2021-11-22 18:23
# Generated by Django 3.2.9 on 2021-11-23 17:55
from django.db import migrations, models
import django.db.models.deletion

View File

@@ -4,14 +4,9 @@
<head>
<!-- Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-PGM5LTFSMG"></script>
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-213552250-1', {
'storage': 'none',
});
ga('send', 'pageview');
</script>
<script>window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;ga('create', 'UA-213552250-1', {'storage': 'none',});ga('send', 'pageview');</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>
<script src="{% static 'js/cookies.js' %}"></script>
<!-- End Google Analytics -->
<!-- Required META Tags-->
@@ -38,7 +33,7 @@
{% endif %}
</head>
<body class="bg-dark">
<script src="{% static 'js/cookies.js' %}"></script>
<header class="p-3 bg-dark text-white shadow">

View File

@@ -1,11 +1,8 @@
from django.http.response import HttpResponse, HttpResponseForbidden
from django.http.response import HttpResponse
from django.shortcuts import render, redirect
from .models import Category, Topic, Rating
from analytics.models import View
def index(req):
view = View(ip=get_ip(req), custom_title="index")
view.save()
categorys_obj = Category.objects.all()
return render(req, "main/index.html", {'categorys': categorys_obj})
@@ -40,10 +37,6 @@ def topic(req, category, topic):
'notHelpful_count': notHelpful_count,
'read_more': topic_obj.read_more,
}
view = View(ip=get_ip(req), topic=topic_obj)
view.save()
return render(req, "main/topic.html", context)
return redirect("main-index")
@@ -57,9 +50,6 @@ def category(req, category):
if category_obj:
topics_obj = Topic.objects.filter(category=category_obj)
view = View(ip=get_ip(req), category=category_obj)
view.save()
context = {
'category_obj': category_obj,
'topics': topics_obj,
@@ -83,8 +73,6 @@ def search(req, value): # https://django-taggit.readthedocs.io/en/latest/getting
def sitemap(req):
topics = Topic.objects.all()
categories = Category.objects.all()
#REPLACE ALL BLANKS WITH %20
context = {
'topics': topics,