def _get_my_ip_list_by_page(uid, allot_num, verify_result): page_index, page_size = get_page_info() if not allot_num or allot_num == 0: page = Page(0, page_index, page_size) return [], page.to_dict() args = [allot_num, uid] join = 'as a left join %s as b on a.objectId = b.objectId and a.verifyType = b.verifyType' % ( IPVerify.__table__, ) where = '%s where a.allotNum = ? and b.adminId = ?' % (join, ) if verify_result: args.append(verify_result) where = '%s and a.verifyResult = ?' % (where, ) total = IPSamplingVerify.count_by_field(where, 'a.id', *args) page = Page(total, page_index, page_size) where = '%s order by a.updateAt limit ?,?' % (where, ) args.append(page.offset) args.append(page.limit) lists = IPSamplingVerify.select_by( where, args, ['a.*, b.verifyResult as ipVerifyResult']) IPPool.join_by(lists, 'objectId', 'objectId') return lists, page.to_dict()
def _get_blacklist_by_page(title, status, order): page_index, page_size = get_page_info() if title: args = ['%' + title + '%'] where = 'where `title` like ?' else: args = [status] where = 'where status = ?' total = IPBlacklist.count_by(where, *args) page = Page(total, page_index, page_size) if status < 3: order_field = 'updateAt ASC' else: order_field = 'blacklistUpdateAt DESC' where = '%s order by %s limit ?,?' % (where, order_field) args.append(page.offset) args.append(page.limit) lists = IPBlacklist.find_by(where, *args) if status > 1: RMS.join_by(lists, 'packagerId', 'uid') IP.join_by(lists, 'id', 'id') IPStatis.join_by(lists, 'id', 'ipId') return lists, page.to_dict()
def _get_list_by_page(verify_type='0', status=None, has_outline=None, title=None, order='0'): page_index, page_size = get_page_info() if title: args = ['%' + title + '%'] where = 'where `title` like ? and discard = 0' elif status and has_outline: args = [verify_type, status, has_outline] where = 'where `verifyType` = ? and `status` = ? and `hasOutline` = ? and discard = 0' elif status: args = [verify_type, status] where = 'where `verifyType` = ? and `status` = ? and discard = 0' else: args = [verify_type] where = 'where `verifyType` = ? and discard = 0 and status != -1' total = IPPool.count_by(where, *args) page = Page(total, page_index, page_size) if order == '0': where = '%s order by createAt DESC limit ?,?' % (where, ) else: where = '%s order by updateAt DESC limit ?,?' % (where, ) args.append(page.offset) args.append(page.limit) lists = IPPool.find_by(where, *args) return lists, page.to_dict()
def _get_package_list_by_page(title, status, order): page_index, page_size = get_page_info() args = [ctx.request.user.uid] where = "where packagerId = ?" if title: args.append('%' + title + '%') where = '%s and status > 1 and `title` like ? ' % (where, ) else: args.append(status) where = '%s and status = ?' % (where, ) total = IPBlacklist.count_by(where, *args) page = Page(total, page_index, page_size) if order == 0: order_by = 'DESC' else: order_by = 'ASC' where = '%s order by updateAt %s limit ?,?' % (where, order_by) args.append(page.offset) args.append(page.limit) lists = IPBlacklist.find_by(where, *args) IP.join_by(lists, 'id', 'id') return lists, page.to_dict()
def _get_list(api_url): pn = int(ctx.request.get('pn', 1)) rn = int(ctx.request.get('rn', 10)) list_type = ctx.request.get('type', 'open') list_api = _API_HOST + api_url + '?listType=%s&pn=%d&rn=%d&token=%s' % ( list_type, pn - 1, rn, ctx.request.cookies.get('leancloud-token')) res_data = urllib2.urlopen(list_api) res = res_data.read() res_data.close() data = json.loads(res) if data['code'] != 0: error_code = ERROR_CODE['data_exception_error'] raise APIError(error_code, ERROR_MESSAGE[error_code], {}) page = Page(data['count'], pn, rn) params = { 'type': list_type, 'apiHost': _API_HOST, 'token': ctx.request.cookies.get('leancloud-token') } return dict(data=data['data'], page=page.to_dict(), param=params, user=ctx.request.user)
def _get_users_by_page(crm=None, mobile=None): page_index, page_size = get_page_info() where, args = None, [] if crm and mobile: args = ['%' + crm + '%', mobile] where = 'where `crm` like ? and `mobile` = ?' elif crm and not mobile: args = ['%' + crm + '%'] where = 'where `crm` like ?' elif not crm and mobile: args = [mobile] where = 'where `mobile` = ?' else: where = 'where length(crm) > 0' if not where: total = RMS.count_all() else: total = RMS.count_by(where, *args) page = Page(total, page_index, page_size) args.append(page.offset) args.append(page.limit) where = '%s order by id desc limit ?,?' % (where,) users = RMS.find_by(where, *args) IpPoolAdmin.join_by(users, 'uid', 'uid') _format_data(users) return users, page.to_dict()
def _get_verify_list(status=None): page_index, page_size = get_page_info() join = 'as a left join %s as b on a.newWriterId = b.id' % ( NewWriterPool.__table__, ) args = [ctx.request.user.uid] where = '%s where a.uid = ? and a.status != 1' % (join, ) count_where = 'where uid = ? and status != 1' if status is not None: args.append(status) where = '%s and a.status = ?' % (where, ) count_where = '%s and status = ?' % (count_where, ) total = NewWriterVerifyRecord.count_by(count_where, *args) page = Page(total, page_index, page_size) where = '%s order by a.updateAt DESC limit ?,?' % (where, ) args.append(page.offset) args.append(page.limit) lists = NewWriterVerifyRecord.select_by(where, args, [ 'a.*', 'b.phone', 'b.ippreId', 'b.uid as userId', 'b.verifyType', 'b.verifyResult' ]) IPPool.join_by(lists, 'ippreId', 'ippreId') User.join_by(lists, 'userId', 'id') return lists, page.to_dict()
def api_get_users(): total = Users.count_all() page = Page(total, _get_page_index()) users = Users.find_by('order by created_at desc limit ?,?', page.offset, page.limit) for u in users: u.password = '******' return dict(users=users, page=page.to_dict())
def _get_allot_user_by_page(allot_num): page_index, page_size = get_page_info() if not allot_num or allot_num == 0: page = Page(0, page_index, page_size) return [], page.to_dict() args = [allot_num] where = 'where `allotNum` = ?' total = IPSamplingAllot.count_by(where, *args) page = Page(total, page_index, page_size) where = '%s order by accuracy DESC limit ?,?' % (where, ) args.append(page.offset) args.append(page.limit) lists = IPSamplingAllot.find_by(where, *args) RMS.join_by(lists, 'owner', 'uid') return lists, page.to_dict()
def _get_list_by_page(list_type='0', status='-1', final_state='-1', title=None, boutique='-1'): page_index, page_size = get_page_info() args = [list_type] where = 'where type = ?' if title: global IPPRE query = IPPRE.query query_res = query.contains('title', title).find() id_list = [] for info in query_res: id_list.append(info.id) args = [] where = "where ippreId in ('%s')" % ("','".join(id_list), ) else: if status != '-1': args.append(status) where = '%s and status = ?' % (where, ) if final_state != '-1': args.append(final_state) where = '%s and finalState = ?' % (where, ) if boutique == '1': where = '%s and ((verifyType = 3 or verifyType = 4) and verifyResult = 1)' % ( where, ) if boutique == '2': where = '%s and ((verifyType = 3 or verifyType = 4) and verifyResult = 2)' % ( where, ) if boutique == '3': where = '%s and ((verifyType = 1 and verifyResult = 1) or ((verifyType = 3 or verifyType = 4) and verifyResult = 0))' % ( where, ) if boutique == '4': where = '%s and verifyType = 1 and verifyResult = 2' % (where, ) total = NewWriterPool.count_by(where, *args) page = Page(total, page_index, page_size) where = '%s order by id DESC limit ?,?' % (where, ) args.append(page.offset) args.append(page.limit) lists = NewWriterPool.find_by(where, *args) IPPool.join_by(lists, 'ippreId', 'ippreId') User.join_by(lists, 'uid', 'id') return lists, page.to_dict()
def _get_excellent_list_by_page(title, order): page_index, page_size = get_page_info() if title: args = ['%' + title + '%'] where = 'where `title` like ? and discard = 0' else: args = [] where = 'where (`verifyType` = 3 or `verifyType` = 4) and discard = 0 and status = 1' total = IPPool.count_by(where, *args) page = Page(total, page_index, page_size) if order == '0': where = '%s order by createAt DESC limit ?,?' % (where, ) else: where = '%s order by updateAt DESC limit ?,?' % (where, ) args.append(page.offset) args.append(page.limit) lists = IPPool.find_by(where, *args) return lists, page.to_dict()
def home(): pn = int(ctx.request.get('pn', 1)) rn = int(ctx.request.get('rn', 10)) list_api = _API_HOST + '/copy/workchecklist?pn=%d&rn=%d&token=%s' % ( pn - 1, rn, ctx.request.cookies.get('leancloud-token')) res_data = urllib2.urlopen(list_api) res = res_data.read() res_data.close() data = json.loads(res) if data['errno'] != 0: error_code = ERROR_CODE['data_exception_error'] raise APIError(error_code, ERROR_MESSAGE[error_code], {}) _format_data(data['data']['list']) page = Page(data['data']['count'], pn, rn) return dict(data=data['data'], page=page.to_dict(), user=ctx.request.user)
def _get_verify_list_by_page(verify_type='1', verify_result=None, title=None): page_index, page_size = get_page_info() join = 'as a left join %s as b on a.objectId = b.objectId' % ( IPPool.__table__, ) if title: args = ['%' + title + '%', ctx.request.user.uid] where = '%s where b.title like ? and a.verifyPerson = ?' % (join, ) elif verify_type == '1': if verify_result: args = [verify_result, ctx.request.user.uid] where = '%s where a.verifyType = 1 and a.verifyResult = ? and a.verifyPerson = ?' % ( join, ) else: args = [verify_type, ctx.request.user.uid] where = '%s where a.verifyType = ? and a.verifyPerson = ?' % ( join, ) elif verify_type == '3': if verify_result: args = [verify_result, ctx.request.user.uid] where = '%s where (a.verifyType = 3 or a.verifyType = 4) and a.verifyResult = ? and a.verifyPerson = ?' % ( join, ) else: args = [ctx.request.user.uid] where = '%s where (a.verifyType = 3 or a.verifyType = 4) and a.verifyPerson = ?' % ( join, ) else: error_code = ERROR_CODE['param_error'] raise APIError(error_code, ERROR_MESSAGE[error_code], {}) total = IPSamplingVerify.count_by_field(where, 'a.id', *args) page = Page(total, page_index, page_size) where = '%s order by updateAt limit ?,?' % (where, ) args.append(page.offset) args.append(page.limit) lists = IPSamplingVerify.select_by(where, args, [ 'a.*', 'b.verifyType as ipPoolType', 'status', 'b.title', 'b.hasOutline', 'b.author', 'b.createAt as publishTime' ]) return lists, page.to_dict()
def _get_list_by_page(verify_type='0', verify_result=None, has_outline=None, title=None, order='0'): page_index, page_size = get_page_info() join = 'as a left join %s as b on a.objectId = b.objectId where b.discard = 0' % ( IPPool.__table__, ) if title: args = ['%' + title + '%', ctx.request.user.uid] where = '%s and b.title like ? and a.adminId = ?' % (join, ) elif verify_result and has_outline: args = [verify_type, verify_result, has_outline, ctx.request.user.uid] where = '%s and a.verifyType = ? and a.verifyResult = ? and b.hasOutline = ? and a.adminId = ?' % ( join, ) elif verify_result: args = [verify_type, verify_result, ctx.request.user.uid] where = '%s and a.verifyType = ? and a.verifyResult = ? and a.adminId = ?' % ( join, ) else: args = [verify_type, ctx.request.user.uid] where = '%s and a.verifyType = ? and a.adminId = ?' % (join, ) total = IPVerify.count_by_field(where, 'a.id', *args) page = Page(total, page_index, page_size) if order == '1': where = '%s order by a.updateAt DESC limit ?,?' % (where, ) else: where = '%s order by b.createAt ASC limit ?,?' % (where, ) args.append(page.offset) args.append(page.limit) lists = IPVerify.select_by(where, args, [ 'a.*', 'b.title', 'b.hasOutline', 'b.author', 'b.createAt as publishTime' ]) return lists, page.to_dict()
def _get_blogs_by_page(): total = Blogs.count_all() page = Page(total, _get_page_index()) blogs = Blogs.find_by('order by created_at desc limit ?,?', page.offset, page.limit) return blogs, page.to_dict()
def api_get_comments(): total = Comments.count_all() page = Page(total, _get_page_index()) comments = Comments.find_by('order by created_at desc limit ?,?', page.offset, page.limit) return dict(comments=comments, page=page.to_dict())