Revert "branch 1st"

This reverts commit 8a9dd44c50.
This commit is contained in:
Desktop
2025-11-17 01:35:13 +05:00
parent 8a9dd44c50
commit ab292de06c

View File

@@ -309,29 +309,51 @@ class ModuleEnableSettingsViewSet(AccountModelViewSet):
def get_queryset(self):
"""Get module enable settings for current account"""
# Don't filter here - list() and retrieve() handle get_or_create
# This prevents empty queryset from causing 404 errors
return ModuleEnableSettings.objects.all()
# 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
def list(self, request, *args, **kwargs):
"""Get or create module enable settings for current account"""
account = getattr(request, 'account', None)
if not account:
user = getattr(request, 'user', None)
if user and hasattr(user, 'account'):
account = getattr(user, 'account', None)
if not account:
try:
account = getattr(request, 'account', None)
if not account:
user = getattr(request, 'user', None)
if user and hasattr(user, 'account'):
account = user.account
if not account:
return error_response(
error='Account not found',
status_code=status.HTTP_400_BAD_REQUEST,
request=request
)
# 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)
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='Account not found',
status_code=status.HTTP_400_BAD_REQUEST,
error=f'Failed to load module enable settings: {str(e)}',
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
request=request
)
# Get or create settings for account (one per account)
settings, created = ModuleEnableSettings.objects.get_or_create(account=account)
serializer = self.get_serializer(settings)
return success_response(data=serializer.data, request=request)
def retrieve(self, request, pk=None, *args, **kwargs):
"""Get module enable settings for current account"""