def test_delete_all_in_view(): from melkman.db.util import delete_all_in_view from couchdb.schema import Document from couchdb.design import ViewDefinition db = make_db() view_bad = ViewDefinition('test_daiv', 'bad_items', ''' function(doc) { if (doc.badflag == true) { emit(true, null); } } ''') view_bad.sync(db) for i in range(10): doc = Document('doc_%d' % i) doc['foo'] = i if i % 2 == 1: doc['badflag'] = True doc.store(db) for i in range(10): assert 'doc_%d' % i in db delete_all_in_view(db, view_bad) for i in range(10): doc_id = 'doc_%d' % i if i % 2 == 0: assert doc_id in db, 'expected %s in db' % doc_id else: assert doc_id not in db, 'expected %s not in db' % doc_id
def store(self, db, update_timestamp=True): if not self.published: self.published = datetime.utcnow() if update_timestamp or not self.updated: self.updated = datetime.utcnow() Document.store(self, db)
def __init__(self, *args, **kw): Document.__init__(self, *args, **kw) self._context = None
def save(self): Document.store(self, self._context.db)
def __init__(self, *args, **kwargs): Document.__init__(self, *args, **kwargs)