class Test(Model): a = Integer() b = Integer() best = Integer() @a.setter def a(self, value): self.best = min(self.b, value) return value @b.setter def b(self, value): self.best = min(self.a, value) return value
class Flag(Model): uuid = UUID() name = Keyword() fans = List(Integer(), default=[])
class A(Model): fast = Integer(default=1) slow = Keyword(default='abc') flags = List(Keyword(), default=['cat-snack'])
class BannedTest(Model): ALL = Integer()
class BannedTest(Model): id = Integer()
class BannedTest(Model): _1 = Integer()
class Test(Model): a = Compound(Inner) b = Integer()
class Test(Model): a = Compound(InnerA) b = Compound(InnerB) c = Compound(InnerB, default={'number': 99, 'value': 'yellow'}) x = Integer() y = Integer(default=-1)
class Test(Model): a = Integer() b = Integer()
class InnerA(Model): number = Integer(default=10) value = Keyword()
class InnerB(Model): number = Integer() value = Keyword()
class Entry(Model): value = Integer() key = Keyword()
class Test(Model): values = List(Integer())
class Test(Model): first = Integer() @first.getter def first(self, value): return value if value >= 1 else 100
class A(Model): fast = Integer(default=1) slow = Keyword(default='abc') count = List(Integer())
class Test(Model): a = Mapping(Integer(), default={}, index=True, store=True)
class Inner(Model): a = Integer() b = Integer()
class Test(Model): a = Mapping(Integer(), default={}, index=False, store=False)
class Test(Model): first = Keyword() second = Integer()
def _validate_operations(self, operations): """ Validate the different operations received for a partial update TODO: When the field is of type Mapping, the validation/check only works for depth 1. A full recursive solution is needed to support multi-depth cases. :param operations: list of operation tuples :raises: DatastoreException if operation not valid """ if self.model_class: fields = self.model_class.flat_fields(show_compound=True) if 'classification in fields': fields.update({ "__access_lvl__": Integer(), "__access_req__": List(Keyword()), "__access_grp1__": List(Keyword()), "__access_grp2__": List(Keyword()) }) else: fields = None ret_ops = [] for op, doc_key, value in operations: if op not in self.UPDATE_OPERATIONS: raise DataStoreException(f"Not a valid Update Operation: {op}") if fields is not None: prev_key = None if doc_key not in fields: if '.' in doc_key: prev_key = doc_key[:doc_key.rindex('.')] if prev_key in fields and not isinstance( fields[prev_key], Mapping): raise DataStoreException( f"Invalid field for model: {prev_key}") else: raise DataStoreException( f"Invalid field for model: {doc_key}") if prev_key: field = fields[prev_key].child_type else: field = fields[doc_key] if op in [self.UPDATE_APPEND, self.UPDATE_REMOVE]: try: value = field.check(value) except (ValueError, TypeError, AttributeError): raise DataStoreException( f"Invalid value for field {doc_key}: {value}") elif op in [self.UPDATE_SET, self.UPDATE_DEC, self.UPDATE_INC]: try: value = field.check(value) except (ValueError, TypeError): raise DataStoreException( f"Invalid value for field {doc_key}: {value}") if isinstance(value, Model): value = value.as_primitives() elif isinstance(value, datetime): value = value.isoformat() elif isinstance(value, ClassificationObject): value = str(value) ret_ops.append((op, doc_key, value)) return ret_ops