From 6c03b320d1c241db3b15d6475360fe0c3417e63f Mon Sep 17 00:00:00 2001 From: Greg Doermann Date: Wed, 30 Jul 2014 18:17:28 -0600 Subject: [PATCH] Reverted the changes I made as everything I had done is in the code base now. --- cqlengine/__init__.py | 2 +- cqlengine/columns.py | 14 +++++++++----- cqlengine/functions.py | 15 --------------- cqlengine/models.py | 16 +++------------- 4 files changed, 13 insertions(+), 34 deletions(-) diff --git a/cqlengine/__init__.py b/cqlengine/__init__.py index ecec3cd0..ef273d96 100644 --- a/cqlengine/__init__.py +++ b/cqlengine/__init__.py @@ -4,7 +4,7 @@ from cassandra import ConsistencyLevel from cqlengine.columns import * from cqlengine.functions import * -from cqlengine.models import Model, CounterModel +from cqlengine.models import Model from cqlengine.query import BatchQuery diff --git a/cqlengine/columns.py b/cqlengine/columns.py index 9e92eefe..66286d38 100644 --- a/cqlengine/columns.py +++ b/cqlengine/columns.py @@ -473,11 +473,15 @@ class Float(Column): class Decimal(Column): db_type = 'decimal' -class Counter(Column): - #TODO: counter field - def __init__(self, **kwargs): - super(Counter, self).__init__(**kwargs) - raise NotImplementedError + def validate(self, value): + from decimal import Decimal as _Decimal + from decimal import InvalidOperation + val = super(Decimal, self).validate(value) + if val is None: return + try: + return _Decimal(val) + except InvalidOperation: + raise ValidationError("'{}' can't be coerced to decimal".format(val)) def to_python(self, value): return self.validate(value) diff --git a/cqlengine/functions.py b/cqlengine/functions.py index 164bfd41..b5f6a5af 100644 --- a/cqlengine/functions.py +++ b/cqlengine/functions.py @@ -116,18 +116,3 @@ class Token(BaseQueryFunction): for i, (col, val) in enumerate(zip(self._columns, self.value)): ctx[str(self.context_id + i)] = col.to_database(val) - -class NotSet(object): - """ - Different from None, so you know when it just wasn't set compared to passing in None - """ - pass - - -def format_timestamp(timestamp): - if isinstance(timestamp, datetime): - epoch = datetime(1970, 1, 1) - ts = long((timestamp - epoch).total_seconds() * 1000) - else : - ts = long(timestamp) - return ts diff --git a/cqlengine/models.py b/cqlengine/models.py index ae0c7e4d..d4ce1e77 100644 --- a/cqlengine/models.py +++ b/cqlengine/models.py @@ -8,7 +8,6 @@ from cqlengine.query import ModelQuerySet, DMLQuery, AbstractQueryableColumn from cqlengine.query import DoesNotExist as _DoesNotExist from cqlengine.query import MultipleObjectsReturned as _MultipleObjectsReturned - class ModelDefinitionException(ModelException): pass @@ -279,6 +278,9 @@ class BaseModel(object): def __init__(self, **values): self._values = {} + self._ttl = None + self._timestamp = None + for name, column in self._columns.items(): value = values.get(name, None) if value is not None or isinstance(column, columns.BaseContainerColumn): @@ -772,15 +774,3 @@ class Model(BaseModel): __metaclass__ = ModelMetaClass -class CounterBaseModel(BaseModel): - def _can_update(self): - # INSERT is not allowed for counter column families - return True - - -class CounterModel(CounterBaseModel): - """ - the db name for the column family can be set as the attribute db_name, or - it will be genertaed from the class name - """ - __metaclass__ = ModelMetaClass