diff --git a/django_code/apps/website_redirection/admin.py b/django_code/apps/website_redirection/admin.py index 5b99b4f..b3172de 100644 --- a/django_code/apps/website_redirection/admin.py +++ b/django_code/apps/website_redirection/admin.py @@ -1,5 +1,5 @@ from django.contrib import admin -from .models import redirectData +from .models import historicalData,redirectData from .utils import redirect_method from import_export.admin import ImportExportModelAdmin @@ -19,7 +19,13 @@ def re_redirect(modeladmin, request, queryset): output_generated ) +@admin.register(historicalData) +class historicalAdmin(ImportExportModelAdmin): + list_display = [field.name for field in historicalData._meta.fields if field.name != 'id'] + actions = [re_redirect] + + @admin.register(redirectData) class redirectAdmin(ImportExportModelAdmin): list_display = [field.name for field in redirectData._meta.fields if field.name != 'id'] - actions = [re_redirect] \ No newline at end of file + \ No newline at end of file diff --git a/django_code/apps/website_redirection/migrations/0004_rename_redirectdata_historicaldata.py b/django_code/apps/website_redirection/migrations/0004_rename_redirectdata_historicaldata.py new file mode 100644 index 0000000..88077b5 --- /dev/null +++ b/django_code/apps/website_redirection/migrations/0004_rename_redirectdata_historicaldata.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.30 on 2026-07-28 09:11 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('redirect', '0003_redirectdata_key'), + ] + + operations = [ + migrations.RenameModel( + old_name='redirectData', + new_name='historicalData', + ), + ] diff --git a/django_code/apps/website_redirection/migrations/0005_alter_historicaldata_seendate.py b/django_code/apps/website_redirection/migrations/0005_alter_historicaldata_seendate.py new file mode 100644 index 0000000..dbee48f --- /dev/null +++ b/django_code/apps/website_redirection/migrations/0005_alter_historicaldata_seendate.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.30 on 2026-07-28 09:14 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('redirect', '0004_rename_redirectdata_historicaldata'), + ] + + operations = [ + migrations.AlterField( + model_name='historicaldata', + name='seenDate', + field=models.DateField(blank=True, null=True, verbose_name='Seen'), + ), + ] diff --git a/django_code/apps/website_redirection/migrations/0006_alter_historicaldata_table.py b/django_code/apps/website_redirection/migrations/0006_alter_historicaldata_table.py new file mode 100644 index 0000000..d7a1fc5 --- /dev/null +++ b/django_code/apps/website_redirection/migrations/0006_alter_historicaldata_table.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.30 on 2026-07-28 09:15 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('redirect', '0005_alter_historicaldata_seendate'), + ] + + operations = [ + migrations.AlterModelTable( + name='historicaldata', + table='historical', + ), + ] diff --git a/django_code/apps/website_redirection/migrations/0007_redirectdata.py b/django_code/apps/website_redirection/migrations/0007_redirectdata.py new file mode 100644 index 0000000..6a6ee83 --- /dev/null +++ b/django_code/apps/website_redirection/migrations/0007_redirectdata.py @@ -0,0 +1,24 @@ +# Generated by Django 4.2.30 on 2026-07-28 09:17 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('redirect', '0006_alter_historicaldata_table'), + ] + + operations = [ + migrations.CreateModel( + name='redirectData', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('key', models.CharField(default='streaming', max_length=1000)), + ('url', models.CharField(max_length=1000)), + ], + options={ + 'db_table': 'redirect', + }, + ), + ] diff --git a/django_code/apps/website_redirection/models.py b/django_code/apps/website_redirection/models.py index b441355..3aa5857 100644 --- a/django_code/apps/website_redirection/models.py +++ b/django_code/apps/website_redirection/models.py @@ -1,10 +1,16 @@ from django.db import models -class redirectData(models.Model): +class historicalData(models.Model): url = models.CharField(max_length=1000) key = models.CharField(max_length=1000,default="streaming") addedDate = models.DateField('Published', blank=True, null=True, auto_now_add=True) - seenDate = models.DateField('Published', blank=True, null=True) + seenDate = models.DateField('Seen', blank=True, null=True) + class Meta: + db_table = 'historical' + +class redirectData(models.Model): + key = models.CharField(max_length=1000,default="streaming") + url = models.CharField(max_length=1000) class Meta: db_table = 'redirect' diff --git a/django_code/apps/website_redirection/utils.py b/django_code/apps/website_redirection/utils.py index 3e8d913..1c49bbe 100644 --- a/django_code/apps/website_redirection/utils.py +++ b/django_code/apps/website_redirection/utils.py @@ -1,16 +1,16 @@ -import redis -from .models import redirectData +from .models import historicalData,redirectData -r = redis.Redis( - host='django-redis-svc', - port=6379, - db=0 # The default Redis database index -) def redirect_method(key,value): key = key.lower() - r.set(key, value) - redirectData.objects.create(url=value,key=key) + + #Add to the redirect database to be used as a redirection point + # using update_or_create so there is no duplicate of one index/key + redirectData.objects.update_or_create(key=key,defaults={'url': value}) + + #Add to the historical database + historicalData.objects.create(url=value, key=key) + text_generated = "successfully set "+value+" to "+key return text_generated \ No newline at end of file diff --git a/django_code/apps/website_redirection/views.py b/django_code/apps/website_redirection/views.py index 4a32330..ec1b57c 100644 --- a/django_code/apps/website_redirection/views.py +++ b/django_code/apps/website_redirection/views.py @@ -2,22 +2,15 @@ from django.shortcuts import render from django.http import HttpResponse from django.http import HttpResponseRedirect from django.apps import AppConfig -from .models import redirectData +from .models import historicalData,redirectData from .utils import redirect_method -import redis + def hello(request): return HttpResponse('