예제 #1
0
    def dot_notation_set_value(self, notation, value):
        traverser = DotPathTraverser(notation)
        traverser.resolve_for_instance(self)

        try:
            traverser.set_value(value)
        except:
            print traverser.resolved_paths
            raise
예제 #2
0
 def evaluate_query_index(self, registered_index, query_index, doc_id, data):
     from dockit.backends.djangodocument.models import RegisteredIndexDocument
     
     schema = query_index.document
     
     #evaluate if document passes filters
     for inclusion in query_index.inclusions:
         dotpath = inclusion.dotpath()
         traverser = DotPathTraverser(dotpath)
         try:
             traverser.resolve_for_raw_data(data, schema=schema)
         except DotPathNotFound:
             return False
         except ObjectDoesNotExist:
             return False
         if traverser.current_value != inclusion.value:
             return False
     for exclusion in query_index.exclusions:
         dotpath = exclusion.dotpath()
         traverser = DotPathTraverser(dotpath)
         try:
             traverser.resolve_for_raw_data(data, schema=schema)
         except DotPathNotFound:
             pass
         except ObjectDoesNotExist:
             pass
         else:
             if traverser.current_value == exclusion.value:
                 return False
     
     #index params
     encoded_data = simplejson.dumps(data, cls=DjangoJSONEncoder)
     index_doc, created = RegisteredIndexDocument.objects.get_or_create(index=registered_index, doc_id=doc_id, defaults={'data':encoded_data})
     if not created:
         index_doc.data = encoded_data
         index_doc.save()
     for param in query_index.indexes:
         dotpath = param.dotpath()
         traverser = DotPathTraverser(dotpath)
         try:
             traverser.resolve_for_raw_data(data, schema=schema)
         except DotPathNotFound:
             value = None
             field = None
         except ObjectDoesNotExist:
             value = None
             field = None
         else:
             value = traverser.current_value
             field = traverser.current_field
         index_model = self.lookup_index(value=value, field=field)
         #now create a BaseIndex entry associated to a registered index document
         #if param.key == '@natural_key_hash':
         #    assert value
         #    assert False, str(value) +':'+ str(index_model)
         
         index_model.objects.db_index(index_doc, param.key, value)
예제 #3
0
 def get_field(self, schema, dotpath, obj=None):
     field = None
     if dotpath and obj:
         field = obj.dot_notation_to_field(dotpath)
         if field is None:
             parent_path = dotpath.rsplit('.', 1)[0]
             print 'no field', dotpath, obj
             
             from dockit.schema.common import DotPathTraverser
             traverser = DotPathTraverser(parent_path)
             traverser.resolve_for_instance(obj)
             info = traverser.resolved_paths
             subschema = info[2]['field'].schema
             fields = subschema._meta.fields
             
             field = obj.dot_notation_to_field(parent_path)
             data = obj._primitive_data
             assert field
     return field
예제 #4
0
    def _get_field(self, schema, dotpath):
        #helper function that returns the field belonging to the dotpath
        field = None
        if dotpath and self.parent:
            obj = self.parent.instance
            field = obj.dot_notation_to_field(dotpath)
            if field is None:
                parent_path = dotpath.rsplit('.', 1)[0]
                print 'no field', dotpath, obj

                from dockit.schema.common import DotPathTraverser
                traverser = DotPathTraverser(parent_path)
                traverser.resolve_for_instance(obj)
                info = traverser.resolved_paths
                subschema = info[-1]['field'].schema
                fields = subschema._meta.fields

                field = obj.dot_notation_to_field(parent_path)
                data = obj._primitive_data
                assert field
        return field
예제 #5
0
 def dot_notation_to_field(self, notation):
     traverser = DotPathTraverser(notation)
     traverser.resolve_for_instance(self)
     return traverser.current["field"]
예제 #6
0
 def dot_notation_to_field(self, notation):
     traverser = DotPathTraverser(notation)
     traverser.resolve_for_schema(self._document)
     return traverser.current['field']
예제 #7
0
 def dot_notation_to_value(self, notation):
     traverser = DotPathTraverser(notation)
     traverser.resolve_for_instance(self)
     return traverser.current['value']