def delete_siteall(request): mysql_conn = mysql_options.mysql_init() ids = request.GET['del_ids'] # print ids myid = [] flag = False if "username" in request.session: username = request.session['username'] flag = True if flag: if ids: ids = ids.split(',') # print ids result = mysql_options.delete_site_by_id(mysql_conn, ids) site_list = mysql_options.get_site_info(mysql_conn) for list in site_list: myid.append(list[0]) if result: mymessage = "<script>alert('删除成功!')</script>" return render( request, 'site_management.html', { 'message': mymessage, 'flag': flag, 'site_list': site_list, 'myid': myid }) else: mymessage = "<script>alert('删除失败!')</script>" return render( request, 'site_management.html', { 'message': mymessage, 'flag': flag, 'site_list': site_list, 'myid': myid }) else: site_list = mysql_options.get_site_info(mysql_conn) for list in site_list: myid.append(list[0]) mymessage = "<script>alert('请选择一个站点删除!')</script>" return render( request, 'site_management.html', { 'message': mymessage, 'flag': flag, 'site_list': site_list, 'myid': myid }) else: return render(request, 'spiders_management.html', {'flag': flag})
def do_add_site(request): name = request.GET['name'] url = request.GET['start_urls'] rule = request.GET['extract_from'] mysql_conn = mysql_options.mysql_init() result = mysql_options.add_site(mysql_conn, name, url, rule) if "username" in request.session: username = request.session['username'] flag = True if flag: myid = [] site_list = mysql_options.get_site_info(mysql_conn) for list in site_list: myid.append(list[0]) if result: addMessage = "<script>alert('添加成功!')</script>" return render( request, 'site_management.html', { 'message': addMessage, 'flag': flag, 'site_list': site_list, 'myid': myid }) else: addMessage = "<script>alert('添加失败!')</script>" return render( request, 'site_management.html', { 'message': addMessage, 'flag': flag, 'site_list': site_list, 'myid': myid }) else: return render(request, 'spiders_management.html', {'flag': flag})
def site_management(request): mysql_conn = mysql_options.mysql_init() flag = False myid = [] if "username" in request.session: username = request.session['username'] flag = True if flag: site_list = mysql_options.get_site_info(mysql_conn) for list in site_list: myid.append(list[0]) return render( request, 'site_management.html', { 'login_user': username, 'flag': flag, 'site_list': site_list, 'myid': myid }) # return render(request, 'site_management.html', {'login_user': username, 'flag': flag}) else: return render(request, 'site_management.html', {'flag': flag})
def do_update(request): mysql_conn = mysql_options.mysql_init() myid = request.GET['site_id'] name = request.GET['name'] url = request.GET['start_urls'] rule = request.GET['extract_from'] # print myid,name,url,rule result = mysql_options.update_site_info(mysql_conn, myid, name, url, rule) print result flag = False if "username" in request.session: username = request.session['username'] flag = True if flag: myid = [] site_list = mysql_options.get_site_info(mysql_conn) for list in site_list: myid.append(list[0]) if result: updatemessage = "<script>alert('修改成功!')</script>" return render( request, 'site_management.html', { 'message': updatemessage, 'flag': flag, 'site_list': site_list, 'myid': myid }) else: updatemessage = "<script>alert('修改失败!')</script>" return render( request, 'site_management.html', { 'message': updatemessage, 'flag': flag, 'site_list': site_list, 'myid': myid }) else: return render(request, 'spiders_management.html', {'flag': flag})