diff --git a/app.py b/app.py
index 4f9ee03..5b5e1cb 100644
--- a/app.py
+++ b/app.py
@@ -41,5 +41,18 @@ def index():
return redirect("/%s/" % perhaps_logged_in_username)
return goto("release")
+
+@app.context_processor
+def _set_global_variable_for_templates():
+ """render_template()에 변수를 넘기지 않고도 사용할 수 있어요!
+
+ Flask의 render_template()는 사실 Jinja2라는 Template Engine을 이용해 제공됩니다.
+ 근데 여기에 전역변수를 선언할 수 있다네요. WOW!
+ """
+ return {
+ "get_logged_in_username": get_logged_in_username(),
+ }
+
+
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0")
diff --git a/nickname.py b/nickname.py
index b3fc7bb..b7ceb67 100644
--- a/nickname.py
+++ b/nickname.py
@@ -33,14 +33,20 @@ def RecommendNickname():
target = request.form['target']
nick = request.form['nick']
if not check_username(target, is_internal=True):
- return '존재하지 않는 유저에게 추천하려고 하였습니다.', 400
+ return render_template(
+ "_error.html",
+ _error__msg='존재하지 않는 유저에게 추천하려고 하였습니다.',
+ ), 400
found = Nickname.query.filter(
Nickname.username == target,
Nickname.nick == nick,
).first()
if found:
- return '이미 해당유저가 사용중인 별명입니다.', 400
+ return render_template(
+ "_error.html",
+ _error__msg='이미 해당유저가 사용중인 별명입니다.',
+ ), 400
new = NickRecom()
new.nick = nick
@@ -72,7 +78,10 @@ def ManageMyNicknames(link):
"""
username = get_logged_in_username()
if not username:
- return '로그인 해주세요!!'
+ return render_template(
+ "_error.html",
+ _error__msg='로그인 해주세요!!',
+ ), 400
found = Nickname.query.filter(
Nickname.username == username,
@@ -91,11 +100,10 @@ def ManageMyNicknames(link):
recomm['idx'].append(nick.idx)
return render_template(
- "profile_manage_nick.html",
- username=username,
- menu='nicknames',
- found=found,
- recomm=recomm,
+ "manager.html",
+ manager__right_html_for_menu="_includes/manager/nicknames.html",
+ manager__nickname__my_nickname_classes=found,
+ manager__nickname__recommended_nicknames_for_me=recomm,
)
@@ -107,7 +115,10 @@ def DelMyNick(idx):
username = get_logged_in_username()
if not found.username == username:
- return 'fuck off', 400
+ return render_template(
+ "_error.html",
+ _error__msg="fuck off",
+ ), 400
db.session.delete(found)
db.session.commit()
@@ -123,7 +134,10 @@ def ManageRecommNick(idx):
username = get_logged_in_username()
if not found_recomm.username == username:
- return 'ㅗㅗ', 400
+ return render_template(
+ "_error.html",
+ _error__msg="ㅗㅗ",
+ ), 400
nick = found_recomm.nick
if request.form.get('use', None):
@@ -156,4 +170,3 @@ def RemoveRecommNick(nick):
).first()
db.session.delete(del_from_Recomm)
db.session.commit()
- return
diff --git a/photo.py b/photo.py
index f7518ec..02134c9 100644
--- a/photo.py
+++ b/photo.py
@@ -26,23 +26,31 @@ def photo_upload(link):
"""
username = get_logged_in_username()
if not username:
- return "로그인이 되어있지 않습니다.", 400
+ return render_template(
+ "_error.html",
+ _error__msg="로그인이 되어있지 않습니다.",
+ ), 400
if not link == username:
- return "자신이 아닙니다!", 400
+ return render_template(
+ "_error.html",
+ _error__msg="자신이 아닙니다!",
+ ), 400
# 파일을 업로드
if request.method == "GET":
return render_template(
- "profile_manage_photo.html",
- username=username,
- menu='photo',
+ "manager.html",
+ manager__right_html_for_menu="_includes/manager/photo.html",
)
# 파일을 업로드 후 저장
else:
file = request.files['upfile']
if not file:
- return "이미지를 업로드하지 않았습니다.", 400
+ return render_template(
+ "_error.html",
+ _error__msg="이미지를 업로드하지 않았습니다.",
+ ), 400
filename = username + os.path.splitext(file.filename)[1]
# 폴더가 없다면 만들어줍니다.
diff --git a/templates/_error.html b/templates/_error.html
new file mode 100644
index 0000000..77c8a80
--- /dev/null
+++ b/templates/_error.html
@@ -0,0 +1,4 @@
+{% extends "_extends/_index.html" %}
+{% block _index__container %}
+ {{ _error__msg }}
+{% endblock %}
diff --git a/templates/_extends/__bootstrap.html b/templates/_extends/__bootstrap.html
new file mode 100644
index 0000000..a213cbd
--- /dev/null
+++ b/templates/_extends/__bootstrap.html
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+{% block __bootstrap__style %}
+{% endblock %}
+
+
+{% block __bootstrap__body %}
+{% endblock %}
+
+
+
+{% block __bootstrap__script %}
+{% endblock %}
+
+
diff --git a/templates/_extends/_index.html b/templates/_extends/_index.html
new file mode 100644
index 0000000..861d271
--- /dev/null
+++ b/templates/_extends/_index.html
@@ -0,0 +1,33 @@
+{% extends "_extends/__bootstrap.html" %}
+{% block __bootstrap__style %}
+
+ {% block _index__style %}
+ {% endblock %}
+{% endblock %}
+{% block __bootstrap__body %}
+ {% include "_includes/top_menu_nav.html" %}
+
+ {% block _index__container %}
+ {% endblock %}
+
+{% endblock %}
+{% block __bootstrap__script %}
+ {% block _index__script %}
+ {% endblock %}
+{% endblock %}
diff --git a/templates/_includes/manager/nicknames.html b/templates/_includes/manager/nicknames.html
new file mode 100644
index 0000000..c885193
--- /dev/null
+++ b/templates/_includes/manager/nicknames.html
@@ -0,0 +1,23 @@
+내 닉네임 :
+{% for one_of_my_nick_class in manager__nickname__my_nickname_classes %}
+
+
+
+
+{% endfor %}
+
+
+추천받은 닉네임 :
+{% for idx in range(0, manager__nickname__recommended_nicknames_for_me['nick'].__len__()) %}
+
+
+
+
+{% endfor %}
diff --git a/templates/_includes/manager/photo.html b/templates/_includes/manager/photo.html
new file mode 100644
index 0000000..681edff
--- /dev/null
+++ b/templates/_includes/manager/photo.html
@@ -0,0 +1,7 @@
+
+
+ 정사각형의 사진을 올려주시면 예뻐요.
+
diff --git a/templates/_includes/profile.html b/templates/_includes/profile.html
new file mode 100644
index 0000000..61a8cbb
--- /dev/null
+++ b/templates/_includes/profile.html
@@ -0,0 +1,56 @@
+{% if not profile__is_in_manager %}
+ {% if profile__user_class.username == get_logged_in_username %}
+
+
+
+ {% endif %}
+{% endif %}
+
+
+ {% if profile__photo_url %}
+
+ {% else %}
+
+ {% endif %}
+
+
+
+ {{ profile__user_class.realname }}
+
+
+
+ {% for nickname in profile__user_nickname_classes %}
+
+ {{ nickname.nick }}
+
+ {% endfor %}
+
+
+ {% if get_logged_in_username %}
+ {% if profile__user_class.username != get_logged_in_username %}
+ {% if not profile__is_in_manager %}
+
+ {% endif %}
+ {% endif %}
+ {% endif %}
+
diff --git a/templates/_includes/top_menu_nav.html b/templates/_includes/top_menu_nav.html
new file mode 100644
index 0000000..4142955
--- /dev/null
+++ b/templates/_includes/top_menu_nav.html
@@ -0,0 +1,31 @@
+
diff --git a/templates/_main.html b/templates/_main.html
deleted file mode 100644
index 8c5ac28..0000000
--- a/templates/_main.html
+++ /dev/null
@@ -1,81 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
- {% block style %}
-
- {% endblock %}
-
-
-
-
-
-
-
-
-
-
-
- {% block script %}
-
- {% endblock %}
-
-
-
diff --git a/templates/_profile.html b/templates/_profile.html
deleted file mode 100644
index 9e1d820..0000000
--- a/templates/_profile.html
+++ /dev/null
@@ -1,44 +0,0 @@
- {% if is_me %}
-
-
-
- {% endif %}
-
-
diff --git a/templates/_profile_manage.html b/templates/_profile_manage.html
deleted file mode 100644
index d240dcd..0000000
--- a/templates/_profile_manage.html
+++ /dev/null
@@ -1,81 +0,0 @@
-{% extends "_main.html" %}
-{% block content %}
-
-
-
-
-
-
-
- {% block manage_content %}
- {% endblock %}
-
-
-{% endblock %}
diff --git a/templates/login.html b/templates/login.html
index 986abff..e7e3154 100644
--- a/templates/login.html
+++ b/templates/login.html
@@ -1,8 +1,8 @@
-{% extends "_main.html" %}
-{% block content %}
-
+{% extends "_extends/_index.html" %}
+{% block _index__container %}
+
{% endblock %}
diff --git a/templates/main.html b/templates/main.html
deleted file mode 100644
index 9f7d159..0000000
--- a/templates/main.html
+++ /dev/null
@@ -1,5 +0,0 @@
-{% extends "_main.html" %}
-{% block content %}
- {{ naeyoung }}
-{% endblock %}
-
diff --git a/templates/manager.html b/templates/manager.html
new file mode 100644
index 0000000..69221b2
--- /dev/null
+++ b/templates/manager.html
@@ -0,0 +1,74 @@
+{% extends "_extends/_index.html" %}
+{% block _index__container %}
+
+
+
+
+
+
+ {% if manager__right_html_for_menu %}
+ {% include manager__right_html_for_menu %}
+ {% endif %}
+
+
+{% endblock %}
diff --git a/templates/profile.html b/templates/profile.html
index 7dd65c5..f979f6e 100644
--- a/templates/profile.html
+++ b/templates/profile.html
@@ -1,16 +1,4 @@
-{% extends "_main.html" %}
-{% block content %}
- {% include "_profile.html" %}
- {% if not is_me %}
- {% if username %}
-
-
-
- {% endif %}
- {% endif %}
+{% extends "_extends/_index.html" %}
+{% block _index__container %}
+ {% include "_includes/profile.html" %}
{% endblock %}
-
diff --git a/templates/profile_manage.html b/templates/profile_manage.html
deleted file mode 100644
index 2811a92..0000000
--- a/templates/profile_manage.html
+++ /dev/null
@@ -1,4 +0,0 @@
-{% extends "_profile_manage.html" %}
-{% block manage_content %}
- {% include '_profile.html' %}
-{% endblock %}
diff --git a/templates/profile_manage_nick.html b/templates/profile_manage_nick.html
deleted file mode 100644
index e0e31c1..0000000
--- a/templates/profile_manage_nick.html
+++ /dev/null
@@ -1,26 +0,0 @@
-{% extends "_profile_manage.html" %}
-{% block manage_content %}
-내 닉네임 :
-{% for nick in found %}
-
-
-
-
-{% endfor %}
-
-
-추천받은 닉네임 :
-{% for i in range(0,recomm['nick'].__len__()) %}
-
-
-
-
-{% endfor %}
-{% endblock %}
diff --git a/templates/profile_manage_photo.html b/templates/profile_manage_photo.html
deleted file mode 100644
index b9d4122..0000000
--- a/templates/profile_manage_photo.html
+++ /dev/null
@@ -1,10 +0,0 @@
-{% extends "_profile_manage.html" %}
-{% block manage_content %}
-
-
- 정사각형의 사진을 올려주시면 예뻐요.
-
-{% endblock %}
diff --git a/templates/register.html b/templates/register.html
index 8eb3ef1..421f376 100644
--- a/templates/register.html
+++ b/templates/register.html
@@ -1,58 +1,60 @@
-{% extends "_main.html" %}
-{% block content %}
-
-
+ Student Number:
+
+
{% endblock %}
-{% block script %}
-
+ );
+
{% endblock %}
diff --git a/url.py b/url.py
index a138e12..cd51014 100644
--- a/url.py
+++ b/url.py
@@ -43,7 +43,10 @@ def goto(link, is_manage=False):
else:
return userpage(this_user)
else:
- return "존재하지 않는 페이지입니다.", 404
+ return render_template(
+ "_error.html",
+ _error__msg="존재하지 않는 페이지입니다.",
+ ), 404
def gotomanage(link):
@@ -57,13 +60,13 @@ def addURL(link, username):
URL.link == link,
).first()
if found:
- return "이미 생성된 링크입니다.", 400
+ return False
newP = URL()
newP.link = link
newP.username = username
db.session.add(newP)
db.session.commit()
- return "등록됐습니다."
+ return True
def get_logged_in_username(*args, **kwargs):
@@ -85,17 +88,12 @@ def userpage(user):
Nickname.username == user.username,
).all()
- is_me = False
- if user.username == get_logged_in_username():
- is_me = True
-
return render_template(
"profile.html",
- user=user,
- photo=my_photo,
- nicknames=my_nicknames,
- is_me=is_me,
- username=get_logged_in_username(),
+ profile__is_in_manager=False,
+ profile__photo_url=my_photo,
+ profile__user_class=user,
+ profile__user_nickname_classes=my_nicknames,
)
@@ -114,12 +112,12 @@ def usermanagepage(user):
Nickname.username == user.username,
).all()
return render_template(
- "profile_manage.html",
- user=user,
- photo=my_photo,
- nicknames=my_nicknames,
- username=user.username,
- menu='profile',
+ "manager.html",
+ manager__right_html_for_menu="_includes/profile.html",
+ profile__is_in_manager=True,
+ profile__photo_url=my_photo,
+ profile__user_class=user,
+ profile__user_nickname_classes=my_nicknames,
)
diff --git a/user.py b/user.py
index d31fd4c..4f8ee5e 100644
--- a/user.py
+++ b/user.py
@@ -30,32 +30,53 @@ def add_routes(app):
def register():
"""GET /register 회원가입폼 POST /register 실제회원가입."""
if get_logged_in_username():
- return "이미 로그인되어있어요!", 400
+ return render_template(
+ "_error.html",
+ _error__msg="이미 로그인되어있어요!",
+ ), 400
if request.method == "GET":
return render_template("register.html")
else:
username = request.form['usr']
if not username or len(username) > N:
- return 'Failed', 400
+ return render_template(
+ "_error.html",
+ _error__msg="Failed - username이 맞지 않습니다.",
+ ), 400
found = check_username(username, is_internal=True)
if found:
- return "Existing Username", 400
+ return render_template(
+ "_error.html",
+ _error__msg="Failed - username이 겹칩니다.",
+ ), 400
if not request.form['pwd']:
- return 'Failed', 400
+ return render_template(
+ "_error.html",
+ _error__msg="Failed - password가 맞지 않습니다.",
+ ), 400
if request.form['pwd'] != request.form['pwda']:
- return 'Failed', 400
+ return render_template(
+ "_error.html",
+ _error__msg="Failed - password가 맞지 않습니다.",
+ ), 400
password_hash = bcrypt.generate_password_hash(request.form['pwd'])
realname = request.form['realname']
if not realname or len(realname) > N:
- return 'Failed', 400
+ return render_template(
+ "_error.html",
+ _error__msg="Failed - 이름이 맞지 않습니다.",
+ ), 400
try:
student_number = int(request.form['sn'])
except ValueError:
- return 'Failed', 400
+ return render_template(
+ "_error.html",
+ _error__msg="Failed - 학번이 맞지 않습니다.",
+ ), 400
new_user = User()
new_user.username = username