def __init__(self, id, **kwargs): super(LastSeen, self).__init__(id, **kwargs) # Bad hack in order to fix couchdb pip non uniform loading/creating API doc = Document.load(id=id, db=settings.DB) if doc: self._data['_id'] = doc.id self._data['_rev'] = doc.rev self._data['seq'] = doc['seq'] self._data['last_modified'] = datetime.strptime( doc['last_modified'], '%Y-%m-%dT%H:%M:%SZ')
def _UpdateTo(self): ''' Updates the remote to match local. ''' document = Document.load(self._dump_db, self['_id']) if '_rev' in self: self.pop('_rev') for key in self.keys(): document[key] = self[key] document.store(self._dump_db)
def _UpdateFrom(self): ''' Sets a key:value pair for each field of the couch doc. Existing key:values are changed and new ones are created. Missing keys are NOT removed. Changes are made to the current instance but a copy is also returned. ''' document = Document.load(self._dump_db, doc_id) for field_name in document: if not field_name == '_id': self[field_name] = document[field_name]
def load(cls, *args, **kwargs): return Document.load(Connection().db, *args, **kwargs)