Example #1
0
def get_actionlist():
    jdata = request.get_json()
    uid = jdata['uid']
    off = jdata['off']
    state = OPER_INVALID
    items = []
    try:
        sql = " select a.action_type,b.id,b.title,b.content,b.type,b.abstract,c.name "
        sql += " from user_action a, collection b ,user c "
        sql += " where a.obj_id = b.id and a.uid = c.id and "
        sql += " a.action_type in ('1000','1100','1200') and b.create_by = %s " % uid
        sql += " order by a.create_time desc limit %s,%s" % (int(off),
                                                             PAGE_SIZE)

        session = Session()
        relist = session.query(UserAction.action_type, Collection.id,
                               Collection.type, Collection.content,
                               Collection.abstract,
                               User.name).from_statement(sql).all()
        for e in relist:
            d = {
                'cid': e.id,
                'type': e.type,
                'name': e.name,
                'action_type': e.action_type,
                'abstract': e.abstract
            }
            items.append(d)
        state = OPER_SUCCESS
    except Exception, e:
        print e
        logger = logging.getLogger('watch_dog')
        logger.error(e)
        state = OPER_EXCEPTION
Example #2
0
def add_favorite():
    jdata = request.get_json()
    state = constants.OPER_INVALID
    bids = jdata['bids'].strip()
    ids = bids[1:-1].split(',')
    try:
        session = Session()
        for bid in ids:
            item = Favorite(collection_id=jdata['cid'],
                            box_id=bid,
                            create_by=jdata['create_by'])
            session.add(item)
        action = UserAction(uid=jdata['create_by'],
                            action_type=ACTION_COLLECT_COLLECTION,
                            obj_id=jdata['cid'])
        session.add(action)
        session.query(FavoriteBox).filter(FavoriteBox.id.in_(
            tuple(ids))).update(
                {FavoriteBox.box_count: FavoriteBox.box_count + 1},
                synchronize_session=False)

        session.commit()
        state = constants.OPER_SUCCESS
    except Exception, e:
        print e
        logger = logging.getLogger('watch_dog')
        logger.error(e)
        state = constants.OPER_EXCEPTION
Example #3
0
def add_comment():
    jdata = request.get_json()
    state = OPER_INVALID
    cid = jdata['cid']
    receiver_id = jdata['receiver_id']
    comment_type = jdata['type']
    try:
        session = Session()
        item = Comment(collection_id=cid,
                       type=comment_type,
                       content=jdata['content'],
                       receiver_id=receiver_id,
                       create_by=jdata['create_by'])
        session.add(item)
        session.commit()
        #use trigger more flexible
        session.query(Collection).filter(Collection.id == cid).update(
            {Collection.comment_count: Collection.comment_count + 1})

        session.commit()
        state = constants.OPER_SUCCESS
    except Exception, e:
        print e
        logger = logging.getLogger('watch_dog')
        logger.error(e)
        state = constants.OPER_EXCEPTION
Example #4
0
def getpacklist():
    jdata = request.get_json();
    off= jdata['off'];
    items = [] ; 
    try:
        session = Session();
        relist = session.query(Collection,User).filter(Collection.create_by == User.id,
                                                Collection.pack_id == jdata['pack_id'],
                                                Collection.state == '1').\
        order_by(Collection.last_modify).offset(off).limit(PAGE_SIZE).all();
        for c in relist :
            d = {
                 'cid':c[0].id,
                 'cisn':c[0].cisn,
                 'title':c[0].title,
                 'abstract':c[0].abstract,
                 'create_by':c[0].create_by,
                 'vote_count':c[0].vote_count,
                 'name':c[1].name,
                 'sex':c[1].sex,
                 'signature':c[1].signature,
                 'comment_count':c[0].comment_count
            }; 
            if c[1].photo_url is not None :
                d['photo'] = NGINX_USERPHOTO_BIG_URL_BASE+c[1].photo_url
            else:
                d['photo'] = "";
            if c[0].cover is not None :
                d['cover'] = NGINX_IMAGE_SERVER_URI+c[0].cover 
            items.append(d); 
    except Exception,e:
        print e ; 
        logger = logging.getLogger('watch_dog');
        logger.error(e);
Example #5
0
def get_topic():
    jdata = request.get_json()
    uid = jdata['uid']
    obj_id = jdata['obj_id']
    state = OPER_INVALID
    info = {}
    session = Session()
    try:
        sql = " select a.id,a.topic_name,a.topic_desc,a.focus_count ,"
        if uid is None:
            sql += " ( select false from dual ) is_focus "
        else:
            sql += " (select b.id from userfocus b where a.id = b.obj_id and b.focus_type ='002' and b.user_id = %s limit 1 ) is_focus " % (
                uid)
        sql += " from topic a where a.id = %s " % (obj_id)
        entry = session.query(Topic.id, Topic.topic_name, Topic.topic_desc,
                              Topic.focus_count,
                              'is_focus').from_statement(sql).one()
        flag = True
        if entry.is_focus is None or bool(entry.is_focus) is False:
            flag = False
        info = {
            'topic_id': entry.id,
            'topic_name': entry.topic_name,
            'topic_desc': entry.topic_desc,
            'focus_count': entry.focus_count,
            'is_focus': flag
        }
        state = OPER_SUCCESS
    except Exception, e:
        print e
        logger = logging.getLogger('watch_dog')
        logger.error(e)
        state = OPER_EXCEPTION
Example #6
0
def config_removebytype(ctype):
    session = Session()
    try:
        session.query(ServerConfig).filter(
            ServerConfig.cfg_type == ctype).delete()
    except Exception, e:
        print e
Example #7
0
def get_userlist():
    jdata = request.get_json()
    s = jdata['slice']
    off = jdata['off']
    session = Session()
    items = []
    state = OPER_INVALID
    try:
        relist = session.query(User).filter(User.name.like('%'+s+'%')).\
                    offset(int(off)).limit(10).all()
        for e in relist:
            d = {
                'id': e.id,
                'name': e.name,
                'sex': e.sex,
                'signature': e.signature
            }

            if e.photo_url is not None:
                d['photo'] = NGINX_USERPHOTO_MEDIUM_URL_BASE + e.photo_url
            else:
                d['photo'] = ""
            items.append(d)
            state = OPER_SUCCESS
    except Exception, e:
        print e
        logger = logging.getLogger('watch_dog')
        logger.error(e)
        state = OPER_EXCEPTION
Example #8
0
def get_topiclist():
    jdata = request.get_json()
    off = request.get_json().get("off")
    s = jdata['slice']
    session = Session()
    items = []
    state = OPER_INVALID
    try:
        relist = None
        if off is None:
            relist = session.query(Topic).filter(
                Topic.topic_name.like('%' + s + '%')).all()
        else:
            relist = session.query(Topic).filter(Topic.topic_name.like('%'+s+'%')).\
                    offset(int(off)).limit(10).all()
        for e in relist:
            d = {
                'tid': e.id,
                'topic_name': e.topic_name,
                'topic_desc': e.topic_desc,
                'topic_pic': NGINX_TOPICIMAGE_URL_BASE + e.pic_url
            }
            items.append(d)
        print items
        state = OPER_SUCCESS
    except Exception, e:
        print e
        logger = logging.getLogger('watch_dog')
        logger.error(e)
        state = OPER_EXCEPTION
Example #9
0
def get_userpacks():
    req_uid = request.get_json().get("req_uid");
    uid = request.get_json().get("uid");
    ismyself = False ; 
    if req_uid == uid : #myself 
        ismyself = True ; 
    off = request.get_json().get("off"); 
    state = OPER_INVALID;
    items = [] ;     
    session=Session();
    try:
        if ismyself:
            relist = session.query(CollectPack).filter(CollectPack.create_by == uid)\
                    .offset(int(off)).limit(10).all();
        else:
            relist = session.query(CollectPack).filter(CollectPack.create_by == uid,CollectPack.is_private == False)\
                        .offset(int(off)).limit(10).all();
        for e in relist :
            d={
               'id':e.id,
               'pack_name':e.pack_name,
               'pack_desc':e.pack_desc,
               'pack_type':e.type,
               'focus_count':e.focus_count,
               'collect_count':e.collect_count,
               'topic_ids':e.topic_id,
               'create_by':e.create_by
            };
            items.append(d);
        state = OPER_SUCCESS;
    except Exception,e:
        print e ;
        logger = logging.getLogger('watch_dog');
        logger.error(e);
        state = OPER_EXCEPTION ; 
Example #10
0
def get_boxes():
    jdata = request.get_json()
    uid = jdata['uid']
    session = Session()
    state = OPER_INVALID
    items = []
    try:
        relist = session.query(FavoriteBox).filter(
            FavoriteBox.create_by == uid).all()
        state = OPER_SUCCESS
        for e in relist:
            d = {
                'box_id': e.id,
                'box_type': e.type,
                'box_type': e.type,
                'box_name': e.box_name,
                'box_desc': e.box_desc,
                'focus_count': e.focus_count,
                'is_private': e.is_private,
                'create_by': e.create_by
            }
            items.append(d)
    except Exception, e:
        print e
        logger = logging.getLogger('watch_dog')
        logger.error(e)
        state = OPER_EXCEPTION
Example #11
0
def get_boxdetail():
    jdata = request.get_json()
    uid = jdata['uid']
    off = jdata['off']
    session = Session()
    items = []
    state = OPER_INVALID
    try:
        sql = " select a.id,a.type,a.box_name,a.box_desc ,a.focus_count, a.box_count,"
        sql += " (select group_concat(b.title) from collection b ,favorite c where c.collection_id = b.id and c.box_id = a.id limit 3) titles"
        sql += " from favorite_box a where a.create_by = %s " % uid
        sql += " order by a.create_time desc limit %s,%s" % (int(off),
                                                             PAGE_SIZE)
        relist = session.query(FavoriteBox.id, FavoriteBox.type,
                               FavoriteBox.box_name, FavoriteBox.box_desc,
                               FavoriteBox.box_count, FavoriteBox.focus_count,
                               'titles').from_statement(sql).all()
        for e in relist:
            d = {
                'box_id': e.id,
                'box_type': e.type,
                'box_name': e.box_name,
                'box_desc': e.box_desc,
                'box_count': e.box_count,
                'focus_count': e.focus_count,
                'titles': e.titles
            }
            items.append(d)
        print items
        state = OPER_SUCCESS
    except Exception, e:
        print e
        logger = logging.getLogger('watch_dog')
        logger.error(e)
        state = OPER_EXCEPTION
Example #12
0
def config_removebykey(key):
    session = Session()
    try:
        session.query(ServerConfig).filter(
            ServerConfig.cfg_key == key).delete()
    except Exception, e:
        print e
Example #13
0
def del_follows():
    jdata = request.get_json()
    follower_id = jdata['follower_id']
    obj_id = jdata['obj_id']
    focus_type = jdata['type']
    state = OPER_INVALID
    session = Session()
    try:
        session.query(Userfocus).filter(Userfocus.user_id == follower_id and \
            Userfocus.focus_type == focus_type and Userfocus.obj_id == obj_id ).delete()

        if focus_type == FOLLOW_TYPE_TOPIC:
            session.query(Topic).filter(Topic.id == obj_id).update(
                {Topic.focus_count: Topic.focus_count - 1})
        elif focus_type == FOLLOW_TYPE_COLLECTPACK:
            session.query(CollectPack).filter(CollectPack.id == obj_id).update(
                {CollectPack.focus_count: CollectPack.focus_count - 1})
        elif focus_type == FOLLOW_TYPE_COLLECTOR:
            pass
        state = OPER_SUCCESS
        session.commit()
    except Exception, e:
        print e
        logger = logging.getLogger('watch_dog')
        logger.error(e)
        state = OPER_EXCEPTION
Example #14
0
def get_packinfo():
    jdata = request.get_json();
    uid = jdata['uid'];
    pack_id = jdata['pack_id'];
    state  = OPER_INVALID; 
    session = Session();
    result = {};
    try:
        sql = " select a.id,a.pack_name,a.type,a.pack_desc,a.focus_count,a.create_by,a.topic_id,a.is_private,";
        sql += " u.name,u.sex,u.photo_url,u.signature,"    
        if uid is None: #not login actually .
            sql += " (select false from dual ) is_focus " ; 
        else:     
            sql += " (select b.id from userfocus b where a.id = b.obj_id and b.focus_type ='003' and b.user_id = %s limit 1 ) is_focus" % (uid); 
        sql += " from collect_pack a ,user u where a.create_by = u.id and  a.id = %s " % (pack_id);
        entry = session.query(CollectPack.id,CollectPack.pack_name,CollectPack.type,CollectPack.pack_desc,CollectPack.focus_count,
                              CollectPack.create_by,CollectPack.topic_id,CollectPack.is_private,
                              User.name,User.photo_url,User.sex,User.signature,'is_focus',).\
                              from_statement(sql).first();  
        isFocus = True;
        if entry.is_focus is None or bool(entry.is_focus) is False:
            isFocus = False ; 
        result = {
            'id' : entry.id,
            'pack_name':entry.pack_name,
            'pack_type':entry.type,
            'pack_desc':entry.pack_desc,
            'focus_count':entry.focus_count,
            'create_by':entry.create_by,
            'is_focus': isFocus,
            'topic_id':entry.topic_id,
            'is_private':bool(entry.is_private),
            'name':entry.name,
            'sex':entry.sex,
            'signature':entry.signature            
        };
        
        if entry.topic_id is not None and entry.topic_id != '':
            tids = entry.topic_id.split(','); 
            names = '';
            item = session.query(Topic.topic_name).filter(Topic.id.in_(tuple(tids))).all();
            for e in item :
                names+=e.topic_name ; 
                names+=',';
            result['topic_names'] = names; 
        else :
            result['topic_names'] = '';
    
        if entry.photo_url is not None :
            result['photo'] = NGINX_USERPHOTO_BIG_URL_BASE+entry.photo_url
        else:
            result['photo'] = "";
        print result ;
        state = OPER_SUCCESS ; 
    except Exception,e:
        print e ; 
        logger = logging.getLogger('watch_dog');
        logger.error(e);
        state= OPER_EXCEPTION ; 
Example #15
0
 def verify_auth_token(token):
     s = Serializer(app.secret_key)
     try:
         data = s.loads(token)
     except SignatureExpired:
         return None
     except BadSignature:
         return None
     db_session = Session()
     user = db_session.query(User).filter(User.id == data['id'])
     db_session.close()
     return user
Example #16
0
def verify_password(useremail_or_token, password):
    # first try to authenticate by token
    db_session = Session()
    user = User.verify_auth_token(useremail_or_token)
    if not user:
        # try to authenticate with email/password
        user = db_session.query(User).filter_by(
            email=useremail_or_token).first()
        if not user or not user.verify_password(password):
            return False
    g.user = user
    db_session.close()
    return True
Example #17
0
def get_bestauthor():
    #jdata = request.get_json();
    #tid = jdata['tid'];
    state = OPER_INVALID
    try:
        session = Session()
        sql = "select a.id,a.name,a.sex,a.signature,a.photo_url from user a limit 0,5 "
        relist = session.query(User.id, User.name, User.sex, User.signature,
                               User.photo_url).from_statement(sql).all()
        state = OPER_SUCCESS
    except Exception, e:
        print e
        state = OPER_EXCEPTION
Example #18
0
def add_collection():
    jdata = request.get_json()
    uid = jdata['create_by']
    pid = jdata['pack_id']
    ctype = jdata['type']
    #collection type
    content = jdata['content']
    abstract = jdata['abstract']
    cover = jdata['cover']
    state = constants.OPER_INVALID
    result = {}
    if ctype == CTYPE_TEXTIMG:
        content = replace_url(content)
    try:
        session = Session()
        item = Collection(type=ctype,title=jdata['title'],cover=cover,content=content,abstract = abstract,\
                          pack_id = pid,cisn = jdata['cisn'],create_by=uid)
        session.query(CollectPack).filter(CollectPack.id == pid).update(
            {CollectPack.collect_count: CollectPack.collect_count + 1})
        session.add(item)
        session.commit()
        result['cid'] = item.id
        state = constants.OPER_SUCCESS
    except Exception, e:
        print e
        logger = logging.getLogger('watch_dog.'.join(__name__))
        logger.error(e)
        state = constants.OPER_EXCEPTION
Example #19
0
def get_userinfo():
    jdata = request.get_json()
    uid = jdata['uid']
    obj_id = jdata['obj_id']
    state = OPER_INVALID
    info = {}
    try:
        session = Session()
        sql = " select a.id,a.name,a.sex,a.email,a.photo_url,a.signature,a.login_state,a.reg_state,a.profession,a.residence,a.education,"
        if uid is None or uid == '':
            sql += " (select false from dual ) is_focus "
        else:
            sql += " (select b.id from userfocus b where a.id = b.obj_id and b.focus_type ='001' and b.user_id = %s limit 1 ) is_focus" % (
                uid)
        sql += " from user a where a.id = %s " % (obj_id)
        #entry = session.query(User).filter(User.id==jdata['uid']).one();
        entry = session.query(User.id, User.name, User.sex, User.email,
                              User.photo_url, User.signature, User.profession,
                              User.residence, User.education, User.login_state,
                              User.reg_state,
                              'is_focus').from_statement(sql).one()
        state = OPER_SUCCESS
        flag = True
        if entry.is_focus is None or bool(entry.is_focus) is False:
            flag = False
        info = {
            'id': entry.id,
            'name': entry.name,
            'sex': entry.sex,
            'email': entry.email,
            'signature': entry.signature,
            'login_state': entry.login_state,
            'reg_state': entry.reg_state,
            'is_focus': flag,
            'profession': entry.profession,
            'residence': entry.residence,
            'education': entry.education
        }

        if entry.photo_url is not None:
            info['photo'] = NGINX_USERPHOTO_BIG_URL_BASE + entry.photo_url
        else:
            info['photo'] = ""

    except Exception, e:
        print e
        logger = logging.getLogger('watch_dog')
        logger.error(e)
        state = OPER_EXCEPTION
Example #20
0
def del_comment():
    jdata = request.get_json();
    state = constants.OPER_INVALID;
    session = Session();
    try:
        session.query(Comment).filter(Comment.id == jdata['comment_id']).delete();
        session.commit();
        session.query(Collection).filter(Collection.id == jdata['cid']).update({
                                Collection.comment_count: Collection.comment_count - 1});
        session.commit();     
        state = constants.OPER_SUCCESS;
    except Exception,e:
        print e ; 
        logger = logging.getLogger('watch_dog');
        logger.error(e);
        state = constants.OPER_EXCEPTION;
Example #21
0
def get_favorite():
    jdata = request.get_json()
    session = Session()
    items = []
    state = OPER_INVALID
    off = int(jdata['off'])
    try:
        sql = " select a.id as cid,a.title,a.abstract,a.content,a.type,a.last_modify,a.pack_id,a.create_by , a.vote_count , "
        sql += " a.cisn,b.name,b.sex,b.signature,b.photo_url ,"
        sql += " (select count(*) from comment c where c.collection_id = a.id ) comment_count "
        sql += " from collection  a , user b, favorite f  where a.create_by = b.id "
        sql += " and a.id = f.collection_id and a.state= 1 and  f.create_by = %s " % (
            jdata['uid'])
        sql += " and f.box_id = %s " % (jdata['box_id'])
        sql += " order by a.last_modify desc  limit %s,%s " % (off, PAGE_SIZE)
        relist = session.query('cid', Collection.title, Collection.abstract,
                               Collection.cisn, Collection.content,
                               Collection.type, Collection.pack_id,
                               Collection.create_by, Collection.vote_count,
                               User.name, User.sex, User.signature,
                               User.photo_url,
                               'comment_count').from_statement(sql).all()
        for e in relist:
            d = {
                'id': e.cid,
                'title': e.title,
                'abstract': e.abstract,
                'cisn': e.cisn,
                'vote_count': e.vote_count,
                'create_by': e.create_by,
                'comment_count': e.comment_count,
                'name': e.name,
                'signature': e.signature,
                'sex': e.sex
            }
            if e.photo_url is not None:
                d['photo'] = str(NGINX_USERPHOTO_URL_BASE + e.photo_url)
            else:
                d['photo'] = ''
            items.append(d)
        state = OPER_SUCCESS
    except Exception, e:
        print e
        logger = logging.getLogger('watch_dog')
        logger.error(e)
        state = OPER_EXCEPTION
Example #22
0
def gethotpacks():
    jdata = request.get_json();
    off = jdata['off'];
    action = jdata['action'];   
    state = OPER_INVALID;
    items = [] ; 
    try:
        session=Session();
        sql = ' select distinct a.id,a.type,a.box_name,a.box_desc,a.box_count , a.focus_count,b.id as uid ,b.name,b.sex, b.photo_url '; 
        sql +=' from favorite_box a, user b ';
        sql +=' where a.create_by = b.id and a.is_private = false  '
        if int(off) == 0 :
            sql += " order by a.focus_count desc   limit %s,%s " % (0,PAGE_SIZE);
        elif action == 'REQ_NEWDATA':
            sql += " and a.focus_count > %s order by a.focus_count desc  limit 0, 6" % (jdata['threshold']);
        elif action == 'REQ_HISTORY' :
            sql += " order by a.focus_count desc  limit %s, %s " % (int(off),PAGE_SIZE);    
        
        reslist = session.query(FavoriteBox.id,FavoriteBox.type,FavoriteBox.box_name,FavoriteBox.box_desc,FavoriteBox.focus_count,
            FavoriteBox.box_count,'uid',User.name,User.sex,User.photo_url).from_statement(sql).all();
        for e in reslist:
            d={
               'box_id':e.id,
               'box_type':e.type,
               'box_name':e.box_name,
               'box_desc':e.box_desc,
               'box_count':e.box_count,
               'focus_count':e.focus_count, 
               'uid':e.uid,
               'name':e.name,
               'sex' :e.sex,
            };            
            if e.photo_url is not None :
                d['photo'] = NGINX_USERPHOTO_BIG_URL_BASE+e.photo_url
            else:
                d['photo'] = "";
                
            items.append(d);
        state = OPER_SUCCESS;
    except Exception,e:
        print e; 
        logger = logging.getLogger('watch_dog');
        logger.error(e);
        state = OPER_EXCEPTION;
Example #23
0
def get_userdetail():
    jdata = request.get_json()
    uid = jdata['uid']
    requestor_id = jdata['requestor_id']
    session = Session()
    state = OPER_INVALID
    d = {}
    flag = True
    try:
        sql = "select a.*,(select count(*) from userfocus b where b.user_id=a.id and b.focus_type='002') topic_count,"
        sql += "(select count(*)from userfocus b where b.user_id = a.id and b.focus_type= '001') my_follow_count ,"
        sql += "(select count(*)from userfocus b where b.obj_id = a.id and b.focus_type ='001' ) follow_me_count ,"
        if requestor_id == uid:  #myself
            sql += "(select count(*) from collect_pack b where b.create_by = a.id) pack_count,"
            sql += '(select false from dual ) is_focus'
        else:
            sql += "(select count(*) from collect_pack b where b.create_by = a.id and b.is_private = false) pack_count,"
            sql += "(select b.id from userfocus b where b.obj_id = a.id and b.user_id = %s and b.focus_type='001' limit 0,1 ) is_focus " % (
                requestor_id)
        sql += " from user a where a.id = %s" % uid
        entry = session.query(User.email, User.profession, User.residence,
                              User.education, 'topic_count', 'my_follow_count',
                              'follow_me_count', 'pack_count',
                              'is_focus').from_statement(sql).one()

        if entry.is_focus is None or bool(entry.is_focus) is False:
            flag = False
        d = {
            'topic_count': entry.topic_count,
            'my_follow_count': entry.my_follow_count,
            'follow_me_count': entry.follow_me_count,
            'pack_count': entry.pack_count,
            'is_focus': flag,
            'email': entry.email,
            'profession': entry.profession,
            'residence': entry.residence,
            'education': entry.education
        }
        state = OPER_SUCCESS
    except Exception, e:
        print e
        logger = logging.getLogger('watch_dog')
        logger.error(e)
        state = OPER_EXCEPTION
Example #24
0
def get_comments():
    jdata = request.get_json()
    off = jdata['off']
    cid = jdata['cid']
    state = OPER_INVALID
    items = []
    try:
        session = Session()
        sql = "select a.id,a.collection_id,a.type,a.content,a.create_by,a.create_time,a.vote_count ,b.name,b.sex,b.photo_url,"
        sql += "(select name from user c where c.id = a.receiver_id ) receiver_name "
        sql += " from comment a,user b where a.create_by = b.id and a.collection_id = %s " % cid
        sql += " order by a.create_time "
        sql += " limit %s,%s " % (int(off), 10)
        relist = session.query(Comment.id, Comment.collection_id, Comment.type,
                               Comment.content, Comment.create_by,
                               Comment.create_time, Comment.vote_count,
                               User.name, User.sex, User.photo_url,
                               'receiver_name').from_statement(sql).all()
        state = OPER_SUCCESS
        for e in relist:
            d = {
                'comment_id': e.id,
                'cid': e.collection_id,
                'type': e.type,
                'content': e.content,
                'create_by': e.create_by,
                'create_time': e.create_time.strftime('%Y-%m-%d'),
                'vote_count': e.vote_count,
                'user_name': e.name,
                'user_sex': e.sex,
                'receiver_name': e.receiver_name
            }

            if e.photo_url is not None:
                d['user_pic'] = NGINX_USERPHOTO_URL_BASE + e.photo_url
            else:
                d['user_pic'] = ""
            items.append(d)
    except Exception, e:
        print e
        logger = logging.getLogger('watch_dog')
        logger.error(e)
        state = OPER_EXCEPTION
Example #25
0
def get_collectedbox():
    jdata = request.get_json()
    uid = jdata['uid']
    cid = jdata['cid']
    session = Session()
    state = OPER_INVALID
    box_ids = ''
    try:
        relist = session.query(Favorite).filter(Favorite.create_by == uid,\
            Favorite.collection_id == cid).all()
        state = OPER_SUCCESS
        for e in relist:
            box_ids += str(e.box_id)
            box_ids += ','
    except Exception, e:
        print e
        logger = logging.getLogger('watch_dog')
        logger.error(e)
        state = OPER_EXCEPTION
Example #26
0
def get_useraction():
    jdata = request.get_json()
    uid = jdata['uid']
    obj_id = jdata['obj_id']
    actions = ''
    state = OPER_INVALID
    try:
        session = Session()
        relist = session.query(UserAction).filter(
            UserAction.uid == uid, UserAction.obj_id == obj_id).all()
        for e in relist:
            actions += e.action_type
            actions += ','
        state = OPER_SUCCESS
    except Exception, e:
        print e
        logger = logging.getLogger('watch_dog')
        logger.error(e)
        state = OPER_EXCEPTION
Example #27
0
def del_topic(did):
    try:
        session= Session();
        session.query(Topic).filter(Topic.id==did).delete();
        session.commit();
    except Exception,e:
        print e; 
Example #28
0
def update_collection():
    jdata = request.get_json()
    cid = jdata['cid']
    fields = {}
    if 'title' in jdata:
        fields['title'] = jdata['title']
    if 'content' in jdata:
        content = jdata['content']
        content = replace_url(content)
        fields['content'] = content
    if 'type' in jdata:
        fields['type'] = jdata['type']
    if 'vote_count' in jdata:
        fields['vote_count'] = jdata['vote_count']
    if 'bro_count' in jdata:
        fields['bro_count'] = jdata['bro_count']
    if 'share_count' in jdata:
        fields['share_count'] = jdata['share_count']
    if 'visit_count' in jdata:
        fields['visit_count'] = jdata['visit_count']
    if 'focus_count' in jdata:
        fields['focus_count'] = jdata['focus_count']
    if 'cover' in jdata:
        fields['cover'] = jdata['cover']
    state = OPER_INVALID
    try:
        session = Session()
        session.query(Collection).filter(Collection.id == cid).update(fields)
        session.commit()
        state = OPER_SUCCESS
    except Exception, e:
        print e
        logger = logging.getLogger('watch_dog')
        logger.error(e)
        state = OPER_EXCEPTION
Example #29
0
def del_collectpack():
    jdata = request.get_json()
    state = constants.OPER_INVALID
    session = Session()
    print jdata['pid']
    try:
        '''
        sql = " select * from imagelib where collection_id in " ; 
        sql += " (select id from collection where pack_id = %s ) " % jdata['pid'];       
        imgs = session.query(Imagelib.id,Imagelib.type,Imagelib.image_name,Imagelib.image_url).\
                from_statement(sql).all();
        remove_files(imgs);        
        session.execute('delete from imagelib  where collection_id in(select id from collection  where pack_id = :id )',
                        {'id':jdata['pid']});
        session.query(Collection).filter(Collection.pack_id == jdata["pid"]).delete();        
        session.query(CollectPack).filter(CollectPack.id == jdata["pid"]).delete();    
        '''
        #update state
        session.query(CollectPack).filter(
            CollectPack.id == jdata['pid']).update({CollectPack.state: 0})
        session.commit()
        state = constants.OPER_SUCCESS
    except Exception, e:
        print e
        state = constants.OPER_EXCEPTION
        logger = logging.getLogger('watch_dog')
        logger.error(e)
Example #30
0
def del_imgs():
    cid = request.get_json().get('cid')
    ids = request.get_json().get('ids')
    state = OPER_INVALID
    ids = tuple(ids.split(","))
    if ids is not None and ids != '':
        session = Session()
        try:
            #delete image file first
            imgs = session.query(Imagelib).filter(Imagelib.id.in_(ids)).all()
            hasthumbnail = remove_files(imgs)

            print '#################', ids
            #delete imagelib record
            session.query(Imagelib).filter(
                Imagelib.id.in_(ids)).delete(synchronize_session=False)

            if not hasthumbnail:
                relist = session.query(Imagelib).filter(
                    Imagelib.collection_id == cid).all()
                if len(relist) > 0:
                    session.query(Imagelib).filter(Imagelib.id == relist[0].id) \
                        .update({Imagelib.type:'THUMBNAIL'})
                    src_path = UPLOAD_IAMGE_ROOT_PATH + relist[0].image_url
                    params = [
                        {
                            'size': (200, 150),
                            'dst_path': UPLOAD_IMAGE_THUMBNAIL_PATH
                        },
                    ]
                    make_thumbnail(src_path, params)
            session.commit()

            state = OPER_SUCCESS
        except Exception, e:
            print e
            logger = logging.getLogger('watch_dog')
            logger.error(e)
            state = OPER_EXCEPTION
        finally: