def publicsettingdelete(): if request.method == 'GET': change_cate = str(request.args.get('abbname', '')) if change_cate == '': flash(u"未输入分类缩略名,请正确操作") return redirect( url_for('sign_module.setting_function', setcate="publicsetting")) if not NoteCate.objects( abbname=change_cate, belong=User.objects( email=session['user']['email']).first()).count() == 1: flash(u"分类缩略名有误,请正确操作") return redirect( url_for('sign_module.setting_function', setcate="publicsetting")) this_user_cate = NoteCate.objects( abbname=change_cate, belong=User.objects( email=session['user']['email']).first()).first() other_user_cate = NoteCate.objects( abbname__ne=change_cate, belong=User.objects( email=session['user']['email']).first()).first() all_this_cate_note = Note.objects( public_status=NOTECONSTANTS.PUBLIC, public_cate=this_user_cate, belong=User.objects(email=session['user']['email']).first()) if other_user_cate is None: for one_note in all_this_cate_note: one_note.public_status = NOTECONSTANTS.PRIVATE one_note.public_cate = None one_note.save() flash(u"分类已删除,因无其他公开分类,该分类下的笔记全部迁移为私有笔记") else: for one_note in all_this_cate_note: one_note.public_cate = other_user_cate one_note.save() flash(u"分类已删除,原分类笔记已迁移至 " + other_user_cate.name) NoteCate.delete(this_user_cate) return redirect( url_for('sign_module.setting_function', setcate="publicsetting")) else: flash(u"非法操作。") return redirect( url_for('sign_module.setting_function', setcate="publicsetting"))
def publicsettingdelete(): if request.method == 'GET': change_cate = str(request.args.get('abbname', '')) if change_cate == '': flash(u"未输入分类缩略名,请正确操作") return redirect(url_for('sign_module.setting_function', setcate="publicsetting")) if not NoteCate.objects(abbname=change_cate, belong=User.objects(email=session['user']['email']).first()).count() == 1: flash(u"分类缩略名有误,请正确操作") return redirect(url_for('sign_module.setting_function', setcate="publicsetting")) this_user_cate = NoteCate.objects( abbname=change_cate, belong=User.objects(email=session['user']['email']).first() ).first() other_user_cate = NoteCate.objects(abbname__ne=change_cate, belong=User.objects(email=session['user']['email']).first()).first() all_this_cate_note = Note.objects(public_status=NOTECONSTANTS.PUBLIC, public_cate=this_user_cate, belong=User.objects(email=session['user']['email']).first()) if other_user_cate is None: for one_note in all_this_cate_note: one_note.public_status = NOTECONSTANTS.PRIVATE one_note.public_cate = None one_note.save() flash(u"分类已删除,因无其他公开分类,该分类下的笔记全部迁移为私有笔记") else: for one_note in all_this_cate_note: one_note.public_cate = other_user_cate one_note.save() flash(u"分类已删除,原分类笔记已迁移至 "+other_user_cate.name) NoteCate.delete(this_user_cate) return redirect(url_for('sign_module.setting_function', setcate="publicsetting")) else: flash(u"非法操作。") return redirect(url_for('sign_module.setting_function', setcate="publicsetting"))
def note_function(): all_note = Note.objects() return render_template('admin/note.html', all_note=all_note)