Compare commits
62
Commits
57f58b0c9a
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ff4f98841 | ||
|
|
0a8c337b1e | ||
|
|
2dac0d1f53 | ||
|
|
73b627214d | ||
|
|
c79168453b | ||
|
|
299f72abca | ||
|
|
058125f0b1 | ||
|
|
130b0af8d8 | ||
|
|
6f7542ef27 | ||
|
|
919d1a3a28 | ||
|
|
3c4c32e72d | ||
|
|
3294e70b3f | ||
|
|
5908d8d282 | ||
|
|
32f8251a90 | ||
|
|
a3fec86eae | ||
|
|
672edccd70 | ||
|
|
f188e25453 | ||
|
|
d4a72ebf5d | ||
|
|
4492db4185 | ||
|
|
015edcd63d | ||
|
|
aaad6b2b7e | ||
|
|
3b6eccba80 | ||
|
|
44b730dbfc | ||
|
|
ea4ebb0de0 | ||
|
|
3b3e82f16a | ||
|
|
1430afe600 | ||
|
|
e3f01da175 | ||
|
|
7a5c7b6de9 | ||
|
|
c880172aa5 | ||
|
|
6b631fb3e3 | ||
|
|
712f3d50b5 | ||
|
|
f6875b498b | ||
|
|
2e728d4698 | ||
|
|
98a969fa04 | ||
|
|
154717aca7 | ||
|
|
cc0eb74090 | ||
|
|
e2f49a5b1f | ||
|
|
c8ceaab950 | ||
|
|
3fbf333d3d | ||
|
|
3cb09b34da | ||
|
|
1d9d723ce9 | ||
|
|
cf06bfd1bd | ||
|
|
df7340e578 | ||
|
|
7a02fb89f4 | ||
|
|
bfdf8b3b2a | ||
|
|
1ae2917263 | ||
|
|
1fea1c9e23 | ||
|
|
fa804dbed1 | ||
|
|
3b28145d0a | ||
|
|
e9bf6ba7b5 | ||
|
|
cc3394d5eb | ||
|
|
90156a4733 | ||
|
|
314a6f1bed | ||
|
|
eab0ddd697 | ||
|
|
3c1960f015 | ||
|
|
3ff4dd1fae | ||
|
|
dbeaf4c58c | ||
|
|
0f49484a43 | ||
|
|
b540c7b7e8 | ||
|
|
1012ea31ad | ||
|
|
a00baa490f | ||
|
|
bc9e331c68 |
@@ -15,9 +15,9 @@ jobs:
|
||||
env:
|
||||
RUNNER_TOOL_CACHE: /toolcache
|
||||
DEBUG: True
|
||||
ALLOWED_HOSTS: "django.tryton.geeraert.eu"
|
||||
ALLOWED_HOSTS: "django.geeraert.eu"
|
||||
container:
|
||||
image: gitea.tryton.geeraert.eu/pi-ux-ce/custom-runner-debian-slim:1.0.6
|
||||
image: gitea.geeraert.eu/pi-ux-ce/custom-runner-debian-slim:1.0.6
|
||||
volumes:
|
||||
- act-toolcache:/opt/hostedtoolcache # this is where Runner store their cache default
|
||||
runs-on: host-runner
|
||||
@@ -59,7 +59,7 @@ jobs:
|
||||
- name: Login to gitea
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: gitea.tryton.geeraert.eu
|
||||
registry: gitea.geeraert.eu
|
||||
username: ${{ secrets.USERNAME_GITEA }}
|
||||
password: ${{ secrets.PASSWORD_GITEA }}
|
||||
|
||||
@@ -67,16 +67,16 @@ jobs:
|
||||
run: |
|
||||
docker build \
|
||||
-f infra/production/dockerfile \
|
||||
--build-arg ALLOWED_HOSTS='django.tryton.geeraert.eu' \
|
||||
--build-arg ALLOWED_HOSTS='django.geeraert.eu' \
|
||||
--build-arg DEBUG='True' \
|
||||
-t gitea.tryton.geeraert.eu/pi-ux-ce/django-python:latest \
|
||||
-t gitea.tryton.geeraert.eu/pi-ux-ce/django-python:${{ env.next_version }} \
|
||||
-t gitea.geeraert.eu/pi-ux-ce/django-python:latest \
|
||||
-t gitea.geeraert.eu/pi-ux-ce/django-python:${{ env.next_version }} \
|
||||
.
|
||||
|
||||
- name: Push image
|
||||
run: |
|
||||
docker push gitea.tryton.geeraert.eu/pi-ux-ce/django-python:latest
|
||||
docker push gitea.tryton.geeraert.eu/pi-ux-ce/django-python:${{ env.next_version }}
|
||||
docker push gitea.geeraert.eu/pi-ux-ce/django-python:latest
|
||||
docker push gitea.geeraert.eu/pi-ux-ce/django-python:${{ env.next_version }}
|
||||
|
||||
- name: Rollout Django to force pulling the new image
|
||||
uses: actions-hub/kubectl@master
|
||||
@@ -91,7 +91,7 @@ jobs:
|
||||
run: |
|
||||
curl -X PUT -H "Content-Type: application/json" \
|
||||
--user ${{ secrets.USERNAME_GITEA }}:${{ secrets.PASSWORD_GITEA }} \
|
||||
https://gitea.tryton.geeraert.eu/api/v1/repos/pi-ux-ce/${{ github.event.repository.name }}/actions/variables/VERSION \
|
||||
https://gitea.geeraert.eu/api/v1/repos/pi-ux-ce/${{ github.event.repository.name }}/actions/variables/VERSION \
|
||||
-d "{\"Value\":\"$next_version\"}"
|
||||
|
||||
- name: backup git for future use
|
||||
|
||||
@@ -36,7 +36,7 @@ jobs:
|
||||
- name: Login to gitea
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: gitea.tryton.geeraert.eu
|
||||
registry: gitea.geeraert.eu
|
||||
username: ${{ secrets.USERNAME_GITEA }}
|
||||
password: ${{ secrets.PASSWORD_GITEA }}
|
||||
|
||||
@@ -44,23 +44,23 @@ jobs:
|
||||
run: |
|
||||
docker build \
|
||||
-f infra/testing/dockerfile \
|
||||
--build-arg ALLOWED_HOSTS='django-testing.tryton.geeraert.eu' \
|
||||
--build-arg ALLOWED_HOSTS='django-testing.geeraert.eu' \
|
||||
--build-arg DEBUG='True' \
|
||||
--build-arg CACHE_BUST=${{ env.next_version }} \
|
||||
-t gitea.tryton.geeraert.eu/pi-ux-ce/django-testing:latest \
|
||||
-t gitea.tryton.geeraert.eu/pi-ux-ce/django-testing:${{ env.next_version }} \
|
||||
-t gitea.geeraert.eu/pi-ux-ce/django-testing:latest \
|
||||
-t gitea.geeraert.eu/pi-ux-ce/django-testing:${{ env.next_version }} \
|
||||
.
|
||||
|
||||
- name: Push image
|
||||
run: |
|
||||
docker push gitea.tryton.geeraert.eu/pi-ux-ce/django-testing:latest
|
||||
docker push gitea.tryton.geeraert.eu/pi-ux-ce/django-testing:${{ env.next_version }}
|
||||
docker push gitea.geeraert.eu/pi-ux-ce/django-testing:latest
|
||||
docker push gitea.geeraert.eu/pi-ux-ce/django-testing:${{ env.next_version }}
|
||||
|
||||
- name: update version in the variable
|
||||
run: |
|
||||
curl -X PUT -H "Content-Type: application/json" \
|
||||
--user ${{ secrets.USERNAME_GITEA }}:${{ secrets.PASSWORD_GITEA }} \
|
||||
https://gitea.tryton.geeraert.eu/api/v1/repos/pi-ux-ce/${{ github.event.repository.name }}/actions/variables/VERSION_TESTING \
|
||||
https://gitea.geeraert.eu/api/v1/repos/pi-ux-ce/${{ github.event.repository.name }}/actions/variables/VERSION_TESTING \
|
||||
-d "{\"Value\":\"$next_version\"}"
|
||||
|
||||
- name: Rollout Django to force pulling the new image
|
||||
|
||||
@@ -72,14 +72,14 @@ export bitwarden_organization_id=""
|
||||
|
||||
```
|
||||
cd existing_repo
|
||||
git remote add origin https://gitlab.tryton.geeraert.eu/pierre/django_kube.git
|
||||
git remote add origin https://gitea.geeraert.eu/pi-ux-ce/Django_kube.git
|
||||
git branch -M main
|
||||
git push -uf origin main
|
||||
```
|
||||
|
||||
## Integrate with your tools
|
||||
|
||||
- [ ] [Set up project integrations](https://gitlab.tryton.geeraert.eu/pierre/django_kube/-/settings/integrations)
|
||||
- [ ] [Set up project integrations](https://gitlab.geeraert.eu/pierre/django_kube/-/settings/integrations)
|
||||
|
||||
## Collaborate with your team
|
||||
|
||||
|
||||
@@ -59,7 +59,25 @@ class betaserieUtils():
|
||||
show_id = response.json()['shows'][0]['id']
|
||||
|
||||
return show_id
|
||||
|
||||
|
||||
def poster_serie(self,serie_name,verbose=False):
|
||||
#
|
||||
# Usage
|
||||
# poster_url = beta.poster_serie("The simpsons")
|
||||
# poster_url = beta.poster_serie("The simpsons",verbose=True)
|
||||
#
|
||||
url = "https://api.betaseries.com/shows/search?title="+serie_name
|
||||
|
||||
response = requests.request("GET", url, headers=self.headers, data=self.payload)
|
||||
if verbose:
|
||||
print("Url request: "+str(url))
|
||||
print(response.text)
|
||||
|
||||
poster_url = response.json()['shows'][0]['images']['show']
|
||||
|
||||
return poster_url
|
||||
|
||||
|
||||
def identify_episode(self,show_id,episode_number,verbose=False):
|
||||
#
|
||||
# Usage
|
||||
|
||||
@@ -12,9 +12,9 @@ class bitwardenUtils():
|
||||
client = BitwardenClient(
|
||||
client_settings_from_dict(
|
||||
{
|
||||
"apiUrl": os.getenv("API_URL", "https://bitwarden.tryton.geeraert.eu/api"),
|
||||
"apiUrl": os.getenv("API_URL", "https://bitwarden.geeraert.eu/api"),
|
||||
"deviceType": DeviceType.SDK,
|
||||
"identityUrl": os.getenv("IDENTITY_URL", "https://bitwarden.tryton.geeraert.eu/identity"),
|
||||
"identityUrl": os.getenv("IDENTITY_URL", "https://bitwarden.geeraert.eu/identity"),
|
||||
"userAgent": "Python",
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
from django.contrib import admin,messages
|
||||
from django.utils.translation import ngettext
|
||||
from .models import Deployment_Data,Schedule_Day_Data,Schedule_Week_Data,Namespace_Data
|
||||
from .utils import import_namespace,import_deployment,generate_default_day_schedule,generate_default_week_schedule,Check_server_supposed_XXX
|
||||
from .models import Deployment_Data,Schedule_Day_Data,Schedule_Week_Data,Namespace_Data,Ingress_Data
|
||||
from .utils import import_namespace,import_deployment,generate_default_day_schedule,generate_default_week_schedule,Check_server_supposed_XXX,retrieve_and_apply
|
||||
from apps.kubernetes_connection.utils import scale_up,scale_down
|
||||
from admin_extra_buttons.api import button
|
||||
from core.admin import UniversalModelAdmin
|
||||
|
||||
DB = 'cloudmanager_db'
|
||||
|
||||
|
||||
@admin.action(description="scale up")
|
||||
@@ -49,21 +50,6 @@ def Check_server_supposed_true(modeladmin, request, queryset):
|
||||
servers_supposed_false = Check_server_supposed_XXX(True)
|
||||
for server in servers_supposed_false:
|
||||
messages.add_message(request, messages.INFO, server)
|
||||
|
||||
@admin.action(description="create default schedule")
|
||||
def generate_default_day_schedule_admin(modeladmin, request, queryset):
|
||||
generate_default_day_schedule()
|
||||
generate_default_week_schedule()
|
||||
|
||||
|
||||
@admin.action(description="import namespace")
|
||||
def import_namespace_admin(modeladmin, request, queryset):
|
||||
import_namespace()
|
||||
|
||||
@admin.action(description="import deployment")
|
||||
def import_deployment_admin(modeladmin, request, queryset):
|
||||
import_deployment()
|
||||
|
||||
|
||||
|
||||
class ActiveAtHourFilter(admin.SimpleListFilter):
|
||||
@@ -80,45 +66,58 @@ class ActiveAtHourFilter(admin.SimpleListFilter):
|
||||
return queryset
|
||||
|
||||
|
||||
class MultiDBModelAdmin(admin.ModelAdmin):
|
||||
"""Base class that pins all admin operations to DB."""
|
||||
db = DB
|
||||
|
||||
def get_queryset(self, request):
|
||||
return super().get_queryset(request).using(self.db)
|
||||
|
||||
def save_model(self, request, obj, form, change):
|
||||
obj.save(using=self.db)
|
||||
|
||||
def delete_model(self, request, obj):
|
||||
obj.delete(using=self.db)
|
||||
|
||||
def delete_queryset(self, request, queryset):
|
||||
queryset.using(self.db).delete()
|
||||
|
||||
|
||||
@admin.register(Deployment_Data)
|
||||
class DeploymentDataAdmin(MultiDBModelAdmin):
|
||||
class DeploymentDataAdmin(UniversalModelAdmin):
|
||||
list_display = ('name', 'namespace', 'schedule_week', 'schedule_day', 'replicas')
|
||||
list_filter = (ActiveAtHourFilter,)
|
||||
actions = [Check_server_supposed_False,Check_server_supposed_true,scale_up_deploy,scale_down_deploy,import_deployment_admin,generate_default_day_schedule_admin]
|
||||
|
||||
actions = [Check_server_supposed_False,Check_server_supposed_true,scale_up_deploy,scale_down_deploy]
|
||||
ordering = ('name',)
|
||||
@button()
|
||||
def retrieve_and_apply(self, request):
|
||||
# your business logic here
|
||||
retrieve_and_apply()
|
||||
self.message_user(request, 'Operation started')
|
||||
|
||||
@button()
|
||||
def import_deployment(self, request):
|
||||
# your business logic here
|
||||
import_deployment()
|
||||
self.message_user(request, 'Deployments imported')
|
||||
|
||||
@admin.register(Schedule_Day_Data)
|
||||
class ScheduleDayAdmin(MultiDBModelAdmin):
|
||||
class ScheduleDayAdmin(UniversalModelAdmin):
|
||||
list_display = ['name_schedule'] + [f'state_at_{h}' for h in range(24)]
|
||||
actions = [import_deployment_admin,generate_default_day_schedule_admin]
|
||||
@button()
|
||||
def generate_default_day_schedule_admin(self, request):
|
||||
generate_default_day_schedule()
|
||||
generate_default_week_schedule()
|
||||
self.message_user(request, 'Created default schedules')
|
||||
|
||||
@admin.register(Schedule_Week_Data)
|
||||
class ScheduleWeekAdmin(MultiDBModelAdmin):
|
||||
class ScheduleWeekAdmin(UniversalModelAdmin):
|
||||
list_display = (
|
||||
'name_schedule',
|
||||
'state_Monday', 'state_Tuesday', 'state_Wednesday',
|
||||
'state_Thursday', 'state_Friday', 'state_Saturday', 'state_Sunday',
|
||||
)
|
||||
actions = [import_deployment_admin,generate_default_day_schedule_admin]
|
||||
@button()
|
||||
def generate_default_day_schedule_admin(self, request):
|
||||
generate_default_day_schedule()
|
||||
generate_default_week_schedule()
|
||||
self.message_user(request, 'Created default schedules')
|
||||
|
||||
|
||||
@admin.register(Namespace_Data)
|
||||
class NamespaceAdmin(MultiDBModelAdmin):
|
||||
class NamespaceAdmin(UniversalModelAdmin):
|
||||
list_display = ('namespace',)
|
||||
actions = [import_namespace_admin]
|
||||
|
||||
|
||||
@button()
|
||||
def import_namespace(self, request):
|
||||
# your business logic here
|
||||
import_namespace()
|
||||
self.message_user(request, 'Namespaces imported')
|
||||
|
||||
@admin.register(Ingress_Data)
|
||||
class IngressAdmin(UniversalModelAdmin):
|
||||
list_display = ('url','namespace')
|
||||
@@ -1,37 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
from django.http import HttpResponse
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render
|
||||
import os
|
||||
#import psycopg2
|
||||
from apps.cloudmanager.db_interaction import DB_generation,Check_server_supposed_XXX,Give_current_weekday,Give_current_hour
|
||||
|
||||
|
||||
class CloudmanagerConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'apps.cloudmanager'
|
||||
label = 'cloudmanager'
|
||||
|
||||
def coucou(request):
|
||||
return HttpResponse('<h1>Hello cmm!</h1>')
|
||||
|
||||
def hello(request):
|
||||
list_schedule = ['schedule1','schedule2']
|
||||
list_servers_up = [['wiki', 'wikijs', 2], ['book', 'bookstack-db', 1]]
|
||||
return render(request, 'cloudmanager/index.html', {'list_schedule':list_schedule,'list_servers_up':list_servers_up})
|
||||
|
||||
def redirect(request):
|
||||
db_host = os.environ.get('DB_HOST')
|
||||
db_port = os.environ.get('DB_PORT')
|
||||
db_user = os.environ.get('DB_USERNAME')
|
||||
db_password = os.environ.get('DB_PASSWORD')
|
||||
db_name = os.environ.get('CUSTOM_DB_DATABASE',os.environ.get('DB_DATABASE'))
|
||||
|
||||
generated_db = DB_generation(db_host, db_port, db_user, db_password,db_name)
|
||||
##operation:
|
||||
## Server(s) supposed to be UP
|
||||
|
||||
list_servers_up = Check_server_supposed_XXX(generated_db, "up", Give_current_hour(),Give_current_weekday())
|
||||
print(list_servers_up)
|
||||
return render(request, 'cloudmanager/cmm_blank_page.html', {'list_servers_up':list_servers_up})
|
||||
|
||||
|
||||
@@ -153,10 +153,6 @@ def main(request):
|
||||
|
||||
#print(Is_the_server_already_wanted_state(112, "stopped"))
|
||||
return HttpResponse('<h1>CMM executed!</h1>')
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
||||
"""
|
||||
TO DO:
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.2.29 on 2026-09-13 15:38
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cloudmanager', '0002_deployment_data_actual_replica'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='deployment_data',
|
||||
name='do_not_touch_until',
|
||||
field=models.DateField(blank=True, null=True, verbose_name='do_not_touch_until'),
|
||||
),
|
||||
]
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.2.30 on 2026-09-14 13:59
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cloudmanager', '0003_deployment_data_do_not_touch_until'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='deployment_data',
|
||||
name='do_not_touch_until',
|
||||
field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='do_not_touch_until'),
|
||||
),
|
||||
]
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
# Generated by Django 4.2.30 on 2026-09-14 14:14
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cloudmanager', '0004_alter_deployment_data_do_not_touch_until'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='deployment_data',
|
||||
name='do_not_touch_until',
|
||||
field=models.DateTimeField(default=datetime.datetime(2026, 9, 14, 14, 14, 29, 566084, tzinfo=datetime.timezone.utc), verbose_name='do_not_touch_until'),
|
||||
),
|
||||
]
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
# Generated by Django 4.2.30 on 2026-09-14 14:14
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cloudmanager', '0005_alter_deployment_data_do_not_touch_until'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='deployment_data',
|
||||
name='do_not_touch_until',
|
||||
field=models.DateTimeField(default=datetime.datetime(2026, 9, 14, 14, 14, 33, 642627, tzinfo=datetime.timezone.utc), verbose_name='do_not_touch_until'),
|
||||
),
|
||||
]
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
# Generated by Django 4.2.30 on 2026-09-14 14:35
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cloudmanager', '0006_alter_deployment_data_do_not_touch_until'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='deployment_data',
|
||||
name='do_not_touch_until',
|
||||
field=models.DateTimeField(default=datetime.datetime(2026, 9, 14, 14, 35, 47, 473312, tzinfo=datetime.timezone.utc), verbose_name='do_not_touch_until'),
|
||||
),
|
||||
]
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
# Generated by Django 4.2.30 on 2026-09-14 14:35
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cloudmanager', '0007_alter_deployment_data_do_not_touch_until'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='deployment_data',
|
||||
name='do_not_touch_until',
|
||||
field=models.DateTimeField(default=datetime.datetime(2026, 9, 14, 14, 35, 51, 657797, tzinfo=datetime.timezone.utc), verbose_name='do_not_touch_until'),
|
||||
),
|
||||
]
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
# Generated by Django 4.2.30 on 2026-09-14 14:43
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cloudmanager', '0008_alter_deployment_data_do_not_touch_until'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='deployment_data',
|
||||
name='do_not_touch_until',
|
||||
field=models.DateTimeField(default=datetime.datetime(2026, 9, 14, 14, 43, 26, 985719, tzinfo=datetime.timezone.utc), verbose_name='do_not_touch_until'),
|
||||
),
|
||||
]
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
# Generated by Django 4.2.30 on 2026-09-14 14:43
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cloudmanager', '0009_alter_deployment_data_do_not_touch_until'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='deployment_data',
|
||||
name='do_not_touch_until',
|
||||
field=models.DateTimeField(default=datetime.datetime(2026, 9, 14, 14, 43, 31, 55115, tzinfo=datetime.timezone.utc), verbose_name='do_not_touch_until'),
|
||||
),
|
||||
]
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.2.30 on 2026-09-14 14:46
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cloudmanager', '0010_alter_deployment_data_do_not_touch_until'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='deployment_data',
|
||||
name='do_not_touch_until',
|
||||
field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='do_not_touch_until'),
|
||||
),
|
||||
]
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
# Generated by Django 4.2.30 on 2026-09-14 15:13
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cloudmanager', '0011_alter_deployment_data_do_not_touch_until'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='deployment_data',
|
||||
name='do_not_touch_until',
|
||||
field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='do_not_touch_until'),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,22 @@
|
||||
# Generated by Django 4.2.30 on 2026-09-21 16:14
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cloudmanager', '0012_alter_deployment_data_do_not_touch_until'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Ingress_Data',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('url', models.CharField(max_length=100)),
|
||||
('namespace', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='cloudmanager.namespace_data')),
|
||||
],
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.2.30 on 2026-09-21 21:06
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cloudmanager', '0013_ingress_data'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='ingress_data',
|
||||
name='namespace',
|
||||
field=models.CharField(blank=True, max_length=100, null=True),
|
||||
),
|
||||
]
|
||||
@@ -1,7 +1,5 @@
|
||||
from django.db import models
|
||||
|
||||
|
||||
|
||||
from django.utils import timezone
|
||||
|
||||
class Schedule_Week_Data(models.Model):
|
||||
name_schedule = models.CharField(max_length=100,unique=True)
|
||||
@@ -55,6 +53,7 @@ class Deployment_Data(models.Model):
|
||||
schedule_day = models.ForeignKey(Schedule_Day_Data,null=True, blank=True, on_delete=models.SET_NULL)
|
||||
replicas = models.IntegerField()
|
||||
actual_replica = models.IntegerField()
|
||||
do_not_touch_until = models.DateTimeField('do_not_touch_until', default=timezone.now)
|
||||
class Meta:
|
||||
db_table = 'machine'
|
||||
|
||||
@@ -63,3 +62,9 @@ class Namespace_Data(models.Model):
|
||||
#deployments = models.ForeignKey(Schedule_Week_Data,null=True, blank=True, on_delete=models.SET_NULL)
|
||||
class Meta:
|
||||
db_table = 'namespace'
|
||||
def __str__(self):
|
||||
return self.namespace
|
||||
|
||||
class Ingress_Data(models.Model):
|
||||
url = models.CharField(max_length=100)
|
||||
namespace = models.CharField(max_length=100,null=True, blank=True)
|
||||
|
||||
@@ -15,25 +15,19 @@ Including another URLconf
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.urls import path
|
||||
from apps.cloudmanager import apps as cloudmanager_apps
|
||||
from apps.cloudmanager import views as cloudmanager_views
|
||||
|
||||
from .views import hello,import_namespace_view,retrieve_and_apply_view,scale_up_gui,scale_down_gui,add_ingress,delete_ingress
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
################### cloudmanager ###################
|
||||
path('', cloudmanager_apps.redirect),
|
||||
path('hello', cloudmanager_apps.hello, name='hello'),
|
||||
path('coucou', cloudmanager_views.coucou, name='coucou'),
|
||||
path('display', cloudmanager_views.display, name='display'),
|
||||
#path('/run-action/', cloudmanager_views.trigger_my_action, name='run_my_action_url'),
|
||||
#path('change-schedule/', cloudmanager_views.change_schedule, name='change_schedule'),
|
||||
#path('/main/', db_interaction.main),
|
||||
|
||||
################### onenote ###################
|
||||
path('dashboard/', dashboardapp.hello),
|
||||
path('view/about', dashboardview.about),
|
||||
path('view/home', dashboardview.home),
|
||||
path('view/success', dashboardview.success),
|
||||
path('scale_up/<str:namespace_name>/<str:deploy_name>', dashboardview.scale_up),
|
||||
path('scale_down/<str:namespace_name>/<str:deploy_name>', dashboardview.scale_down),
|
||||
path('', hello, name='hello'),
|
||||
path('import_namespace', import_namespace_view, name='import_namespace'),
|
||||
path('retrieve_and_apply_view', retrieve_and_apply_view, name='retrieve_and_apply_view'),
|
||||
path('scale_up/<str:namespace_name>/<str:deploy_name>', scale_up_gui),
|
||||
path('scale_down/<str:namespace_name>/<str:deploy_name>', scale_down_gui),
|
||||
path('add_ingress', add_ingress),
|
||||
path('delete_ingress', delete_ingress),
|
||||
|
||||
|
||||
]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import datetime
|
||||
|
||||
from django.utils import timezone
|
||||
import datetime
|
||||
from apps.kubernetes_connection.utils import get_namespace,get_deployments,scale_up,scale_down
|
||||
from apps.cloudmanager.models import Schedule_Day_Data,Schedule_Week_Data,Namespace_Data,Deployment_Data
|
||||
|
||||
@@ -17,8 +17,13 @@ def import_deployment():
|
||||
Schedule_Week_Always_off,Schedule_Week_Always_on = generate_default_week_schedule()
|
||||
|
||||
for deployment in deployment_list:
|
||||
#if the replicas is originally 0 , it means it is disabled so put the schedule as always off
|
||||
if deployment[2] == 0:
|
||||
schedule_object = Schedule_Day_Always_off
|
||||
else:
|
||||
schedule_object = Schedule_Day_Always_on
|
||||
if deployment[0]!="kube-system":
|
||||
Deployment_Data.objects.get_or_create(namespace=deployment[0],name=deployment[1],defaults={"replicas":deployment[2],"actual_replica":deployment[2],"schedule_day":Schedule_Day_Always_on,"schedule_week":Schedule_Week_Always_on})
|
||||
Deployment_Data.objects.get_or_create(namespace=deployment[0],name=deployment[1],defaults={"replicas":deployment[2],"actual_replica":deployment[2],"schedule_day":schedule_object,"schedule_week":Schedule_Week_Always_on})
|
||||
|
||||
|
||||
def generate_default_day_schedule():
|
||||
@@ -92,6 +97,10 @@ def Check_server_supposed_XXX(expected_status,verbose=False):
|
||||
|
||||
|
||||
def retrieve_and_apply(verbose=False):
|
||||
output = ""
|
||||
output += str(Give_current_hour())
|
||||
output += str("\n")
|
||||
|
||||
|
||||
#Get current replica to compare with the replicas created at the start
|
||||
get_current_replicas()
|
||||
@@ -104,8 +113,14 @@ def retrieve_and_apply(verbose=False):
|
||||
#check if the expected replica (server[2]) match the current replica of the deployment (server[3].actual_replica)
|
||||
if server[3].actual_replica == server[2]:
|
||||
if verbose : print("name: "+str(server[1])+" namespace: "+str(server[0])+" already UP")
|
||||
elif server[3].do_not_touch_until > timezone.now():
|
||||
if verbose : print("name: "+str(server[1])+" namespace: "+str(server[0])+" is in freeze period")
|
||||
else:
|
||||
print("Starting -> name: "+str(server[1])+" namespace: "+str(server[0])+" replicas: "+str(server[2]))
|
||||
echo = "Starting -> name: "+str(server[1])+" namespace: "+str(server[0])+" replicas: "+str(server[2])
|
||||
output += str(echo)
|
||||
output += "\n"
|
||||
print(echo)
|
||||
|
||||
scale_up(namespace_name=server[1],deploy_name=server[0],replicas=server[2])
|
||||
|
||||
print("------------------------------------------")
|
||||
@@ -116,6 +131,14 @@ def retrieve_and_apply(verbose=False):
|
||||
#check if the current replica of the deployment (server[3].actual_replica) is already 0 meaning the server is already down
|
||||
if server[3].actual_replica == 0:
|
||||
if verbose : print("name: "+str(server[1])+" namespace: "+str(server[0])+" already DOWN")
|
||||
elif server[3].do_not_touch_until > timezone.now():
|
||||
if verbose : print("name: "+str(server[1])+" namespace: "+str(server[0])+" is in freeze period")
|
||||
else:
|
||||
print("Shutting down -> name: "+str(server[1])+" namespace: "+str(server[0])+" replicas: "+str(server[2]))
|
||||
|
||||
echo = "Shutting down -> name: "+str(server[1])+" namespace: "+str(server[0])+" replicas: "+str(server[2])
|
||||
output += str(echo)
|
||||
output += str("\n")
|
||||
print(echo)
|
||||
scale_down(namespace_name=server[1],deploy_name=server[0])
|
||||
print("------------------------------------------")
|
||||
return output
|
||||
@@ -1,25 +1,77 @@
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import render
|
||||
from datetime import timedelta
|
||||
from django.utils import timezone
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.http import JsonResponse
|
||||
|
||||
# IMPORT AT THE TOP HERE: This is completely safe!
|
||||
from apps.cloudmanager.models import Deployment_Data,Schedule_Week_Data
|
||||
from apps.import_aggregator.import_rest_framework import api_view, authentication_classes, permission_classes,TokenAuthentication,IsAuthenticated,Response,status
|
||||
|
||||
def coucou(request):
|
||||
# 1. Prepare the data inside the function
|
||||
data = CmmData(
|
||||
name="test",
|
||||
namespace="testspace",
|
||||
schedule_hour="1",
|
||||
schedule_day="deux",
|
||||
replicas=3
|
||||
)
|
||||
from .utils import import_namespace,retrieve_and_apply
|
||||
from apps.kubernetes_connection.utils import scale_up,scale_down
|
||||
from .models import Deployment_Data,Ingress_Data
|
||||
|
||||
# 2. This line actually pushes the data into your cloudmanager_db!
|
||||
data.save()
|
||||
def hello(request):
|
||||
list_schedule = ['schedule1','schedule2']
|
||||
list_servers_up = [['wiki', 'wikijs', 2], ['book', 'bookstack-db', 1]]
|
||||
return render(request, 'cloudmanager/index.html', {'list_schedule':list_schedule,'list_servers_up':list_servers_up})
|
||||
|
||||
return HttpResponse('<h1>Hello cmm! Data saved successfully!</h1>')
|
||||
def import_namespace_view(request):
|
||||
import_namespace()
|
||||
return HttpResponse('<h1>Namespace imported!</h1>')
|
||||
|
||||
def display(request):
|
||||
data = CmmData.objects.all()
|
||||
print(data[0].namespace)
|
||||
return HttpResponse(data)
|
||||
|
||||
def retrieve_and_apply_view(request):
|
||||
output = retrieve_and_apply()
|
||||
return HttpResponse('<h1>'+output+'</h1>')
|
||||
|
||||
def scale_up_gui(request,namespace_name,deploy_name,replicas=1):
|
||||
Deployment_Data.objects.filter(namespace=namespace_name,name=deploy_name).update(do_not_touch_until=timezone.now() + timedelta(hours=1))
|
||||
scale_up(namespace_name=namespace_name,deploy_name=deploy_name,replicas=replicas)
|
||||
return render(request, 'dashboard/start.html', {'namespace':namespace_name,'deployment': deploy_name, 'url': 'https://namespace.com'})
|
||||
|
||||
|
||||
def scale_down_gui(request,namespace_name,deploy_name):
|
||||
Deployment_Data.objects.filter(namespace=namespace_name,name=deploy_name).update(do_not_touch_until=timezone.now() + timedelta(hours=1))
|
||||
scale_down(namespace_name=namespace_name,deploy_name=deploy_name)
|
||||
return render(request, 'dashboard/shutdown.html',
|
||||
{'namespace': namespace_name, 'deployment': deploy_name, 'url': 'https://namespace.com'})
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([TokenAuthentication])
|
||||
@permission_classes([IsAuthenticated])
|
||||
def add_ingress(request):
|
||||
url = request.POST.get('url')
|
||||
namespace = request.POST.get('namespace')
|
||||
print("URL: "+str(url))
|
||||
print("NS: "+str(namespace))
|
||||
|
||||
try:
|
||||
Ingress_Data.objects.update_or_create(url=url,namespace=namespace)
|
||||
except Exception as exception:
|
||||
return JsonResponse({"status": "error","reason":str(exception)})
|
||||
|
||||
return JsonResponse({"status": "added","url":str(url),"namespace":str(namespace)})
|
||||
|
||||
@api_view(['POST'])
|
||||
@authentication_classes([TokenAuthentication])
|
||||
@permission_classes([IsAuthenticated])
|
||||
def delete_ingress(request):
|
||||
url = request.POST.get('url')
|
||||
namespace = request.POST.get('namespace')
|
||||
print("URL: "+str(url))
|
||||
print("NS: "+str(namespace))
|
||||
|
||||
try:
|
||||
ingress_object = Ingress_Data.objects.filter(url=url,namespace=namespace)
|
||||
except Exception as exception:
|
||||
return JsonResponse({"status": "error","reason":str(exception)})
|
||||
|
||||
try:
|
||||
ingress_object.delete()
|
||||
except Exception as exception:
|
||||
return JsonResponse({"status": "error","reason":str(exception)})
|
||||
|
||||
return JsonResponse({"status": "deleted","url":str(url),"namespace":str(namespace)})
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
@@ -1,46 +0,0 @@
|
||||
from django.apps import AppConfig
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import render
|
||||
import requests
|
||||
from proxmoxer import ProxmoxAPI
|
||||
import docker
|
||||
|
||||
class BackofficeConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'backoffice'
|
||||
|
||||
def hello(request):
|
||||
return HttpResponse('<h1>Start bookstack!</h1>')
|
||||
|
||||
def http_call_test(request):
|
||||
url = 'http://portainer.zeus.geeraert.eu/api/auth/'
|
||||
myobj = {'Username': 'admin','Password':'Xtm78*CX3mJ54g'}
|
||||
|
||||
x = requests.post(url, json = myobj)
|
||||
|
||||
print(x.text)
|
||||
return HttpResponse(x.text)
|
||||
|
||||
def proxmox(request):
|
||||
proxmox = ProxmoxAPI("proxmox.zeus.geeraert.eu", user="root@pam", password="dinner_sl@v3", verify_ssl=False)
|
||||
return HttpResponse(proxmox)
|
||||
|
||||
def docker_call(request,action,id_docker):
|
||||
print(action)
|
||||
print(id_docker)
|
||||
client = docker.from_env()
|
||||
if action == "start":
|
||||
print("nous allons start")
|
||||
client.containers.get(id_docker).start()
|
||||
if action == "stop":
|
||||
print("nous allons stop")
|
||||
client.containers.get(id_docker).stop()
|
||||
|
||||
return HttpResponse(client.containers.get(id_docker).status)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
@@ -1,3 +0,0 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
@@ -1,8 +0,0 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import render
|
||||
|
||||
def hello(request):
|
||||
return HttpResponse('<h1>Hello Django!</h1>')
|
||||
@@ -0,0 +1,6 @@
|
||||
from rest_framework.decorators import api_view, authentication_classes, permission_classes
|
||||
from rest_framework.authentication import TokenAuthentication
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
from django.contrib import admin
|
||||
from import_export.admin import ImportExportModelAdmin
|
||||
from import_export import resources
|
||||
from import_export.fields import Field
|
||||
from .models import JobData
|
||||
from django.utils.text import Truncator
|
||||
from core.admin import UniversalModelAdmin
|
||||
|
||||
# Register your models here.
|
||||
|
||||
@@ -31,7 +31,7 @@ class JobResource(resources.ModelResource):
|
||||
|
||||
|
||||
@admin.register(JobData)
|
||||
class JobAdmin(ImportExportModelAdmin):
|
||||
class JobAdmin(UniversalModelAdmin):
|
||||
list_display = ('job_position','company','URL','status','date_saved','date_applied','type','resume','location','short_description','salary','contact','source')
|
||||
#fields = ['job_position','company','URL','status','date_saved','date_applied','type','resume','cover_letter','location','job_description','salary ','contact','source']
|
||||
resource_classes = [JobResource]
|
||||
|
||||
@@ -62,7 +62,7 @@ def nodes(request):
|
||||
'spec': {
|
||||
|
||||
'containers': [{
|
||||
'image': 'gitea.tryton.geeraert.eu/pi-ux-ce/bitwarden_cli:1.0.1',
|
||||
'image': 'gitea.geeraert.eu/pi-ux-ce/bitwarden_cli:1.0.1',
|
||||
# 'pod-running-timeout': '5m0s',
|
||||
'name': 'testpython',
|
||||
'env': [
|
||||
@@ -96,7 +96,7 @@ def backup_job(request):
|
||||
'spec': {
|
||||
|
||||
'containers': [{
|
||||
'image': 'gitea.tryton.geeraert.eu/pi-ux-ce/bitwarden_cli:1.0.1',
|
||||
'image': 'gitea.geeraert.eu/pi-ux-ce/bitwarden_cli:1.0.1',
|
||||
'name': 'testpython',
|
||||
'command': ['/bin/sh -c /config/export_bitwarden.sh'],
|
||||
'env': [
|
||||
@@ -124,8 +124,8 @@ def backup_job_yaml(request,sync_target):
|
||||
v1 = client.BatchV1Api()
|
||||
|
||||
yaml_location = {
|
||||
"synology" : "https://gitea.tryton.geeraert.eu/pi-ux-ce/Backup_kube/raw/branch/main/Infrequent_access/synology_pod.yaml",
|
||||
"openmediavault":"https://gitea.tryton.geeraert.eu/pi-ux-ce/Backup_kube/raw/branch/main/Infrequent_access/openmediavault_pod.yaml"
|
||||
"synology" : "https://gitea.geeraert.eu/pi-ux-ce/Backup_kube/raw/branch/main/Infrequent_access/synology_pod.yaml",
|
||||
"openmediavault":"https://gitea.geeraert.eu/pi-ux-ce/Backup_kube/raw/branch/main/Infrequent_access/openmediavault_pod.yaml"
|
||||
}
|
||||
print(yaml_location[sync_target])
|
||||
url_to_select=yaml_location[sync_target]
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
from django.contrib import admin
|
||||
from import_export.admin import ImportExportModelAdmin
|
||||
from import_export import resources
|
||||
from django.utils.html import format_html
|
||||
from .models import podcastData
|
||||
from core.admin import UniversalModelAdmin
|
||||
|
||||
# Register your models here.
|
||||
@admin.register(podcastData)
|
||||
class JobAdmin(ImportExportModelAdmin):
|
||||
class PodcastAdmin(UniversalModelAdmin):
|
||||
list_display = ('podcast_name','clickable_links','enabled')
|
||||
|
||||
def clickable_links(self, obj):
|
||||
return format_html('<a href="{}">{}</a>', obj.podcast_url,obj.podcast_url)
|
||||
|
||||
link_field = 'podcast_url'
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
from django.contrib import admin,messages
|
||||
from django.utils.translation import ngettext
|
||||
from django.utils.html import format_html
|
||||
from django.utils import timezone
|
||||
from djangoql.admin import DjangoQLSearchMixin
|
||||
from prompt_toolkit.shortcuts import print_container
|
||||
from import_export.admin import ImportExportModelAdmin
|
||||
from import_export import resources
|
||||
from .models import SimpsonsData,simpsons_data_object,urlData
|
||||
from .models import SimpsonsData,urlData
|
||||
from .utils import mark_episode_watched,unwatch_all_episodes,generate_new_urls_for_episode
|
||||
from core.admin import UniversalModelAdmin
|
||||
|
||||
# Register your models here.
|
||||
|
||||
@@ -65,19 +63,15 @@ def generate_new_urls(modeladmin, request, queryset):
|
||||
|
||||
|
||||
@admin.register(SimpsonsData)
|
||||
class EpisodeAdmin(DjangoQLSearchMixin,ImportExportModelAdmin):
|
||||
class EpisodeAdmin(UniversalModelAdmin):
|
||||
list_display = [field.name for field in SimpsonsData._meta.fields if field.name != 'id']
|
||||
list_display += ['clickable_links']
|
||||
list_filter = ['seen','modified_at']
|
||||
#list_filter = ['seen']
|
||||
fields = ['season', 'episode', 'url', 'seen']
|
||||
actions = [make_seen,make_unseen,unseen_betaserie,generate_new_urls]
|
||||
search_fields = ['season', 'episode', 'url', 'seen']
|
||||
djangoql_completion_enabled_by_default = False
|
||||
|
||||
def clickable_links(self, obj):
|
||||
return format_html('<a href="{}">{}</a>', obj.url,obj.url)
|
||||
|
||||
|
||||
def get_queryset(self, request):
|
||||
return super().get_queryset(request).using(DB)
|
||||
|
||||
@@ -91,7 +85,7 @@ class EpisodeAdmin(DjangoQLSearchMixin,ImportExportModelAdmin):
|
||||
queryset.using(DB).delete()
|
||||
|
||||
@admin.register(urlData)
|
||||
class urldataAdmin(ImportExportModelAdmin):
|
||||
class urldataAdmin(UniversalModelAdmin):
|
||||
list_display = ('url_example', 'prefix', 'infix', 'suffix','addedDate')
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
# Generated by Django 4.2.30 on 2026-09-17 21:26
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('simpsons', '0008_alter_simpsonsdata_modified_at_alter_urldata_infix_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='simpsonsdata',
|
||||
name='modified_at',
|
||||
field=models.DateTimeField(default=datetime.datetime(1969, 12, 31, 23, 0, tzinfo=datetime.timezone.utc)),
|
||||
),
|
||||
]
|
||||
@@ -1,12 +1,26 @@
|
||||
from django.contrib import admin
|
||||
from django.utils.html import format_html
|
||||
from import_export.admin import ImportExportModelAdmin
|
||||
from .models import StreamingSiteTestingData,StreamingRedirectData
|
||||
from .utils import full_testing
|
||||
from apps.website_redirection.utils import redirect_method
|
||||
from urllib.parse import urlsplit, urlunsplit
|
||||
from core.admin import UniversalModelAdmin
|
||||
|
||||
|
||||
@admin.action(description="Add this show to streaming")
|
||||
def re_redirect(modeladmin, request, queryset):
|
||||
output_generated = ""
|
||||
for query in queryset.values():
|
||||
print(query)
|
||||
key = "streaming"
|
||||
value = query.get('url_display')
|
||||
output_generated = output_generated + redirect_method(key,value)+";"
|
||||
|
||||
modeladmin.message_user(
|
||||
request,
|
||||
output_generated
|
||||
)
|
||||
|
||||
@admin.action(description="check the URLs")
|
||||
def check(modeladmin, request, queryset):
|
||||
for query in queryset:
|
||||
@@ -34,14 +48,11 @@ def urlcleaning(modeladmin, request, queryset):
|
||||
|
||||
return 0
|
||||
@admin.register(StreamingSiteTestingData)
|
||||
class streamingAdmin(ImportExportModelAdmin):
|
||||
class streamingAdmin(UniversalModelAdmin):
|
||||
list_display = ['clickable_links','result_colored','newstatus']
|
||||
fields = ['url']
|
||||
actions = [check,urlcleaning]
|
||||
|
||||
def clickable_links(self, obj):
|
||||
return format_html('<a href="{}">{}</a>', obj.url,obj.url)
|
||||
|
||||
def result_colored(self, obj):
|
||||
colors = {
|
||||
'REACHABLE': 'green',
|
||||
@@ -60,9 +71,12 @@ class streamingAdmin(ImportExportModelAdmin):
|
||||
#return obj.status
|
||||
|
||||
|
||||
|
||||
@admin.register(StreamingRedirectData)
|
||||
class StreamingRedirectAdmin(ImportExportModelAdmin):
|
||||
list_display = ['name','season','episode','randomViewing','clickable_links','addedDate','alias']
|
||||
class StreamingRedirectAdmin(UniversalModelAdmin):
|
||||
list_display = ['name','image_tag','season','episode','randomViewing','clickable_links','addedDate','alias']
|
||||
actions = [re_redirect]
|
||||
|
||||
#fields = ['name','season','episode','url_example','prefix','infix','suffix','alias','randomViewing','seasonInformation']
|
||||
fieldsets = (
|
||||
(
|
||||
@@ -77,8 +91,10 @@ class StreamingRedirectAdmin(ImportExportModelAdmin):
|
||||
(
|
||||
'Information', {
|
||||
"classes": ["collapse"],
|
||||
'fields': ('seasonInformation','alias','betaserieShowId','maximumNumberSeason')
|
||||
'fields': ('seasonInformation','alias','betaserieShowId','maximumNumberSeason','poster_url')
|
||||
}),
|
||||
)
|
||||
def clickable_links(self, obj):
|
||||
return format_html('<a href="{}">{}</a>', obj.url_display,obj.url_display)
|
||||
link_field = 'url_display'
|
||||
|
||||
def image_tag(self,obj):
|
||||
return format_html('<img src="{0}" style="width: 355px; height:200px;" />'.format(obj.poster_url))
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 4.2.30 on 2026-09-17 21:26
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('streaming', '0014_remove_streamingredirectdata_url_example_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='streamingredirectdata',
|
||||
name='poster_url',
|
||||
field=models.CharField(blank=True, help_text='poster URL', max_length=1000, null=True),
|
||||
),
|
||||
]
|
||||
@@ -21,7 +21,7 @@ class StreamingRedirectData(models.Model):
|
||||
name = models.CharField(primary_key=True,max_length=1000, help_text="Name of the show")
|
||||
season = models.IntegerField(null=False,default=1)
|
||||
episode = models.IntegerField(null=False,default=0)
|
||||
url_display = models.CharField(max_length=1000, help_text="https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=18&episode=5",blank=True, null=True)
|
||||
url_display = models.CharField(max_length=1000, help_text="https://streaming.geeraert.eu/office",blank=True, null=True)
|
||||
prefix = models.CharField(max_length=1000, help_text="https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=",blank=True, null=True)
|
||||
infix = models.CharField(max_length=1000, help_text="&episode=",blank=True, null=True)
|
||||
suffix = models.CharField(max_length=1000, help_text="" ,blank=True, null=True)
|
||||
@@ -31,28 +31,27 @@ class StreamingRedirectData(models.Model):
|
||||
betaserieShowId = models.IntegerField(null=True,blank=True)
|
||||
maximumNumberSeason = models.IntegerField(null=True,blank=True)
|
||||
randomViewing = models.BooleanField(default=False)
|
||||
poster_url = models.CharField(max_length=1000, help_text="poster URL",blank=True, null=True)
|
||||
|
||||
def sanitize(self, name):
|
||||
return name.replace(" ", "")
|
||||
return name.replace(" ", "").lower()
|
||||
|
||||
def season_information(self, serie_name):
|
||||
betaserie = betaserieUtils()
|
||||
print(serie_name)
|
||||
print(betaserie.identify_serie(serie_name,True))
|
||||
return betaserie.series_information(betaserie.identify_serie(serie_name))[0]
|
||||
|
||||
def maximum_Number_Season(self, serie_name):
|
||||
betaserie = betaserieUtils()
|
||||
print(serie_name)
|
||||
print(betaserie.identify_serie(serie_name))
|
||||
return betaserie.series_information(betaserie.identify_serie(serie_name))[1]
|
||||
|
||||
def betaserie_show_id(self,serie_name):
|
||||
betaserie = betaserieUtils()
|
||||
print(serie_name)
|
||||
print(betaserie.identify_serie(serie_name))
|
||||
return betaserie.identify_serie(serie_name)
|
||||
|
||||
def betaserie_poster_url(self,serie_name):
|
||||
betaserie = betaserieUtils()
|
||||
return betaserie.poster_serie(serie_name)
|
||||
|
||||
def url_display_set(self,alias):
|
||||
if ENVIRONMENT == "PRODUCTION":
|
||||
url = "https://streaming.geeraert.eu/"
|
||||
@@ -73,6 +72,8 @@ class StreamingRedirectData(models.Model):
|
||||
self.maximumNumberSeason = self.maximum_Number_Season(self.name)
|
||||
if not self.url_display:
|
||||
self.url_display = self.url_display_set(self.alias)
|
||||
if not self.poster_url:
|
||||
self.poster_url = self.betaserie_poster_url(self.name)
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
class Meta:
|
||||
|
||||
@@ -15,6 +15,9 @@ def hello(request):
|
||||
|
||||
|
||||
def streamingRedirect(request,alias):
|
||||
#sanitize
|
||||
alias = alias.lower()
|
||||
|
||||
streaming_object = StreamingRedirectData.objects.filter(alias=alias)
|
||||
|
||||
episode = streaming_object.values('episode')[0]['episode']
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from django.contrib import admin
|
||||
from import_export.admin import ImportExportModelAdmin
|
||||
from .models import TelegramData
|
||||
from .utils import telegramUtils
|
||||
from .utils import telegramUtils
|
||||
from core.admin import UniversalModelAdmin
|
||||
|
||||
@admin.action(description="Clear all expired messages")
|
||||
def messages_cleaning(modeladmin, request, queryset):
|
||||
@@ -10,7 +10,7 @@ def messages_cleaning(modeladmin, request, queryset):
|
||||
|
||||
# Register your models here.
|
||||
@admin.register(TelegramData)
|
||||
class JobAdmin(ImportExportModelAdmin):
|
||||
class JobAdmin(UniversalModelAdmin):
|
||||
list_display = ('message_id','chat_id','description','creation_date','expiration_date')
|
||||
actions = [messages_cleaning]
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
from django.contrib import admin
|
||||
from .models import historicalData,redirectData
|
||||
from .utils import redirect_method
|
||||
from import_export.admin import ImportExportModelAdmin
|
||||
from django.utils.html import format_html
|
||||
|
||||
from core.admin import UniversalModelAdmin
|
||||
|
||||
# Register your models here.
|
||||
|
||||
@@ -21,16 +19,13 @@ def re_redirect(modeladmin, request, queryset):
|
||||
output_generated
|
||||
)
|
||||
@admin.register(historicalData)
|
||||
class historicalAdmin(ImportExportModelAdmin):
|
||||
class historicalAdmin(UniversalModelAdmin):
|
||||
list_input = (field.name for field in historicalData._meta.fields if field.name != 'id' or field.name != 'url')
|
||||
list_display = ["clickable_links"]
|
||||
list_display.extend(list_input)
|
||||
actions = [re_redirect]
|
||||
|
||||
|
||||
def clickable_links(self, obj):
|
||||
return format_html('<a href="{}">{}</a>', obj.url,obj.url)
|
||||
|
||||
@admin.register(redirectData)
|
||||
class redirectAdmin(ImportExportModelAdmin):
|
||||
class redirectAdmin(UniversalModelAdmin):
|
||||
list_display = [field.name for field in redirectData._meta.fields if field.name != 'id']
|
||||
list_display += ['clickable_links']
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import redis
|
||||
#import redis
|
||||
from django.http import HttpResponse
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import render
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from django.db import models
|
||||
from django.contrib import admin
|
||||
from django.utils.html import format_html
|
||||
|
||||
class historicalData(models.Model):
|
||||
url = models.CharField(max_length=1000)
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
from import_export.admin import ImportExportModelAdmin
|
||||
from admin_extra_buttons.api import ExtraButtonsMixin
|
||||
from django.contrib import admin
|
||||
from djangoql.admin import DjangoQLSearchMixin
|
||||
from django.utils.html import format_html
|
||||
|
||||
class UniversalModelAdmin(DjangoQLSearchMixin,ImportExportModelAdmin,ExtraButtonsMixin,admin.ModelAdmin):
|
||||
djangoql_completion_enabled_by_default = True
|
||||
|
||||
#Add search fields if you want to have the toggle on/off
|
||||
# example:
|
||||
# search_fields = ['season', 'episode', 'url', 'seen']
|
||||
|
||||
link_field = 'url'
|
||||
|
||||
|
||||
def clickable_links(self, obj):
|
||||
url = getattr(obj, self.link_field, None)
|
||||
return format_html('<a href="{}">{}</a>', url,url)
|
||||
|
||||
@@ -53,6 +53,10 @@ INSTALLED_APPS = [
|
||||
'apps.streaming.apps.StreamingConfig',
|
||||
'import_export',
|
||||
'djangoql',
|
||||
'admin_extra_buttons',
|
||||
'rest_framework',
|
||||
'rest_framework.authtoken',
|
||||
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
@@ -198,7 +202,7 @@ AUTH_PASSWORD_VALIDATORS = [
|
||||
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
TIME_ZONE = 'UTC'
|
||||
TIME_ZONE = 'Europe/London'
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
@@ -251,3 +255,4 @@ PROXIES = {
|
||||
"http" : PROXY_URL,
|
||||
"https" : PROXY_URL
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
@@ -1,7 +1,7 @@
|
||||
FROM python:3.12
|
||||
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
#ENV ALLOWED_HOSTS 'django.tryton.geeraert.eu'
|
||||
#ENV ALLOWED_HOSTS 'django.geeraert.eu'
|
||||
#ENV DEBUG 'True'
|
||||
|
||||
ARG ALLOWED_HOSTS
|
||||
|
||||
@@ -4,7 +4,7 @@ FROM python:3.12
|
||||
MAINTAINER pi-ux-ce
|
||||
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
ENV ALLOWED_HOSTS 'django-testing.tryton.geeraert.eu'
|
||||
ENV ALLOWED_HOSTS 'django-testing.geeraert.eu'
|
||||
ENV DEBUG 'True'
|
||||
|
||||
WORKDIR /code/
|
||||
@@ -20,7 +20,7 @@ RUN apt-get update && \
|
||||
# image silently keeps stale code.
|
||||
ARG CACHE_BUST=1
|
||||
RUN echo "cache bust: ${CACHE_BUST}" && \
|
||||
git clone --depth 1 -b testing https://gitea.tryton.geeraert.eu/pi-ux-ce/Django_kube.git .
|
||||
git clone --depth 1 -b testing https://gitea.geeraert.eu/pi-ux-ce/Django_kube.git .
|
||||
|
||||
RUN pip install --cache-dir=/opt/hostedtoolcache/pip --upgrade pip
|
||||
RUN pip list --cache-dir=/opt/hostedtoolcache/pip --outdated
|
||||
|
||||
+2
-1
@@ -1,6 +1,5 @@
|
||||
django
|
||||
psycopg2
|
||||
#xrequests
|
||||
kubernetes
|
||||
ruamel.yaml
|
||||
pyyaml
|
||||
@@ -17,3 +16,5 @@ bitwarden_sdk
|
||||
xmltodict
|
||||
whitenoise
|
||||
djangoql
|
||||
django-admin-extra-buttons
|
||||
djangorestframework
|
||||
|
||||
Reference in New Issue
Block a user