X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=htsworkflow.git;a=blobdiff_plain;f=htsworkflow%2Ffrontend%2Fbcmagic%2Fviews.py;h=f9fb7933cdecbe70230cc57f04d50c2ec7569e4f;hp=9d145b6092b82489798271d70e515b05dd334e7c;hb=5f645ab6ae26b456f5b11b9e764da7e9c5367f1d;hpb=753584c653403e158bf3b830ef1f1489adb61148 diff --git a/htsworkflow/frontend/bcmagic/views.py b/htsworkflow/frontend/bcmagic/views.py index 9d145b6..f9fb793 100644 --- a/htsworkflow/frontend/bcmagic/views.py +++ b/htsworkflow/frontend/bcmagic/views.py @@ -6,6 +6,7 @@ from django.core.exceptions import ObjectDoesNotExist from htsworkflow.frontend.bcmagic import models from htsworkflow.frontend.bcmagic.utils import report_error, redirect_to_url from htsworkflow.frontend.bcmagic.plugin import bcm_plugin_processor +from htsworkflow.frontend.bcmagic import plugin #from htsworkflow.util.jsonutil import encode_json try: @@ -27,6 +28,31 @@ def index(request): context_instance=RequestContext(request)) +def __plugin_search(text): + """ + Runs registered plugins to search for results + """ + + hits = [] + for label, search_func in plugin._SEARCH_FUNCTIONS.items(): + result = search_func(text) + if result is not None: + hits.extend(result) + + n = len(hits) + if n == 0: + msg = 'No hits found for: %s' % (text) + return report_error(msg) + elif n == 1: + return redirect_to_url(hits[0][1]) + else: + msg = "%d hits found for (%s); multi-hit not implemented yet." % (n, text) + return report_error(msg) + + + #return json.dumps(hits) + + def __magic_process(text): """ Based on scanned text, check to see if there is map object to use @@ -37,7 +63,8 @@ def __magic_process(text): # There should always be at least one | in a valid scan. if len(split_text) <= 1: - return report_error('Invalid text: %s' % (text)) + #return report_error('Invalid text: %s' % (text)) + return __plugin_search(text) # Keyword is the first element in the list keyword = split_text[0]