some bug fixes to install.py

This commit is contained in:
usmannasir
2025-09-21 01:07:38 +05:00
parent f943e5c961
commit 570a4953d0
3 changed files with 16 additions and 12 deletions

View File

@@ -2,7 +2,7 @@
from django.db import models
from django.contrib.auth.models import User
from loginSystem.models import Administrator
# Create your models here.
@@ -16,15 +16,15 @@ class CyberPanelCosmetic(models.Model):
class UserNotificationPreferences(models.Model):
"""Model to store user notification dismissal preferences"""
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='notification_preferences')
user = models.OneToOneField(Administrator, on_delete=models.CASCADE, related_name='notification_preferences')
backup_notification_dismissed = models.BooleanField(default=False, help_text="Whether user has dismissed the backup notification")
ai_scanner_notification_dismissed = models.BooleanField(default=False, help_text="Whether user has dismissed the AI scanner notification")
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
verbose_name = "User Notification Preferences"
verbose_name_plural = "User Notification Preferences"
def __str__(self):
return f"Notification Preferences for {self.user.username}"
return f"Notification Preferences for {self.user.userName}"

View File

@@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.contrib.auth.models import User
from loginSystem.models import Administrator
from .models import UserNotificationPreferences
@receiver(post_save, sender=User)
@receiver(post_save, sender=Administrator)
def create_user_notification_preferences(sender, instance, created, **kwargs):
"""Create default notification preferences when a new user is created"""
"""Create default notification preferences when a new Administrator is created"""
if created:
UserNotificationPreferences.objects.create(
user=instance,
@@ -16,8 +16,8 @@ def create_user_notification_preferences(sender, instance, created, **kwargs):
)
@receiver(post_save, sender=User)
@receiver(post_save, sender=Administrator)
def save_user_notification_preferences(sender, instance, **kwargs):
"""Save notification preferences when user is saved"""
"""Save notification preferences when Administrator is saved"""
if hasattr(instance, 'notification_preferences'):
instance.notification_preferences.save()

View File

@@ -695,12 +695,16 @@ password="%s"
logging.InstallLog.writeToFile("Running Django migrations...")
preFlightsChecks.stdOut("Running Django migrations...")
# Reset migration history in database (in case of re-installation)
command = "/usr/local/CyberPanel-venv/bin/python manage.py migrate --fake-initial"
preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR)
# Create fresh migrations for all apps
command = "/usr/local/CyberPanel-venv/bin/python manage.py makemigrations"
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
# Apply all migrations
command = "/usr/local/CyberPanel-venv/bin/python manage.py migrate"
# Apply all migrations with --fake-initial to handle existing tables
command = "/usr/local/CyberPanel-venv/bin/python manage.py migrate --fake-initial"
preFlightsChecks.call(command, self.distro, command, command, 1, 1, os.EX_OSERR)
logging.InstallLog.writeToFile("Django migrations completed successfully!")