diff --git a/backend/sophon/core/admin.py b/backend/sophon/core/admin.py index f9f8eec..587920d 100644 --- a/backend/sophon/core/admin.py +++ b/backend/sophon/core/admin.py @@ -1,4 +1,4 @@ -from django.contrib import admin +from django.contrib import admin, messages from . import models @@ -25,11 +25,26 @@ class ProjectAdmin(CoreAdmin): ) -@admin.action(description="Syncronize DataFlows (slow, be patient!)") +@admin.action(description="Sync DataFlows") def sync_flows_admin(modeladmin, request, queryset): for datasource in queryset: datasource: models.DataSource - datasource.sync_flows() + try: + datasource.sync_flows() + except NotImplementedError: + modeladmin.message_user( + request, + f"Skipped {datasource}: Syncing DataFlows is not supported on this DataSource.", + level=messages.ERROR + ) + except Exception as exc: + modeladmin.message_user( + request, + f"Skipped {datasource}: {exc}", + level=messages.ERROR + ) + else: + modeladmin.log_change(request, datasource, "Sync DataFlows") @admin.register(models.DataSource) diff --git a/backend/sophon/core/views.py b/backend/sophon/core/views.py index fa0b868..1a27f50 100644 --- a/backend/sophon/core/views.py +++ b/backend/sophon/core/views.py @@ -68,7 +68,18 @@ class DataSourceViewSet(viewsets.ModelViewSet): log.debug(f"Getting DataSource from the database...") db_datasource: models.DataSource = self.get_object() - db_datasource.sync_flows() + try: + db_datasource.sync_flows() + except NotImplementedError: + return response.Response({ + "success": False, + "error": "Syncing DataFlows is not supported on this DataSource." + }) + except Exception as exc: + return response.Response({ + "success": False, + "error": f"{exc}" + }) return response.Response({ "success": True,