def update_password(self, password): query = {'user_id': self.id} update = { 'user_id': self.id, 'password': password, 'update_time': datetime.now() } get_cursor('user_password').update(query, update, upsert=True)
def update(cls, id, text=None, width=None, height=None): update = {} if text: update['text'] = text if width and height: update.update({'width': width, 'height': height}) query = {'_id': ObjectId(id)} get_cursor(cls.table).update(query, {'$set': update}, safe=True)
def update(cls, id, text=None, width=None, height=None): update = {} if text: update["text"] = text if width and height: update.update({"width": width, "height": height}) query = {"_id": ObjectId(id)} get_cursor(cls.table).update(query, {"$set": update}, safe=True)
def get_by_user_and_photo(cls, user_id, photo_id): query = { 'photo_id': photo_id, 'author_id': author_id } item = get_cursor(cls.table).find_one(query) return cls.initialize(item)
def gets(cls, status=STATUS_PENDING, start=0, limit=10): query = {} if status: query['status'] = status rs = get_cursor(cls.table).find(query).sort('create_time', 1)\ .skip(start).limit(limit) return filter(None, [cls.initialize(r) for r in rs])
def update(self, name='', city='', blog='', intro='', uid=''): query = {'_id': ObjectId(self.id)} update = {} if name: update['name'] = name if city: update['city'] = city if blog: update['blog'] = blog if intro: update['intro'] = intro if uid: update['uid'] = uid if update: update['update_time'] = datetime.now() get_cursor(self.table).update(query, {'$set': update}, safe=True) return User.get(self.id)
def new(cls, photo_id, author_id): item = { 'photo_id': photo_id, 'author_id': author_id, 'create_time': datetime.now() } id = get_cursor(cls.table).insert(item, safe=True) if id: return cls.get(id) return None
def new(cls, name, email, city='', blog='', intro='', uid=''): current_time = datetime.now() item = { 'name': name, 'email': email, 'city': city, 'blog': blog, 'intro': intro, 'uid': uid, 'create_time': current_time, 'update_time': current_time } id = get_cursor(cls.table).insert(item, safe=True) if id: return cls.get(id) return None
def new(cls, text, kinds, tags, author_id, content): current_time = datetime.now() item = { "text": text, "kinds": kinds, "tags": tags, "author_id": author_id, "create_time": current_time, "update_time": current_time, "like_count": 0, "comment_count": 0, } id = get_cursor(cls.table).insert(item, safe=True) if id: photo = cls.get(id) if not photo: return None crop_photo_size = crop_photo(photo.filename, content) if crop_photo_size: width, height = crop_photo_size cls.update(id, width=width, height=height) return cls.get(id) return None
def new(cls, text, kinds, tags, author_id, content): current_time = datetime.now() item = { 'text': text, 'kinds': kinds, 'tags': tags, 'author_id': author_id, 'create_time': current_time, 'update_time': current_time, 'like_count': 0, 'comment_count': 0 } id = get_cursor(cls.table).insert(item, safe=True) if id: photo = cls.get(id) if not photo: return None crop_photo_size = crop_photo(photo.filename, content) if crop_photo_size: width, height = crop_photo_size cls.update(id, width=width, height=height) return cls.get(id) return None
def get_by_uid(cls, uid): query = {'uid': uid} item = get_cursor(cls.table).find_one(query) return item and cls.initialize(item)
def inc_comment_count(self, inc=1): query = {'_id': ObjectId(self.id)} update = {'$inc': {'comment_count': inc}} get_cursor(self.table).update(query, update, safe=True) self.comment_count += inc
def gets_by_category(cls, category, start=0, limit=10): query = {'kinds': {'$all': [category]}} rs = get_cursor(cls.table).find(query).sort('update_time', -1)\ .skip(start).limit(limit) return filter(None, [cls.initialize(r) for r in rs])
def gets_by_user(cls, user_id, start=0, limit=10): query = {'author_id': user_id} rs = get_cursor(cls.table).find(query).sort('update_time', -1)\ .skip(start).limit(limit) return filter(None, [cls.initialize(r) for r in rs])
def delete(cls, id): query = {'_id': ObjectId(id)} get_cursor(cls.table).remove(query)
def get_password(self): query = {'user_id': self.id} r = get_cursor('user_password').find_one(query) return r and r.get('password')
def get_count(cls): return get_cursor(cls.table).count()
def get_count_by_photo(cls, photo_id): query = {'photo_id': photo_id} return get_cursor(cls.table).find(query).count()
def gets_by_photo(cls, photo_id, start=0, limit=10): query = {'photo_id': photo_id} rs = get_cursor(cls.table).find(query).sort('create_time')\ .skip(start).limit(limit) return cls.initialize(item)
def get_count_by_user(cls, user_id): query = {'author_id': author_id} return get_cursor(cls.table).find(query).count()
def get_count(cls): return get_cursor(cls.table).find(query).count()
def get_count_by_category(cls, category): query = {'kinds': {'$all': [category]}} return get_cursor(cls.table).find(query).count()
def get_by_email(cls, email): query = {'email': email} item = get_cursor(cls.table).find_one(query) return item and cls.initialize(item)
def gets(cls, start=0, limit=10): rs = get_cursor(cls.table).find('update_time', -1).sort()\ .skip(start).limit(limit) return filter(None, [cls.initialize(r) for r in rs])
def get_count_by_category(cls, category): query = {"kinds": {"$all": [category]}} return get_cursor(cls.table).find(query).count()
def gets_by_photo(cls, photo_id, start=0, limit=10): query = {'photo_id': photo_id} rs = get_cursor(cls.table).find(query).sort('create_time', -1)\ .skip(start).limit(limit) return filter(None, [cls.initialize(r) for r in rs])
def get_count(cls, status=STATUS_PENDING): query = {} if status: query['status'] = status return get_cursor(cls.table).find(query).count()
def audit(self, status=STATUS_PASS): query = {'_id': ObjectId(self.id)} update = {'status': status} get_cursor(cls.table).update(query, {'$set': update}, safe=True)
def gets(cls, start=0, limit=10): rs = get_cursor(cls.table).find().sort('update_time', -1)\ .skip(start).limit(limit) return filter(None, [cls.initialize(r) for r in rs])
def get_count_by_user(cls, user_id): query = {'author_id': user_id} return get_cursor(cls.table).find(query).count()
def get_by_id(cls, id): query = {'_id': ObjectId(id)} item = get_cursor(cls.table).find_one(query) return item and cls.initialize(item)
def gets(cls, ids): query = {'_id': {'$in': [ObjectId(id) for id in ids]}} rs = get_cursor(cls.table).find(query) return filter(None, [cls.initialize(r) for r in rs])
def inc_comment_count(self, inc=1): query = {'_id': ObjectId(self.id)} update = {'$inc': {'comment_count': inc}} get_cursor(self.table).update(query, update, safe=True)
def get(cls, id): query = {'_id': ObjectId(id)} item = get_cursor(cls.table).find_one(query) return cls.initialize(item)
def inc_comment_count(self, inc=1): query = {"_id": ObjectId(self.id)} update = {"$inc": {"comment_count": inc}} get_cursor(self.table).update(query, update, safe=True)