Prototype of bcmagic search plugin.
[htsworkflow.git] / htsworkflow / frontend / inventory / views.py
index 5dd3655aa583edc5d8985bbce2acdf2f20e372dc..027c4aaa4cbdade50a7e9b465e498757ee661d27 100644 (file)
@@ -1,9 +1,11 @@
 from htsworkflow.frontend.inventory.models import Item, LongTermStorage
+from htsworkflow.frontend.inventory.bcmagic import item_search
+from htsworkflow.frontend.bcmagic.plugin import register_search_plugin
 from htsworkflow.frontend.experiments.models import FlowCell
 from htsworkflow.frontend.bcmagic.forms import BarcodeMagicForm
 from htsworkflow.frontend.bcprinter.util import print_zpl_socket
 from htsworkflow.frontend import settings
-from htsworkflow.util.jsonutil import encode_json
+#from htsworkflow.util.jsonutil import encode_json
 
 from django.core.exceptions import ObjectDoesNotExist
 from django.http import HttpResponse, HttpResponseRedirect
@@ -12,7 +14,12 @@ from django.template import RequestContext
 from django.template.loader import get_template
 from django.contrib.auth.decorators import login_required
 
+register_search_plugin('Inventory Item', item_search)
 
+try:
+    import json
+except ImportError, e:
+    import simplejson as json
 
 INVENTORY_CONTEXT_DEFAULTS = {
     'app_name': 'Inventory Tracker',
@@ -71,7 +78,7 @@ def data_items(request):
     
     d['rows'] = rows
     
-    return HttpResponse(encode_json(d), content_type="application/javascript")
+    return HttpResponse(json.dumps(d), content_type="application/javascript")
 
 @login_required
 def index(request):
@@ -87,15 +94,31 @@ def index(request):
                               context_dict,
                               context_instance=RequestContext(request))
     
+
 @login_required
-def item_summary(request, uuid, msg=''):
+def item_summary_by_barcode(request, barcode_id, msg=''):
     """
-    Display a summary for an item
+    Display a summary for an item by barcode
     """
     try:
-        item = Item.objects.get(uuid=uuid)
+        item = Item.objects.get(barcode_id=barcode_id)
     except ObjectDoesNotExist, e:
         item = None
+        
+    return item_summary_by_uuid(request, None, msg, item)
+    
+
+@login_required
+def item_summary_by_uuid(request, uuid, msg='', item=None):
+    """
+    Display a summary for an item
+    """
+    # Use item instead of looking it up if it is passed.
+    if item is None:
+        try:
+            item = Item.objects.get(uuid=uuid)
+        except ObjectDoesNotExist, e:
+            item = None
     
     context_dict = {
         'page_name': 'Item Summary',
@@ -146,7 +169,7 @@ def item_print(request, uuid):
     if item is not None:
         msg = _item_print(item, request)
     
-    return item_summary(request, uuid, msg)
+    return item_summary_by_uuid(request, uuid, msg)
 
 
 def link_flowcell_and_device(request, flowcell, serial):