def on_list(self, request): res = {'error': 1} if request.method == 'GET': keyword = request.args.get('keyword') user_id = request.args.get('user_id') page = cvtools.num(request.args.get('page')) per_page = cvtools.num(request.args.get('per_page')) images, count = cvtools.get_list(keyword, user_id, None, "i.created_at DESC", page, per_page) result = [] for img in images: temp = {} temp['ar_id'] = img['id'] temp['src_img'] = cvtools.get_abs_url(conf.UPLOAD_DIR_SRC[1:], img['src_name']) temp['target_type'] = img['target_type'] if temp['target_type'] == conf.TAR_TYPE_IMAGE: temp['target'] = cvtools.get_abs_url(conf.UPLOAD_DIR_TAR_IMG[1:], img['target']) elif temp['target_type'] == conf.TAR_TYPE_VIDEO: temp['target'] = cvtools.get_abs_url(conf.UPLOAD_DIR_TAR_VIDEO[1:], img['target']) else: temp['target'] = img['target'] temp['title'] = img['title'] temp['user'] = img['username'] temp['created_at'] = img['created_at'].isoformat() result.append(temp) res['error'] = 0 res['result'] = result res['total'] = count else: res['error_msg'] = 'request is not GET' response_str = json.dumps([res]) return Response(response_str, mimetype='application/json')
def on_admin_list(self, request, page): if request.cookies.get('cookie_name') is None or request.cookies.get('cookie_name') == '': return redirect('/') sid = request.cookies.get('cookie_name') keyword = request.args.get('keyword') # My changes start here user = request.cookies.get('cookie_user') if keyword is None: keyword = "" option = request.args.get('option') action = request.args.get('action') search_page = request.args.get('page') types = ['', '', '', '', '', ''] if request.args.get('type-image') is not None: types[1] = int(request.args.get('type-image')) else: types[1] = conf.TAR_TYPE_NOTYPE if request.args.get('type-video') is not None: types[2] = int(request.args.get('type-video')) else: types[2] = conf.TAR_TYPE_NOTYPE if request.args.get('type-url') is not None: types[3] = int(request.args.get('type-url')) else: types[3] = conf.TAR_TYPE_NOTYPE if request.args.get('type-youtube') is not None: types[4] = int(request.args.get('type-youtube')) else: types[4] = conf.TAR_TYPE_NOTYPE if request.args.get('type-model') is not None: types[5] = int(request.args.get('type-model')) else: types[5] = conf.TAR_TYPE_NOTYPE if action == "Signout": response = redirect('/') response.set_cookie('cookie_name', '') return response search = request.args.get('search') # My changes end here if search is not None: if search_page is not None: page = int(search_page) else: page = cvtools.num(page) else: page = cvtools.num(page) per_page = 10 # My changes start here if option == "type": images, count = cvtools.get_list_type(keyword, None, None, 'i.created_at DESC, i.pinned DESC', page, per_page, types) elif option == "user": images, count = cvtools.get_list_user(keyword, None, None, 'i.created_at DESC, i.pinned DESC', page, per_page, types) else: images, count = cvtools.get_list(keyword, None, None, 'i.created_at DESC, i.pinned DESC', page, per_page, types) # My changes end here if not images and page != 1: return self.error_404() pagination = pg.Pagination(page, per_page, count) return self.render_template('admin_list.html', page="admin_list", error=None, images=images, pagination=pagination, keyword=keyword, count=count, option=option, selected='true', types=types, search=search, sid=sid, user=user, abs_url=cvtools.get_abs_url, url_for=url_for, conf=conf)