def __init__(self, id=None, document_type=None, **values): if id is None: id = uuid1().hex Document.__init__(self, id=id, **values) self.created = utcnow() self.document_type = document_type self.void = False
def __init__(self, name, level, seller, price, tags): Document.__init__(self) self.name = name self.level = level self.seller = seller self.gmt_create = str(datetime.now()) self.price = price self.tags = tags
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 __init__(self, id=None, **values): Document.__init__(self, id, **values) self.class_db = get_couch_db(type(self).__name__)
def store(self, db): self.modified = datetime.datetime.utcnow() if not self.created: self.created = self.modified Document.store(self, db)
def query(cls, map_function, reduce_func="", *args, **kwargs): return Document.query(Connection().db, map_function, reduce_func, *args, **kwargs)
def load(cls, *args, **kwargs): return Document.load(Connection().db, *args, **kwargs)
def __init__(self, *args, **kwargs): Document.__init__(self, *args, **kwargs) if not getattr(self, 'id', None): self.id = uuid4().hex
def __init__(self, db=None): if db: self.db = db Document.__init__(self)
def __init__(self,space=False): Document.__init__(self) self.space = space