def board_edit(idx): if request.method == "GET": board = mongo.db.board data = board.find_one({"_id": ObjectId(idx)}) if data is None: flash("해당 게시물이 존재하지 않습니다.") return redirect(url_for("board.lists")) else: if session.get("id") == data.get("writer_id"): return render_template("edit.html", data=data, title="글 수정") else: flash("글 수정 권한이 없습니다.") return redirect(url_for("board.lists")) else: title = request.form.get("title") contents = request.form.get("contents") board = mongo.db.board data = board.find_one({"_id": ObjectId(idx)}) if data.get("writer_id") == session.get("id"): board.update_one({"_id": ObjectId(idx)}, { "$set": { "title": title, "contents": contents, } }) flash("수정되었습니다.") return redirect(url_for("board.board_view", idx=idx)) else: flash("글 수정 권한이 없습니다.") return redirect(url_for("board.lists"))
def board_write(): if session["id"] is None or session["id"] == "": return redirect(url_for("board.member_login")) if request.method == "POST": #name = request.form.get("name") writer_id = session.get("id") title = request.form.get("title") contents = request.form.get("contents") current_utc_time = round(datetime.utcnow().timestamp() * 1000) board = mongo.db.board post = { "writer_id": writer_id, "name": session["name"], "title": title, "contents": contents, "view": 0, "pubdate": current_utc_time, } x = board.insert_one(post) return redirect(url_for("board.board_view", idx=x.inserted_id)) else: return render_template("write.html", name=session["name"], title="글 작성")
def board_delete(idx): board = mongo.db.board data = board.find_one({"_id": ObjectId(idx)}) if data.get("writer_id") == session.get("id"): board.delete_one({"_id": ObjectId(idx)}) flash("삭제 되었습니다.") else: flash("글 삭제 권한이 없습니다.") return redirect(url_for("board.lists"))
def decorated_function(*args, **kwargs): if session.get("id") is None or session.get("id") == "": flash("로그인 후 사용 가능한 기능입니다.") return redirect( url_for("member.member_login", next_url=request.url)) return f(*args, **kwargs)
def decorated_fucntion(*args, **kwargs): if session.get("id") is None or session.get("id") == "": return redirect( url_for("member.member_login", next_url=request.url) ) # next_url : 이 데코레이터가 호출된 페이지의 url을 의미 return f(*args, **kwargs)
def decorated_function(*args, **kwargs): if session.get("id") is None or session.get("id") == "": return redirect(url_for("member.member_login", next_url=request.url)) # 현재 페이지 url저장 return f(*args, **kwargs)