Example #1
0
 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)
Example #2
0
 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)
Example #3
0
 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)
Example #4
0
 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)
Example #5
0
 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)
Example #6
0
 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])
Example #7
0
 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)
Example #8
0
 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
Example #9
0
 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
Example #10
0
 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
Example #11
0
 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
Example #12
0
 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
Example #13
0
 def get_by_uid(cls, uid):
     query = {'uid': uid}
     item = get_cursor(cls.table).find_one(query)
     return item and cls.initialize(item)
Example #14
0
 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
Example #15
0
 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])
Example #16
0
 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])
Example #17
0
 def delete(cls, id):
     query = {'_id': ObjectId(id)}
     get_cursor(cls.table).remove(query)
Example #18
0
 def get_password(self):
     query = {'user_id': self.id}
     r = get_cursor('user_password').find_one(query)
     return r and r.get('password')
Example #19
0
 def get_count(cls):
     return get_cursor(cls.table).count()
Example #20
0
 def get_count_by_photo(cls, photo_id):
     query = {'photo_id': photo_id}
     return get_cursor(cls.table).find(query).count()
Example #21
0
 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)
Example #22
0
 def get_count_by_user(cls, user_id):
     query = {'author_id': author_id}
     return get_cursor(cls.table).find(query).count()
Example #23
0
 def get_count(cls):
     return get_cursor(cls.table).find(query).count()
Example #24
0
 def get_count_by_category(cls, category):
     query = {'kinds': {'$all': [category]}}
     return get_cursor(cls.table).find(query).count()
Example #25
0
 def get_by_email(cls, email):
     query = {'email': email}
     item = get_cursor(cls.table).find_one(query)
     return item and cls.initialize(item)
Example #26
0
 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])
Example #27
0
 def get_count_by_category(cls, category):
     query = {"kinds": {"$all": [category]}}
     return get_cursor(cls.table).find(query).count()
Example #28
0
 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])
Example #29
0
 def get_count(cls, status=STATUS_PENDING):
     query = {}
     if status:
         query['status'] = status
     return get_cursor(cls.table).find(query).count()
Example #30
0
 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])
Example #31
0
 def audit(self, status=STATUS_PASS):
     query = {'_id': ObjectId(self.id)}
     update = {'status': status}
     get_cursor(cls.table).update(query, {'$set': update}, safe=True)
Example #32
0
 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])
Example #33
0
 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])
Example #34
0
 def get_count_by_user(cls, user_id):
     query = {'author_id': user_id}
     return get_cursor(cls.table).find(query).count()
Example #35
0
 def get_by_id(cls, id):
     query = {'_id': ObjectId(id)}
     item = get_cursor(cls.table).find_one(query)
     return item and cls.initialize(item)
Example #36
0
 def get_count_by_category(cls, category):
     query = {'kinds': {'$all': [category]}}
     return get_cursor(cls.table).find(query).count()
Example #37
0
 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])
Example #38
0
 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)
Example #39
0
 def delete(cls, id):
     query = {'_id': ObjectId(id)}
     get_cursor(cls.table).remove(query)
Example #40
0
 def get(cls, id):
     query = {'_id': ObjectId(id)}
     item = get_cursor(cls.table).find_one(query)
     return cls.initialize(item)
Example #41
0
 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)