testing #26

Merged
pi-ux-ce merged 6 commits from testing into main 2026-07-28 14:02:12 +00:00
12 changed files with 147 additions and 33 deletions
+10
View File
@@ -0,0 +1,10 @@
.git
.github
**/__pycache__
*.pyc
.pytest_cache
media
staticfiles
*.sqlite3
node_modules
.env
@@ -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]
@@ -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',
),
]
@@ -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'),
),
]
@@ -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',
),
]
@@ -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',
},
),
]
@@ -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'
@@ -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
+12 -16
View File
@@ -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('<h1>Hello Django!</h1>')
r = redis.Redis(
host='django-redis-svc',
port=6379,
db=0 # The default Redis database index
)
def hello(request):
return HttpResponse('<h1>Hello redirect!</h1>')
@@ -27,7 +20,8 @@ def redirect(request):
def clearkey_process(request):
key = request.GET.get('key')
r.delete(key)
#commenting this for now , need to see if the function is usefull
#r.delete(key)
return 0
def redirect_process(request):
@@ -39,22 +33,24 @@ def redirect_process(request):
return HttpResponse(text_generated, content_type="text/plain")
def display_key(request,key):
value = r.get(key)
value = redirectData.objects.filter(key=key).values('url')[0]['url']
value_extracted = str(value.decode())
text_generated = key+" is set to "+value_extracted
return HttpResponse(text_generated, content_type="text/plain")
def redirect_to_key(request,key):
value = r.get(key)
redirect_object = redirectData.objects.filter(key=key)
value = str(redirect_object.values('url')[0]['url'])
if value == None:
icon_url = r.get('icon')
if icon_url == None:
icon_url = "https://cdn-icons-png.flaticon.com/512/6402/6402576.png"
#get the icon url, if it doesn't exist , create it with a default icon
icon_url = redirectData.objects.get_or_create(key="icon",defaults={'url':"https://cdn-icons-png.flaticon.com/512/6402/6402576.png"})[0].url
print(key+" is not setup, displaying default page")
return render(request, 'website_redirection/blank_page.html', {'title': key,'icon_url':icon_url})
else:
value_extracted = str(value.decode('utf-8'))
value_extracted = str(value)
print(key+" is setup to : "+value_extracted)
print(value_extracted)
return HttpResponseRedirect(value_extracted)
+1 -1
View File
@@ -42,7 +42,7 @@ urlpatterns = [
path('redirect/set/', website_redirectionapp.redirect),
path('redirect/get/<str:key>', website_redirectionapp.display_key),
path('redirect/go/<str:key>', website_redirectionapp.redirect_to_key),
path('redirect/redirect-form/', website_redirectionapp.redirect_process, name='submit_form'),
path('redirect-form/', website_redirectionapp.redirect_process, name='submit_form'),
path('redirect/clearkey/', website_redirectionapp.clearkey_process, name='submit_form'),
################### onenote ###################
+15
View File
@@ -1,5 +1,20 @@
#!/bin/bash
python django_code/manage.py makemigrations
python django_code/manage.py makemigrations redirect
python django_code/manage.py makemigrations cloudmanager
python django_code/manage.py makemigrations simpsons
python django_code/manage.py makemigrations job
python django_code/manage.py makemigrations telegram
python django_code/manage.py makemigrations podcast
python django_code/manage.py migrate
python django_code/manage.py migrate --database=cloudmanager_db
python django_code/manage.py migrate --database=simpsons_db
python django_code/manage.py migrate --database=redirect_db
python django_code/manage.py migrate --database=job_db
python django_code/manage.py migrate --database=telegram_db
python django_code/manage.py migrate --database=podcast_db
python django_code/manage.py runserver "0.0.0.0:8000"
+8 -3
View File
@@ -9,19 +9,24 @@ ENV DEBUG 'True'
WORKDIR /code/
# Install build tools and MaxMind library
RUN apt-get update && \
apt-get install -y git nano && \
rm -rf /var/lib/apt/lists/*
# Clone the project
RUN git clone -b testing https://gitea.tryton.geeraert.eu/pi-ux-ce/Django_kube.git
# Copy only the requirements file first (Changes infrequently)
COPY requirements.txt ./
RUN pip install --cache-dir=/opt/hostedtoolcache/pip --upgrade pip
RUN pip list --cache-dir=/opt/hostedtoolcache/pip --outdated
RUN pip install --cache-dir=/opt/hostedtoolcache/pip --upgrade wheel
RUN pip install --cache-dir=/opt/hostedtoolcache/pip --upgrade setuptools
RUN pip install --cache-dir=/opt/hostedtoolcache/pip -r Django_kube/requirements.txt
RUN pip install --cache-dir=/opt/hostedtoolcache/pip -r requirements.txt
# Copy the rest of your application code (Changes frequently, invalidates subsequent cache)
COPY . ./
COPY infra/testing/entrypoint.sh /code/entrypoint.sh
RUN chmod +x /code/entrypoint.sh