branch 1st

This commit is contained in:
IGNY8 VPS (Salman)
2025-11-16 20:08:58 +00:00
parent 219dae83c6
commit 8a9dd44c50

View File

@@ -309,26 +309,17 @@ class ModuleEnableSettingsViewSet(AccountModelViewSet):
def get_queryset(self):
"""Get module enable settings for current account"""
# Return queryset filtered by account - but list() will handle get_or_create
queryset = super().get_queryset()
# Filter by account if available
account = getattr(self.request, 'account', None)
if not account:
user = getattr(self.request, 'user', None)
if user:
account = getattr(user, 'account', None)
if account:
queryset = queryset.filter(account=account)
return queryset
# Don't filter here - list() and retrieve() handle get_or_create
# This prevents empty queryset from causing 404 errors
return ModuleEnableSettings.objects.all()
def list(self, request, *args, **kwargs):
"""Get or create module enable settings for current account"""
try:
account = getattr(request, 'account', None)
if not account:
user = getattr(request, 'user', None)
if user and hasattr(user, 'account'):
account = user.account
account = getattr(user, 'account', None)
if not account:
return error_response(
@@ -338,22 +329,9 @@ class ModuleEnableSettingsViewSet(AccountModelViewSet):
)
# Get or create settings for account (one per account)
try:
settings = ModuleEnableSettings.objects.get(account=account)
except ModuleEnableSettings.DoesNotExist:
# Create default settings for account
settings = ModuleEnableSettings.objects.create(account=account)
settings, created = ModuleEnableSettings.objects.get_or_create(account=account)
serializer = self.get_serializer(settings)
return success_response(data=serializer.data, request=request)
except Exception as e:
import traceback
error_trace = traceback.format_exc()
return error_response(
error=f'Failed to load module enable settings: {str(e)}',
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
request=request
)
def retrieve(self, request, pk=None, *args, **kwargs):
"""Get module enable settings for current account"""