def applyLink(request): if request.method == "POST" and request.POST: # 如果是POST,接收用户输入 link_form = LinkForm(request.POST) # 表单验证 if link_form.is_valid(): link_form.save() return HttpResponse("申请成功,请稍后我将尽快审核") else: link_form = LinkForm() locs = { "link_form": link_form, } return render(request, 'blog/LinkApply.html', locs)
def new_link(): form = LinkForm() if form.validate_on_submit(): name = form.name.data url = form.url.data link = Link(name=name, url=url) db.session.add(link) db.session.commit() flash('Link created.', 'success') return redirect(url_for('.manage_link')) return render_template('admin/new_link.html', form=form)
def admin_add_link(request): if users.is_current_user_admin(): if request.method == 'GET': form = LinkForm() elif request.method == 'POST': form = LinkForm(request.POST) if form.is_valid(): link = form.save() link.put() return HttpResponseRedirect('/admin') return render_to_response('admin/edit.html', dictionary={ 'form': form, 'type': 'Add Link', }, context_instance=RequestContext(request)) else: return HttpResponseRedirect('/')
def edit_link(link_id): form = LinkForm() link = Link.query.get_or_404(link_id) if form.validate_on_submit(): link.name = form.name.data link.url = form.url.data db.session.commit() flash('Link updated.', 'success') return redirect(url_for('.manage_link')) form.name.data = link.name form.url.data = link.url return render_template('admin/edit_link.html', form=form)
def new_link(): form = LinkForm() if form.validate_on_submit(): name = form.name.data url = form.url.data if Link.query.filter_by(name=name).count() == 1: flash("链接已存在!", "err") link = Link(name=name, url=url) db.session.add(link) db.session.commit() flash('添加链接成功!', 'ok') oplog = Oplog( user='******', ip=request.remote_addr, reason="新增链接-%s" % form.name.data, ) db.session.add(oplog) db.session.commit() return redirect(url_for("admin.new_link")) return render_template('admin/new_link.html', form=form)
def edit_link(link_id=None): if page_data is None or page_data.pages == 1: page = 1 else: page = page_data.page if page_data.page < page_data.pages or page_data.total % page_data.per_page != 1 else page_data.pages - 1 form = LinkForm() link = Link.query.get_or_404(link_id) if form.validate_on_submit(): link.name = form.name.data link.url = form.url.data db.session.commit() flash("编辑链接成功", "ok") oplog = Oplog( user='******', ip=request.remote_addr, reason="修改链接:'%s'为'%s'" % (link.name, form.name.data), ) db.session.add(oplog) db.session.commit() return redirect(url_for('admin.link_list', page=page)) form.name.data = link.name form.url.data = link.url return render_template('admin/edit_link.html', form=form)