Exemple #1
0
def guestbook_store():
    form = GuestbookCreateForm(request.form)
    if form.validate():
        guestbook = Guestbook()
        guestbook.create(data=form.data)
        return Success(message="操作成功!")
    return Fail(message=form.first_error)
Exemple #2
0
def guestbook_lists():
    id = request.args.get('id', None)

    if id:
        guestbook = Guestbook.get_by_id(id)
        if guestbook.root_id == 0:
            total, result = Guestbook.get_list_all_by_id(id)
        else:
            total, result = Guestbook.get_list_all_by_id(id)
    else:
        total, result = Guestbook.get_limit_all()
    return AjaxResponse(data=result, count=total)
Exemple #3
0
 def validate_root_id(self, field):
     if not field.data:
         raise ValidationError("参数错误!")
     arr = field.data.split('-')
     pid = arr.pop()
     guestbook = Guestbook.get_by_id(pid)
     if not guestbook:
         raise ValidationError("参数错误!")
     if len(arr) == 0:
         raise ValidationError("参数错误!")
     root_id = "-".join(arr)
     guestbook = Guestbook.get_by_root_id(root_id)
     if not guestbook:
         raise ValidationError("参数错误!")
Exemple #4
0
def guestbook_update(id):
    edit_one_field = request.form.get('edit_one_field', None)
    if not edit_one_field:
        form = GuestbookEditForm(formdata=request.form, id=id)
    else:
        form = GuestbookEditOneKeyForm(formdata=request.form, id=id)
    if not form.validate():
        return Fail(message=form.first_error)
    guestbook = Guestbook.get_by_id(id=id)
    guestbook.update(form.data, edit_one_field)

    return Success(message="操作成功!")
Exemple #5
0
def guestbook_delete(ids):
    ids = ids.split('-')
    guestbooks = Guestbook.get_all_in_ids(ids=ids)
    for guestbook in guestbooks:
        guestbook.destroy()
    return Success(message="成功删除")
Exemple #6
0
def guestbook_edit(id):
    guestbook = Guestbook.get_by_id(id)
    return render_template('admin/guestbook/edit.html', guestbook=guestbook)
Exemple #7
0
def guestbook_create(id):
    guestbook = Guestbook.get_by_id(id)
    pid = id
    return render_template('admin/guestbook/create.html', guestbook=guestbook, pid=pid)
Exemple #8
0
 def validate_pid(self, field):
     if field.data:
         guestbook = Guestbook.get_by_id(field.data)
         if guestbook.user_id == current_user.id:
             raise ValidationError("您不能回复您自己!")