CORD-880: Get Diag objects working
Change-Id: I27b92c0e6875258d7a14a635fbe53c542d3f899f
diff --git a/xos/synchronizers/new_base/diag.py b/xos/synchronizers/new_base/diag.py
index 86874d6..b4868ac 100644
--- a/xos/synchronizers/new_base/diag.py
+++ b/xos/synchronizers/new_base/diag.py
@@ -4,19 +4,18 @@
import traceback
import json
-from core.models import Diag
from xos.config import Config, XOS_DIR
from xos.logger import Logger, logging, logger
logger = Logger(level=logging.INFO)
-def update_diag(loop_end=None, loop_start=None, syncrecord_start=None, sync_start=None, backend_status=None):
+def update_diag(diag_class, loop_end=None, loop_start=None, syncrecord_start=None, sync_start=None, backend_status=None):
observer_name = Config().observer_name
try:
- diag = Diag.objects.filter(name=observer_name).first()
+ diag = diag_class.objects.filter(name=observer_name).first()
if (not diag):
- diag = Diag(name=observer_name)
+ diag = diag_class(name=observer_name)
br_str = diag.backend_register
br = json.loads(br_str)
if loop_end:
diff --git a/xos/synchronizers/new_base/djangoaccessor.py b/xos/synchronizers/new_base/djangoaccessor.py
index 01d5884..66ded70 100644
--- a/xos/synchronizers/new_base/djangoaccessor.py
+++ b/xos/synchronizers/new_base/djangoaccessor.py
@@ -4,7 +4,6 @@
from django.db import reset_queries
from django.utils import timezone
from modelaccessor import ModelAccessor
-from diag import update_diag
from django.db import connection
from django.db.models import F, Q
from django import setup as django_setup # django 1.7
@@ -71,9 +70,6 @@
def now(self):
return timezone.now()
- def update_diag(self, loop_end=None, loop_start=None, syncrecord_start=None, sync_start=None, backend_status=None):
- return update_diag(loop_end, loop_start, syncrecord_start, sync_start, backend_status)
-
def is_type(self, obj, name):
return type(obj) == self.get_model_class(name)
diff --git a/xos/synchronizers/new_base/modelaccessor.py b/xos/synchronizers/new_base/modelaccessor.py
index bc1d74f..62475bc 100644
--- a/xos/synchronizers/new_base/modelaccessor.py
+++ b/xos/synchronizers/new_base/modelaccessor.py
@@ -11,6 +11,7 @@
import functools
import os
from xos.config import Config
+from diag import update_diag
class ModelAccessor(object):
def __init__(self):
@@ -24,6 +25,10 @@
""" Given a class name, return that model class """
return self.all_model_classes[name]
+ def has_model_class(self, name):
+ """ Given a class name, return that model class """
+ return name in self.all_model_classes
+
def fetch_pending(self, name, deletion=False):
""" Execute the default fetch_pending query """
raise Exception("Not Implemented")
@@ -57,8 +62,8 @@
raise Exception("Not Implemented")
def update_diag(self, loop_end=None, loop_start=None, syncrecord_start=None, sync_start=None, backend_status=None):
- """ Update the diagnostic object """
- pass
+ if self.has_model_class("Diag"):
+ return update_diag(self.get_model_class("Diag"), loop_end, loop_start, syncrecord_start, sync_start, backend_status)
def is_type(self, obj, name):
""" returns True is obj is of model type "name" """
diff --git a/xos/xos_client/xosapi/orm.py b/xos/xos_client/xosapi/orm.py
index 37f706d..69d37b0 100644
--- a/xos/xos_client/xosapi/orm.py
+++ b/xos/xos_client/xosapi/orm.py
@@ -169,6 +169,14 @@
return d
+class ORMQuerySet(list):
+ """ Makes lists look like django querysets """
+ def first(self):
+ if len(self)>0:
+ return self[0]
+ else:
+ return None
+
class ORMLocalObjectManager(object):
""" Manages a local list of objects """
@@ -213,7 +221,7 @@
result=[]
for item in obj.items:
result.append(make_ORMWrapper(item, self._stub))
- return result
+ return ORMQuerySet(result)
def all(self):
return self.wrap_list(self._stub.invoke("List%s" % self._modelName, Empty()))