Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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])
Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 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])
Exemplo n.º 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])
Exemplo n.º 17
0
 def delete(cls, id):
     query = {'_id': ObjectId(id)}
     get_cursor(cls.table).remove(query)
Exemplo n.º 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')
Exemplo n.º 19
0
 def get_count(cls):
     return get_cursor(cls.table).count()
Exemplo n.º 20
0
 def get_count_by_photo(cls, photo_id):
     query = {'photo_id': photo_id}
     return get_cursor(cls.table).find(query).count()
Exemplo n.º 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)
Exemplo n.º 22
0
 def get_count_by_user(cls, user_id):
     query = {'author_id': author_id}
     return get_cursor(cls.table).find(query).count()
Exemplo n.º 23
0
 def get_count(cls):
     return get_cursor(cls.table).find(query).count()
Exemplo n.º 24
0
 def get_count_by_category(cls, category):
     query = {'kinds': {'$all': [category]}}
     return get_cursor(cls.table).find(query).count()
Exemplo n.º 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)
Exemplo n.º 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])
Exemplo n.º 27
0
 def get_count_by_category(cls, category):
     query = {"kinds": {"$all": [category]}}
     return get_cursor(cls.table).find(query).count()
Exemplo n.º 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])
Exemplo n.º 29
0
 def get_count(cls, status=STATUS_PENDING):
     query = {}
     if status:
         query['status'] = status
     return get_cursor(cls.table).find(query).count()
Exemplo n.º 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])
Exemplo n.º 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)
Exemplo n.º 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])
Exemplo n.º 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])
Exemplo n.º 34
0
 def get_count_by_user(cls, user_id):
     query = {'author_id': user_id}
     return get_cursor(cls.table).find(query).count()
Exemplo n.º 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)
Exemplo n.º 36
0
 def get_count_by_category(cls, category):
     query = {'kinds': {'$all': [category]}}
     return get_cursor(cls.table).find(query).count()
Exemplo n.º 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])
Exemplo n.º 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)
Exemplo n.º 39
0
 def delete(cls, id):
     query = {'_id': ObjectId(id)}
     get_cursor(cls.table).remove(query)
Exemplo n.º 40
0
 def get(cls, id):
     query = {'_id': ObjectId(id)}
     item = get_cursor(cls.table).find_one(query)
     return cls.initialize(item)
Exemplo n.º 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)