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)
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)
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)
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)
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)
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)
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)
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)
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)
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="成功删除")
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="成功删除")
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'])
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'])
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)
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'])
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="操作成功!")
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)
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="操作成功!")
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)
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)
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'])
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')
def link_delete(ids): ids = ids.split('-') links = Link.get_all_in_ids(ids=ids) for link in links: link.destroy() return Success(message="成功删除")
def tag_delete(ids): ids = ids.split('-') tags = Tag.get_all_in_ids(ids=ids) for tag in tags: tag.destroy() return Success(message="成功删除")
def document_delete(ids): ids = ids.split('-') documentes = Document.get_all_in_ids(ids=ids) for document in documentes: document.destroy() return Success(message="成功删除")
def menu_delete(ids): ids = ids.split('-') menus = Menu.get_all_in_ids(ids=ids) for menu in menus: menu.destroy() return Success(message="成功删除")
def guestbook_delete(ids): ids = ids.split('-') guestbooks = Guestbook.get_all_in_ids(ids=ids) for guestbook in guestbooks: guestbook.destroy() return Success(message="成功删除")
def focus_delete(ids): ids = ids.split('-') focuses = Focus.get_all_in_ids(ids=ids) for focus in focuses: focus.destroy() return Success(message="成功删除")
def permission_delete(ids): ids = ids.split('-') permissions = Permission.get_all_in_ids(ids=ids) for permission in permissions: permission.destroy() return Success(message="成功删除")
def note_delete(ids): ids = ids.split('-') notes = Note.get_all_in_ids(ids=ids) for note in notes: note.destroy() return Success(message="成功删除")