def article(nav_id=None, id=None): rule = str(request.path) if id == None or nav_id == None: return redirect(url_for('home.index')) #如果在详情页搜索 if ('search' in request.args) and (request.args['search']): search = request.args['search'] return redirect(url_for('home.articles', nav_id=nav_id, search=search)) #获取产品的详细信息 article_detail = Crud.get_data_by_id(Article, id) #如果点击量为None,赋值0 if not article_detail.click: article_detail.click = 0 #如果有缓存的点击量,更新点击量 if rule in CLICKS_COUNT: article_detail.click = int(article_detail.click) + int( CLICKS_COUNT[rule]) else: article_detail.click = int(article_detail.click) + 1 Crud.easy_update(article_detail) # 如果进行了非法操作 if article_detail.column_id != nav_id: return redirect(url_for('home.index')) #获取标签作为关键词 keywords = ','.join([v.name for v in article_detail.tags]) #SEO信息 seo_data.keywords = keywords seo_data.description = article_detail.description seo_data.title = article_detail.title return render_template( "home/article.html", article_data=article_detail, seo_data=seo_data, )
def admin_reset(): getdata = request.args data = Crud.get_data_by_id(Admin, getdata['id']) data.password = "******" result = Crud.easy_update(data) if result: op_log("重置密码") return {"code": 1, "msg": "重置密码成功!"} return {"code": 0, "msg": '重置失败,系统错误'}
def product(nav_id=None, id=None): rule = str(request.path) if id == None or nav_id == None: return redirect(url_for('home.index')) #如果在详情页搜索 if ('search' in request.args) and (request.args['search']): search = request.args['search'] return redirect(url_for('home.products', nav_id=nav_id, search=search)) #获取产品的详细信息 product_detail = Crud.get_data_by_id(Product, id) #如果点击量为None,赋值0 if not product_detail.click: product_detail.click = 0 #如果有缓存的点击量,更新点击量 if rule in CLICKS_COUNT: product_detail.click = int(product_detail.click) + int( CLICKS_COUNT[rule]) else: product_detail.click = int(product_detail.click) + 1 Crud.easy_update(product_detail) # 如果进行了非法操作 if product_detail.column_id != nav_id: return redirect(url_for('home.index')) #获取相识产品,用途和分类一致的产品 similar_products = Crud.search_data( Product, and_(Product.column_id == product_detail.column_id, Product.relation_id == product_detail.relation_id), Product.sort.desc(), 9) #获取标签作为关键词 keywords = ','.join([v.name for v in product_detail.tags]) #获取图集 pictures = product_detail.pictures.split(',') product_data = object_to_dict(product_detail) product_data['pictures'] = pictures #SEO信息 seo_data.keywords = keywords seo_data.description = product_detail.description seo_data.title = product_detail.title return render_template("home/product.html", product_data=product_data, seo_data=seo_data, similar_products=similar_products)
def change_pwd(): data = request.form form = ChangepwdForm(data) if form.validate(): if current_user.check_pwd(data['old_pwd']): current_user.password = data['password'] result = Crud.easy_update(current_user) if result: op_log("修改密码%s" % current_user.username) return {"code": 1, "msg": "修改密码成功"} return {"code": 0, "msg": "修改密码失败,系统错误"} return {"code": 0, "msg": "原密码错误!"} return {"code": 0, "msg": form.get_errors()}
def webconfig(): data = Crud.get_data(Conf, Conf.sort.desc()) if request.method == 'GET': return render_template("admin/conf/webconfig.html") elif request.method == 'POST': form_data = request.form for v in data: v.default_value = form_data[v.ename] result = Crud.easy_update(data) if result: op_log("修改配置") return {"code":1, "msg": '保存成功'} return {"code":0, "msg": '保存失败,系统错误'}