예제 #1
0
def note_store():
    form = NoteCreateForm(request.form)
    if form.validate():
        note = Note()
        note.create(data=form.data)
        return Success(message="操作成功!")
    return Fail(message=form.first_error)
예제 #2
0
def permission_store():
    form = PermissionCreateForm(request.form)
    if form.validate():
        permission = Permission()
        permission.create(data=form.data)
        return Success(message="操作成功!")
    return Fail(message=form.first_error)
예제 #3
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)
예제 #4
0
def menu_store():
    form = MenuCreateForm(request.form)
    if form.validate():
        menu = Menu()
        menu.create(data=form.data)
        return Success(message="操作成功!")
    return Fail(message=form.first_error)
예제 #5
0
def document_store():
    form = DocumentCreateForm(request.form)
    if form.validate():
        document = Document()
        document.create(data=form.data)
        return Success(message="操作成功!")
    return Fail(message=form.first_error)
예제 #6
0
def role_store():
    form = RoleCreateForm(request.form)
    if form.validate():
        role = Role()
        role.create(data=form.data)
        return Success(message="操作成功!")
    return Fail(message=form.first_error)
예제 #7
0
def link_store():
    form = LinkCreateForm(request.form)
    if form.validate():
        link = Link()
        link.create(data=form.data)
        return Success(message="操作成功!")
    return Fail(message=form.first_error)
예제 #8
0
def admin_store():
    form = AdminCreateForm(request.form)
    if form.validate():
        admin = Admin()
        admin.create(data=form.data)
        return Success(message="操作成功!")
    return Fail(message=form.first_error)
예제 #9
0
def focus_store():
    form = FocusCreateForm(request.form)
    if form.validate():
        focus = Focus()
        focus.create(data=form.data)
        return Success(message="操作成功!")
    return Fail(message=form.first_error)
예제 #10
0
def admin_delete(ids):
    ids = ids.split('-')
    if '1' in ids:
        return Fail(message="网站创始人不能删除")
    admins = Admin.get_all_in_ids(ids=ids)
    for admin in admins:
        admin.destroy()
    return Success(message="成功删除")
예제 #11
0
def role_delete(ids):
    ids = ids.split('-')
    if '1' in ids:
        return Fail(message="不能删除超级管理员角色")
    roles = Role.get_all_in_ids(ids=ids)
    for role in roles:
        role.destroy()
    return Success(message="成功删除")
예제 #12
0
def upload_attach():
    upload_type = request.form.get('file_type', 'attach')
    upload = Upload(upload_type=upload_type)
    upload.upload()
    info = upload.info()
    if info['state'] == "SUCCESS":
        return Success(data=info)
    else:
        return Fail(message=info['state'])
예제 #13
0
def upload_avatar():
    upload_type = request.form.get('file_type', 'images')
    upload = Upload(upload_type=upload_type)
    upload.upload()
    info = upload.info()
    if info['state'] == "SUCCESS":
        # if upload_type == 'images':
        #     Images(old_file_name=info['filename']).clip(dst_w=100, dst_h=100).thumb(width=250, height=250).save()
        return Success(data=info)
    else:
        return Fail(message=info['state'])
예제 #14
0
def admin_profile():
    form = AdminProfileForm(request.form)
    if request.method == "POST":
        if form.validate():
            user = current_user
            with db.auto_commit():
                user.set_attrs(form.data)
            return Success(message="操作成功!")
        return Fail(message=form.first_error)
    else:
        roles = Role.get_all()
        return render_template('admin/admin/profile.html', roles=roles)
예제 #15
0
def upload_thumb():
    upload_type = request.form.get('file_type', 'images')
    upload = Upload(upload_type=upload_type)
    upload.upload()
    info = upload.info()
    if info['state'] == "SUCCESS":
        if upload_type == 'images':
            Images(old_file_name=info['filename']).thumb(width=640,
                                                         height=480).save()
        return Success(data=info)
    else:
        return Fail(message=info['state'])
예제 #16
0
def link_update(id):
    edit_one_field = request.form.get('edit_one_field', None)
    if not edit_one_field:
        form = LinkEditForm(formdata=request.form, id=id)
    else:
        form = LinkEditOneKeyForm(formdata=request.form, id=id)
    if not form.validate():
        return Fail(message=form.first_error)
    link = Link.get_by_id(id=id)
    link.update(form.data, edit_one_field)

    return Success(message="操作成功!")
예제 #17
0
def admin_system():
    form = SystemForm(request.form)
    if request.method == "POST":
        if form.validate():
            system = System.query.first()
            system.update(form.data)
            write_ini_file('system', form.data)
            return Success(message="操作成功!")
        return Fail(message=form.first_error)
    else:
        system = System.query.first()
        return render_template('admin/system/index.html', system=system)
예제 #18
0
def permission_update(id):
    edit_one_field = request.form.get('edit_one_field', None)
    if not edit_one_field:
        form = PermissionEditForm(formdata=request.form, id=id)
    else:
        form = PermissionEditOneKeyForm(formdata=request.form, id=id)
    if not form.validate():
        return Fail(message=form.first_error)
    permission = Permission.get_by_id(id=id)
    permission.update(form.data, edit_one_field)

    return Success(message="操作成功!")
예제 #19
0
def admin_mail():
    form = MailForm(request.form)

    if request.method == "POST":
        if form.validate():
            mail = Mail.query.first()
            mail.update(form.data)
            write_ini_file('mail', form.data)
            return Success(message="操作成功!")
        return Fail(message=form.first_error)
    else:

        mail = Mail.query.first()
        return render_template('admin/mail/index.html', mail=mail)
예제 #20
0
def admin_edit_avatar():
    if request.method == "POST":

        form = AdminAvatarForm(request.form)
        if form.validate():
            user = current_user
            with db.auto_commit():
                user.set_attrs(form.data)
            return Success(message="操作成功!")
        return Fail(message=form.first_error)
    else:
        user = current_user
        avatar = user.avatar
        return render_template('admin/admin/avatar.html', avatar=avatar)
예제 #21
0
def upload_file():
    action = request.form.get('action', 'chunk_upload')
    upload_type = request.form.get('file_type', None)
    promise = {
        'chunk_upload': __chunk_upload,
        'md5check': __md5check,
        'chunk': __chunk,
        'merge': __merge,
    }
    info = promise[action]()
    if info['state'] == "SUCCESS":
        if action == 'merge' and upload_type == "images":
            image = Images(old_file_name=info['filename'])
            image.clip(dst_w=100, dst_h=100).thumb(width=250,
                                                   height=250).save()
        return Success(data=info)
    else:
        return Fail(message=info['state'])
예제 #22
0
def admin_edit_password():
    """
    修改密码
    :return:
    """
    form = AdminPasswordForm(request.form)
    if request.method == "POST":
        if form.validate():
            user = current_user
            if not user.check_password(form.oldpassword.data):
                return Fail(message="原始密码错误!")
            if form.oldpassword.data == form.password.data:
                return Fail(message="新旧密码必须不一样!")
            with db.auto_commit():
                user.set_password(form.password.data)
            return Success(message="操作成功!")

        return Fail(message=form.first_error)
    else:
        return render_template('admin/admin/password.html')
예제 #23
0
def link_delete(ids):
    ids = ids.split('-')
    links = Link.get_all_in_ids(ids=ids)
    for link in links:
        link.destroy()
    return Success(message="成功删除")
예제 #24
0
def tag_delete(ids):
    ids = ids.split('-')
    tags = Tag.get_all_in_ids(ids=ids)
    for tag in tags:
        tag.destroy()
    return Success(message="成功删除")
예제 #25
0
def document_delete(ids):
    ids = ids.split('-')
    documentes = Document.get_all_in_ids(ids=ids)
    for document in documentes:
        document.destroy()
    return Success(message="成功删除")
예제 #26
0
def menu_delete(ids):
    ids = ids.split('-')
    menus = Menu.get_all_in_ids(ids=ids)
    for menu in menus:
        menu.destroy()
    return Success(message="成功删除")
예제 #27
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="成功删除")
예제 #28
0
def focus_delete(ids):
    ids = ids.split('-')
    focuses = Focus.get_all_in_ids(ids=ids)
    for focus in focuses:
        focus.destroy()
    return Success(message="成功删除")
예제 #29
0
def permission_delete(ids):
    ids = ids.split('-')
    permissions = Permission.get_all_in_ids(ids=ids)
    for permission in permissions:
        permission.destroy()
    return Success(message="成功删除")
예제 #30
0
def note_delete(ids):
    ids = ids.split('-')
    notes = Note.get_all_in_ids(ids=ids)
    for note in notes:
        note.destroy()
    return Success(message="成功删除")