adding view functions for checking file/folder names for debug page
@@ -4,7 +4,7 @@ from django.http import HttpResponse
from django.template import loader
from hs_core.views.utils import authorize, ACTION_TO_AUTHORIZE
from hs_access_control.models import PrivilegeCodes
-from hs_core.tasks import resource_debug
+from hs_core.tasks import resource_debug, get_non_preferred_paths
from django.shortcuts import redirect
from celery.result import AsyncResult
@@ -13,9 +13,6 @@ def debug_resource(request, shortkey):
""" Debug view for resource depicts output of various integrity checking scripts """
resource, _, _ = authorize(request, shortkey,
needed_permission=ACTION_TO_AUTHORIZE.VIEW_RESOURCE)
- non_preferred_paths = []
- if resource.resource_type == "CompositeResource":
- non_preferred_paths = resource.get_non_preferred_path_names()
template = loader.get_template('debug/debug_resource.html')
context = {
@@ -30,7 +27,6 @@ def debug_resource(request, shortkey):
'type_AVU': resource.getAVU('resourceType'),
'modified_AVU': resource.getAVU('bag_modified'),
'quota_AVU': resource.getAVU('quotaUserName'),
- 'non_preferred_paths': non_preferred_paths,
}
return HttpResponse(template.render(context, request))
@@ -45,7 +41,7 @@ def irods_issues(request, shortkey):
def check_task_status(request, task_id=None, *args, **kwargs):
- ''' Checks the task status of the resource_debug job specified by the task_id '''
+ """Checks the task status of the resource_debug job specified by the task_id """
if resource_debug.AsyncResult(task_id).ready():
status = "SUCCESS"
try:
@@ -62,3 +58,33 @@ def check_task_status(request, task_id=None, *args, **kwargs):
return HttpResponse(json.dumps({"status": None,
"state": AsyncResult(task_id).state}),
content_type="application/json")
+
+
+def check_for_non_preferred_paths(request, shortkey):
+ """Checks for non preferred file/folder paths in a given resource, runs async"""
+
+ resource, _, _ = authorize(request, shortkey,
+ needed_permission=ACTION_TO_AUTHORIZE.VIEW_RESOURCE)
+ task = get_non_preferred_paths.apply_async((resource.short_id,))
+ return redirect("get_path_check_task_status", task_id=task.task_id)
+
+
+def check_non_preferred_paths_task_status(request, task_id=None, *args, **kwargs):
+ """Checks the status of the task/job that checks for non preferred path specified by the task_id """
+
+ if get_non_preferred_paths.AsyncResult(task_id).ready():
+ status = "SUCCESS"
+ non_preferred_paths = []
+ try:
+ non_preferred_paths = AsyncResult(task_id).get()
+ except Exception as e:
+ status = "ERROR - {}".format(str(e))
+ context = {
+ "status": status,
+ "non_preferred_paths": non_preferred_paths,
+ }
+ return HttpResponse(json.dumps(context))
+ else:
+ return HttpResponse(json.dumps({"status": None,
+ "state": AsyncResult(task_id).state}),
+ content_type="application/json")
