From f8228779d0f002ef12b635df6fa26e1aaa42abcb Mon Sep 17 00:00:00 2001 From: AidanFarhi Date: Sun, 18 Jul 2021 13:41:45 -0400 Subject: [PATCH 01/28] created model for message, ghost route and html as well --- forum/forum.py | 13 +++++++++++++ forum/templates/createmessage.html | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 forum/templates/createmessage.html diff --git a/forum/forum.py b/forum/forum.py index 1645346..11b4a88 100644 --- a/forum/forum.py +++ b/forum/forum.py @@ -158,6 +158,12 @@ def action_createaccount(): login_user(user) return redirect("/") +# AIDAN WAS HERE - Route to send a message +@login_required +@app.route('/action_sendmessage') +def action_sendmessage(): + pass + def error(errormessage): return "" + errormessage + "" @@ -324,6 +330,13 @@ def get_time_string(self): return self.savedresponce +# AIDAN WAS HERE +class DirectMessage(db.Model): + id = db.Column(db.Integer, primary_key=True) + sender_id = db.Column(db.Integer) + receiver_id = db.Column(db.Integer) + body = db.Column(db.String(256)) # limit 256 chars in message + def init_site(): admin = add_subforum("Forum", "Announcements, bug reports, and general discussion about the forum belongs here") add_subforum("Announcements", "View forum announcements here",admin) diff --git a/forum/templates/createmessage.html b/forum/templates/createmessage.html new file mode 100644 index 0000000..235d9a1 --- /dev/null +++ b/forum/templates/createmessage.html @@ -0,0 +1,19 @@ +{% extends 'layout.html' %} +{% block body %} + +
+ Enter your post here:
+
+ You are posting to {{ subforum.title }} +
+ +
+ +
+ +
+ + +
+
+{% endblock %} \ No newline at end of file From 1c5696c093ca7019391055db2d98cf547febb837 Mon Sep 17 00:00:00 2001 From: AidanFarhi Date: Sun, 18 Jul 2021 15:50:21 -0400 Subject: [PATCH 02/28] added front end and route to see all messages --- forum/forum.py | 5 +++++ forum/templates/header.html | 8 +++++++- forum/templates/usermessages.html | 20 ++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 forum/templates/usermessages.html diff --git a/forum/forum.py b/forum/forum.py index 11b4a88..bd54cb8 100644 --- a/forum/forum.py +++ b/forum/forum.py @@ -164,6 +164,11 @@ def action_createaccount(): def action_sendmessage(): pass +@login_required +@app.route('/get_messages_for_user') +def get_messages_for_user(): + return render_template('usermessages.html') + def error(errormessage): return "" + errormessage + "" diff --git a/forum/templates/header.html b/forum/templates/header.html index 9403a0d..6daeaf1 100644 --- a/forum/templates/header.html +++ b/forum/templates/header.html @@ -1,7 +1,13 @@ {{ config.SITE_NAME }}{% if config.SITE_DESCRIPTION %} - {% endif %} {{ config.SITE_DESCRIPTION }} + {% endblock %} \ No newline at end of file From 97b522ba692312cacf042211974d4c63b0aaff46 Mon Sep 17 00:00:00 2001 From: AidanFarhi Date: Sun, 18 Jul 2021 17:29:04 -0400 Subject: [PATCH 04/28] made progress on send message form --- forum/forum.py | 19 +++++++++++++++-- forum/templates/createmessage.html | 27 ++++++++++++------------- forum/templates/error.html | 6 ++++++ forum/templates/messagesentsuccess.html | 6 ++++++ forum/templates/usermessages.html | 6 +++++- 5 files changed, 47 insertions(+), 17 deletions(-) create mode 100644 forum/templates/error.html create mode 100644 forum/templates/messagesentsuccess.html diff --git a/forum/forum.py b/forum/forum.py index 06ebfee..fc65113 100644 --- a/forum/forum.py +++ b/forum/forum.py @@ -71,6 +71,10 @@ def get_messages_for_user(): senders = get_sending_usernames(messages) return render_template('usermessages.html', messages=messages, senders=senders) +@login_required +@app.route('/createmessage') +def createmessage(): + return render_template('createmessage.html') def get_sending_usernames(msgs): ''' @@ -181,9 +185,20 @@ def action_createaccount(): # AIDAN WAS HERE - Route to send a message @login_required -@app.route('/action_sendmessage') +@app.route('/action_sendmessage', methods=['POST']) def action_sendmessage(): - pass + errors = [] + receiver_username = request.form['username'] + message_body = request.form['message_body'] + # check is user exists + user = User.query.filter_by(username=receiver_username).first() + if user is None: + errors.append('User does not exist') + return render_template('createmessage.html', errors=errors) + if len(message_body) == 0: + errors.append('Cannot send empty message') + return render_template('createmessage.html', errors=errors) + return render_template('messagesentsuccess.html') def error(errormessage): diff --git a/forum/templates/createmessage.html b/forum/templates/createmessage.html index 235d9a1..710c99f 100644 --- a/forum/templates/createmessage.html +++ b/forum/templates/createmessage.html @@ -1,19 +1,18 @@ {% extends 'layout.html' %} {% block body %} -
- Enter your post here:
-
- You are posting to {{ subforum.title }} +

Send Message

+
+
+
+ +
- - - -
- -
- - -
-
+
+ + +
+
+ + {% endblock %} \ No newline at end of file diff --git a/forum/templates/error.html b/forum/templates/error.html new file mode 100644 index 0000000..09f3a52 --- /dev/null +++ b/forum/templates/error.html @@ -0,0 +1,6 @@ +{% extends 'layout.html' %} +{% block body %} + +

{{ error }}

+ +{% endblock %} \ No newline at end of file diff --git a/forum/templates/messagesentsuccess.html b/forum/templates/messagesentsuccess.html new file mode 100644 index 0000000..0185ab4 --- /dev/null +++ b/forum/templates/messagesentsuccess.html @@ -0,0 +1,6 @@ +{% extends 'layout.html' %} +{% block body %} + +

Message Sent Successfuly!!

+ +{% endblock %} \ No newline at end of file diff --git a/forum/templates/usermessages.html b/forum/templates/usermessages.html index 7d38d48..ebfc0de 100644 --- a/forum/templates/usermessages.html +++ b/forum/templates/usermessages.html @@ -1,7 +1,11 @@ {% extends 'layout.html' %} {% block body %}

Messages

- +
+ + New Message + +
{% for msg in messages %} From 3524b0aceab3045dce189c56551ac1052921edaa Mon Sep 17 00:00:00 2001 From: AidanFarhi Date: Sun, 18 Jul 2021 17:42:38 -0400 Subject: [PATCH 05/28] users are now able to send and receive private messages --- forum/forum.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/forum/forum.py b/forum/forum.py index fc65113..365862f 100644 --- a/forum/forum.py +++ b/forum/forum.py @@ -198,6 +198,9 @@ def action_sendmessage(): if len(message_body) == 0: errors.append('Cannot send empty message') return render_template('createmessage.html', errors=errors) + new_message = DirectMessage(current_user.id, user.id, message_body) + db.session.add(new_message) + db.session.commit() return render_template('messagesentsuccess.html') @@ -369,11 +372,17 @@ def get_time_string(self): # AIDAN WAS HERE class DirectMessage(db.Model): + id = db.Column(db.Integer, primary_key=True) sender_id = db.Column(db.Integer) receiver_id = db.Column(db.Integer) body = db.Column(db.String(256)) # limit 256 chars in message + def __init__(self, sender_id, receiver_id, body): + self.sender_id = sender_id + self.receiver_id = receiver_id + self.body = body + def init_site(): admin = add_subforum("Forum", "Announcements, bug reports, and general discussion about the forum belongs here") add_subforum("Announcements", "View forum announcements here",admin) From 2132da0b0f4a22cc1db50acdef6465fc2319f5c1 Mon Sep 17 00:00:00 2001 From: AidanFarhi Date: Sun, 18 Jul 2021 17:47:14 -0400 Subject: [PATCH 06/28] added some comments --- forum/forum.py | 4 +++- forum/templates/error.html | 6 ------ 2 files changed, 3 insertions(+), 7 deletions(-) delete mode 100644 forum/templates/error.html diff --git a/forum/forum.py b/forum/forum.py index 365862f..92fa711 100644 --- a/forum/forum.py +++ b/forum/forum.py @@ -183,7 +183,7 @@ def action_createaccount(): login_user(user) return redirect("/") -# AIDAN WAS HERE - Route to send a message +# Action to send a message @login_required @app.route('/action_sendmessage', methods=['POST']) def action_sendmessage(): @@ -195,9 +195,11 @@ def action_sendmessage(): if user is None: errors.append('User does not exist') return render_template('createmessage.html', errors=errors) + # check if message is empty if len(message_body) == 0: errors.append('Cannot send empty message') return render_template('createmessage.html', errors=errors) + # create new message and commit to database new_message = DirectMessage(current_user.id, user.id, message_body) db.session.add(new_message) db.session.commit() diff --git a/forum/templates/error.html b/forum/templates/error.html deleted file mode 100644 index 09f3a52..0000000 --- a/forum/templates/error.html +++ /dev/null @@ -1,6 +0,0 @@ -{% extends 'layout.html' %} -{% block body %} - -

{{ error }}

- -{% endblock %} \ No newline at end of file From 3e3a5e889f75aa1cef41f17b6cf63647109f53af Mon Sep 17 00:00:00 2001 From: Nikki Date: Mon, 19 Jul 2021 22:55:10 -0400 Subject: [PATCH 07/28] Added 3 emojis and like button --- .DS_Store | Bin 0 -> 6148 bytes forum/.DS_Store | Bin 0 -> 6148 bytes forum/forum.py | 31 +++++++++++++++++++++++++++++++ forum/templates/viewpost.html | 6 ++++++ 4 files changed, 37 insertions(+) create mode 100644 .DS_Store create mode 100644 forum/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5ee732be0e61da3a9b1394a1e4040a87a0e5f9ff GIT binary patch literal 6148 zcmeHK%Wl&^6upzW#R(v?Kq_M84HAnG#o?t0A%&1Gx@h zpRj_dxdas4$963D!&rtWbBETf0#lWSOZu$CjddsihzgO}6dTmzmrVZb(cz5sAX0xKZdBcCWy*GIOVfu0Q>8lcn z1hztDR}3D(H)Iy%7vp5+=dP-aLh}!f7Sfv4V za{~X$G0Hq$^p-O8&$$6Sp_E2or}QpA{e>XM-vBEEqY6fUc`V|k@?~MEI5bwhk8^Rn zJWh>UxhcQhs8zgrz46ymek?_9!lA@Dn^~yt#dCfRJG@oEDzJJA@c!Vz8Jh;@8r9Z; zL|p-Z4yu(QuYUc39#;UH2Im@40~4AG)Kp=v7{c5fgr=jtY2xP^HJyYS8U2`%g}I>! zbMX+K3MbLjXj7|zRbW|xHC-(8`M-7c{ePKcOI87^z<;HHaN3=A3$J9())OzsXRQa{ rgR^nmT%)2OF~_mW@KJmXt_*D+XMjzEbB(Bh*&hKVgH5ag|5SlLuJ!xG literal 0 HcmV?d00001 diff --git a/forum/.DS_Store b/forum/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..fc403a3326135c037e6d2928573c808a4e5fd63b GIT binary patch literal 6148 zcmeHK%Wl&^6upy%;G{xifz*nXH%Kf3iVG=<5Rw(jqB|rbSO7}x#1KoaZN&~zFhSn% z5j=i?PeFVDAHoN~nMYCVq}}l-nrq!T*E9EwJtvtN4-v7!Y-|y=iO7I+thZ2XFy796 z&1$NK^O)!(pp1sNZc?(Att+$wT7iE}0X}!P#heW&qSg7kI1J;F7sehk`0{WUe*K3q zL?^6-7BnIkJ|Um?Q)boN3af$K1Q%Z+s!#Y_$u;N&#WbZE9dF8KJC*zfrC5JlctE4_ zd$4zB<$CipQ6v58C1H?e-R?J5+p1q^Tr`Z9(Yn-n?o8sjleyU}9k|n{{O+NfO*|Dp zisSHC?0Sy_e?DwqxgSTF8$|w8kb|+0lxI(ZXdKT6@hlprq8~>#7)H}*4%=7r{DyU_ z-|d)td;Mj{%=?zrF?+YW%VpEpxn|uvJUU*y&fhHGe#DSq3`?)D%L-566M~W?ubgQV z#?edEb50XN`H(iDP>AMJS`qC#vQ~fc4U84(zWiQ-%A0 z#tlQQ$S3+Z*M<7y7~AK16#C`00$PFJp#WbWOgKkdVIfg09Vo;R09Z%0FvR?0fpbiS zw!%UpT3}34fs)G95rauO>P?krD=Z{RIx%(lVCuw75x;8kz*P8GnI5(bGNE8$lYC9GI-->tP b!q8^&0B9>LB%%hUKLmsfy3h*zQ3ZYi1NP?~ literal 0 HcmV?d00001 diff --git a/forum/forum.py b/forum/forum.py index 1645346..c3038df 100644 --- a/forum/forum.py +++ b/forum/forum.py @@ -72,6 +72,23 @@ def comment(): if not post: return error("That post does not exist!") content = request.form['content'] + + # Like button + like_counter = 0 + if request.method == 'POST': + if request.form.get('action1') == 'Like': + print('hello') + + + # replaces key word with emoji + if '*wink*' in content: + content = content.replace('*wink*', '\U0001F609') + if '*smile*' in content: + content = content.replace('*smile*', '\U0001F600') + if '*like*' in content: + content = content.replace('*like*', '\U0001F44D') + + postdate = datetime.datetime.now() comment = Comment(content, postdate) current_user.comments.append(comment) @@ -90,6 +107,20 @@ def action_post(): user = current_user title = request.form['title'] content = request.form['content'] + + # replaces key word with emoji + if '*wink*' in content or '*wink*' in title: + content = content.replace('*wink*', '\U0001F609') + title = title.replace('*wink*', '\U0001F609') + if '*smile*' in content or '*smile*' in title: + content = content.replace('*smile*', '\U0001F600') + title = title.replace('*smile*', '\U0001F600') + if '*like*' in content or '*like*' in title: + content = content.replace('*like*', '\U0001F44D') + title = title.replace('*like*', '\U0001F44D') + + + #check for valid posting errors = [] retry = False diff --git a/forum/templates/viewpost.html b/forum/templates/viewpost.html index 3f489ca..0746394 100644 --- a/forum/templates/viewpost.html +++ b/forum/templates/viewpost.html @@ -2,6 +2,7 @@ {% block body %} {{ path|safe}} +
{{post.title}} @@ -26,6 +27,11 @@
+ +
+ +
+ {% if current_user.is_authenticated %} From ee0f1bc5d4253448f619500b923b11d3c93c4b0e Mon Sep 17 00:00:00 2001 From: Nikki Date: Mon, 19 Jul 2021 23:01:55 -0400 Subject: [PATCH 08/28] Added 3 emojis and like button --- .DS_Store | Bin 0 -> 6148 bytes forum/.DS_Store | Bin 0 -> 6148 bytes forum/forum.py | 31 +++++++++++++++++++++++++++++++ forum/templates/viewpost.html | 6 ++++++ 4 files changed, 37 insertions(+) create mode 100644 .DS_Store create mode 100644 forum/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5ee732be0e61da3a9b1394a1e4040a87a0e5f9ff GIT binary patch literal 6148 zcmeHK%Wl&^6upzW#R(v?Kq_M84HAnG#o?t0A%&1Gx@h zpRj_dxdas4$963D!&rtWbBETf0#lWSOZu$CjddsihzgO}6dTmzmrVZb(cz5sAX0xKZdBcCWy*GIOVfu0Q>8lcn z1hztDR}3D(H)Iy%7vp5+=dP-aLh}!f7Sfv4V za{~X$G0Hq$^p-O8&$$6Sp_E2or}QpA{e>XM-vBEEqY6fUc`V|k@?~MEI5bwhk8^Rn zJWh>UxhcQhs8zgrz46ymek?_9!lA@Dn^~yt#dCfRJG@oEDzJJA@c!Vz8Jh;@8r9Z; zL|p-Z4yu(QuYUc39#;UH2Im@40~4AG)Kp=v7{c5fgr=jtY2xP^HJyYS8U2`%g}I>! zbMX+K3MbLjXj7|zRbW|xHC-(8`M-7c{ePKcOI87^z<;HHaN3=A3$J9())OzsXRQa{ rgR^nmT%)2OF~_mW@KJmXt_*D+XMjzEbB(Bh*&hKVgH5ag|5SlLuJ!xG literal 0 HcmV?d00001 diff --git a/forum/.DS_Store b/forum/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..fc403a3326135c037e6d2928573c808a4e5fd63b GIT binary patch literal 6148 zcmeHK%Wl&^6upy%;G{xifz*nXH%Kf3iVG=<5Rw(jqB|rbSO7}x#1KoaZN&~zFhSn% z5j=i?PeFVDAHoN~nMYCVq}}l-nrq!T*E9EwJtvtN4-v7!Y-|y=iO7I+thZ2XFy796 z&1$NK^O)!(pp1sNZc?(Att+$wT7iE}0X}!P#heW&qSg7kI1J;F7sehk`0{WUe*K3q zL?^6-7BnIkJ|Um?Q)boN3af$K1Q%Z+s!#Y_$u;N&#WbZE9dF8KJC*zfrC5JlctE4_ zd$4zB<$CipQ6v58C1H?e-R?J5+p1q^Tr`Z9(Yn-n?o8sjleyU}9k|n{{O+NfO*|Dp zisSHC?0Sy_e?DwqxgSTF8$|w8kb|+0lxI(ZXdKT6@hlprq8~>#7)H}*4%=7r{DyU_ z-|d)td;Mj{%=?zrF?+YW%VpEpxn|uvJUU*y&fhHGe#DSq3`?)D%L-566M~W?ubgQV z#?edEb50XN`H(iDP>AMJS`qC#vQ~fc4U84(zWiQ-%A0 z#tlQQ$S3+Z*M<7y7~AK16#C`00$PFJp#WbWOgKkdVIfg09Vo;R09Z%0FvR?0fpbiS zw!%UpT3}34fs)G95rauO>P?krD=Z{RIx%(lVCuw75x;8kz*P8GnI5(bGNE8$lYC9GI-->tP b!q8^&0B9>LB%%hUKLmsfy3h*zQ3ZYi1NP?~ literal 0 HcmV?d00001 diff --git a/forum/forum.py b/forum/forum.py index 1645346..c3038df 100644 --- a/forum/forum.py +++ b/forum/forum.py @@ -72,6 +72,23 @@ def comment(): if not post: return error("That post does not exist!") content = request.form['content'] + + # Like button + like_counter = 0 + if request.method == 'POST': + if request.form.get('action1') == 'Like': + print('hello') + + + # replaces key word with emoji + if '*wink*' in content: + content = content.replace('*wink*', '\U0001F609') + if '*smile*' in content: + content = content.replace('*smile*', '\U0001F600') + if '*like*' in content: + content = content.replace('*like*', '\U0001F44D') + + postdate = datetime.datetime.now() comment = Comment(content, postdate) current_user.comments.append(comment) @@ -90,6 +107,20 @@ def action_post(): user = current_user title = request.form['title'] content = request.form['content'] + + # replaces key word with emoji + if '*wink*' in content or '*wink*' in title: + content = content.replace('*wink*', '\U0001F609') + title = title.replace('*wink*', '\U0001F609') + if '*smile*' in content or '*smile*' in title: + content = content.replace('*smile*', '\U0001F600') + title = title.replace('*smile*', '\U0001F600') + if '*like*' in content or '*like*' in title: + content = content.replace('*like*', '\U0001F44D') + title = title.replace('*like*', '\U0001F44D') + + + #check for valid posting errors = [] retry = False diff --git a/forum/templates/viewpost.html b/forum/templates/viewpost.html index 3f489ca..0746394 100644 --- a/forum/templates/viewpost.html +++ b/forum/templates/viewpost.html @@ -2,6 +2,7 @@ {% block body %} {{ path|safe}} +
{{post.title}} @@ -26,6 +27,11 @@
+ +
+ +
+ {% if current_user.is_authenticated %} From 8c55aebfab9a4b43a235440877bcbcae0343982d Mon Sep 17 00:00:00 2001 From: Nikki Date: Fri, 23 Jul 2021 13:51:15 -0400 Subject: [PATCH 09/28] 3 emojis added --- .DS_Store | Bin 6148 -> 6148 bytes emoji_list.csv | 16 ++++++++++++++++ forum/forum.py | 14 +++++--------- forum/templates/viewpost.html | 8 +------- 4 files changed, 22 insertions(+), 16 deletions(-) create mode 100644 emoji_list.csv diff --git a/.DS_Store b/.DS_Store index 5ee732be0e61da3a9b1394a1e4040a87a0e5f9ff..af672506d90d227b1106661bffad2e8c102a1cb3 100644 GIT binary patch delta 171 zcmZoMXfc@J&&aniU^g=(-(((^_9z zlrR)~=Hw?Q<>V(ZFfa%(FffV(=^6jQ0LWrs-~;N&1**;hs*h*L0g}Z)U3x%MiW$n# f^tPhv-JHcD%go6LHim(Nd$S;i7|Uigo_pK?g4!zi delta 46 ycmZoMXfc@J&&abeU^g=(&tx8!_|30bWSA$GHE=RAfB^^hW
-
- - -
- -
+
- {% if current_user.is_authenticated %} From af5a57ba8b7f489021d45ed764859cbb6b8d797e Mon Sep 17 00:00:00 2001 From: Sean Date: Fri, 23 Jul 2021 14:03:23 -0400 Subject: [PATCH 10/28] first commit --- .DS_Store | Bin 0 -> 6148 bytes forum/.DS_Store | Bin 0 -> 6148 bytes forum/app.py | 4 +- forum/forum.py | 106 ++++++++++++++++++++++++++--- forum/templates/viewpost copy.html | 77 +++++++++++++++++++++ forum/templates/viewpost.html | 48 +++++++++++-- 6 files changed, 221 insertions(+), 14 deletions(-) create mode 100644 .DS_Store create mode 100644 forum/.DS_Store create mode 100644 forum/templates/viewpost copy.html diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5561818c848113912ea635bdc369d8ddadb95588 GIT binary patch literal 6148 zcmeHK!EVzq82-IwTQWfOFljsHg2bV!+QH~yLMo*@?0_^;1P4G{vz9he8jm(^`}@{cQ!V+T+eg8Ti)yT zKu+69CrQW6&gi8ooph2xVEkuNMoYgFJP&)*)6&jk87G}E?v0onc6$hU^&*VBa@v$> z+#Pd2ZQZ~FotE}yv;BIl?C&2O%*+0)Uayw@`}ZEq=bpQJr}pspZ211e?Bo2?SC)tb zHbS=B1~1_ooXiv_?NJ=bxQ|-JaOnhMN;-#JAw@-5Ni9WIERUYj5j~<7Jpoo|NZq`= zybxJNNi7z=r4;=uZ-^9ALSwKKdRJV0@wqVKCRiyL6)*;cv3?a|9hz|OlYAU6dG>`` z#$DG1Urw;F+|X+U%)F}ZjTLwn`v_J6tH5e0p!NqJNnyj_LL+Y-$oL8XbWqI(pMU*< zzN!E=3@$XH1|~EWsHwtSF@(7}2u(+O!^AH%YB~uX8U2`%g}I>!bMX*9hm&Y%w7FHl zDv(!TT^CF0{6G5l{Xb8#C98l{;94mloL0Nl#FWh0dS!Czto4!3kd&#og+`_zGsiJI f>L}hrVnds+9ALxXLL+Km_D6tau$fihzbfzt=o0%X literal 0 HcmV?d00001 diff --git a/forum/.DS_Store b/forum/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..ad012cd53c99054aa31addf49091550de4191c6f GIT binary patch literal 6148 zcmeHKL5|Zf6#bqlC1Hf<0%>NM4HAnAwF5&JBc!Mdi`gLs!2(bxX#&_-|zf1mBT2N5i)prIELT;p$yTA zmD8Mt6vD?8b3ZlKml~^y+#DCL5VaA+el6FbS0rgdQ##+8|Dl%OqypjDB-U6(go%ouTIY@xpw!FrrzJ8->0`d72bur}Ith>^816uR5;lxYym6!C20M zGAyS>Kb$=0yT@TUj!gVS%Jf$pMo*J?HfY^^D6=w5vUsA%$tXt3i)TqTlC!>?W}`y& z6X*st(4cj&SRD4cZSU~tXxa7_y`i+9WSpCANGV8K>) z!{7=&BiJ(4H^C%JW%e4aE9Qz}@scWFUZk^kNuS?7wpG9?@aGiZ^}&NP`UWeFYUx0s zjsU<0s+A$;p9SW427QB-Mzp|$rUErpm?MVJbkut$&o@|U)N~T&@FC2|!kkcq8Xf(6 zDxHL{(Uw*LtH8PfyZW}p`~Rcgpa0iM_RcC`75J|d5RH@Iq>m|?y>(-9yw`g0GdLUP nRT>oqh1rf(z+3SFTp8Lt4uHPFN+W7u_D4X;U<<3jUsd2InP8(7 literal 0 HcmV?d00001 diff --git a/forum/app.py b/forum/app.py index 1521375..2072b35 100644 --- a/forum/app.py +++ b/forum/app.py @@ -6,5 +6,7 @@ SECRET_KEY=b'kristofer', SITE_NAME = "Schooner", SITE_DESCRIPTION = "a schooner forum", - SQLALCHEMY_DATABASE_URI='sqlite:////tmp/database.db' + SQLALCHEMY_DATABASE_URI='sqlite:////tmp/database.db' #relative pass to physical db location (this has 4 /) ) + + diff --git a/forum/forum.py b/forum/forum.py index 1645346..eb073ee 100644 --- a/forum/forum.py +++ b/forum/forum.py @@ -1,3 +1,4 @@ +# kill -9 40614 from flask import * #from flask.ext.login import LoginManager, login_required, current_user, logout_user, login_user from flask_login import LoginManager, current_user, login_user, logout_user @@ -25,7 +26,7 @@ def index(): @app.route('/subforum') def subforum(): - subforum_id = int(request.args.get("sub")) + subforum_id = int(request.args.get("sub")) subforum = Subforum.query.filter(Subforum.id == subforum_id).first() if not subforum: return error("That subforum does not exist!") @@ -53,32 +54,55 @@ def addpost(): @app.route('/viewpost') def viewpost(): - postid = int(request.args.get("post")) + postid = int(request.args.get("post")) # provides dictionary of the post table post = Post.query.filter(Post.id == postid).first() if not post: return error("That post does not exist!") if not post.subforum.path: subforum.path = generateLinkPath(post.subforum.id) comments = Comment.query.filter(Comment.post_id == postid).order_by(Comment.id.desc()) # no need for scalability now + # how you access the database + return render_template("viewpost.html", post=post, path=subforum.path, comments=comments) #ACTIONS @login_required @app.route('/action_comment', methods=['POST', 'GET']) +# '/action_comment' is how viewpost.html calls comment() def comment(): - post_id = int(request.args.get("post")) - post = Post.query.filter(Post.id == post_id).first() + post_id = int(request.args.get("post")) # goes to the post table and gets the post_id + # .args.get("post") is from html + # ?post = {{post.id}} + post = Post.query.filter(Post.id == post_id).first() # checks to make sure post id exists and returns the first + # a query is a select statement + if not post: return error("That post does not exist!") content = request.form['content'] postdate = datetime.datetime.now() + + comment = Comment(content, postdate) + # this creates an instance of comment current_user.comments.append(comment) - post.comments.append(comment) + # inserts comment into users table + post.comments.append(comment) #go to the post table, go to the comments column, and then add the comment db.session.commit() return redirect("/viewpost?post=" + str(post_id)) + +# create a route that sets passes a ?id= {{comment.id}} method = 'POST' +# grab parent comment id with int(request.args.get(comment.id)) +# make sure route name is unique +# 1) make sure you're getting all data in form +# 2) putting data into the database + +@login_required +@app.route('/comment_comment', methods = ['POST', 'GET']) +def comment_comment(): + pass + @login_required @app.route('/action_post', methods=['POST']) def action_post(): @@ -108,6 +132,7 @@ def action_post(): return redirect("/viewpost?post=" + str(post.id)) + @app.route('/action_login', methods=['POST']) def action_login(): username = request.form['username'] @@ -275,19 +300,84 @@ def get_time_string(self): return self.savedresponce +# a 'Subforum' model is a table, and all the models make up the database +# a model's attributes are its columns when defined with db.Column + +# so below we have the subforum model +# the order is id, title, description, parent_id +# id is the primary key +# title, description are columns +# parent_id sets subforum.id as the parent key +# subforums has a r + + class Subforum(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.Text, unique=True) description = db.Column(db.Text) subforums = db.relationship("Subforum") parent_id = db.Column(db.Integer, db.ForeignKey('subforum.id')) - posts = db.relationship("Post", backref="subforum") + posts = db.relationship("Post", backref="subforum") # Post's table is going to get a virtual column of subforum path = None hidden = db.Column(db.Boolean, default=False) def __init__(self, title, description): self.title = title self.description = description + +# order is id, content, postdate, user_id, post_id +# we set parent_comment_id as the hcild key, id as the parent_key + +class Comment(db.Model): + id = db.Column(db.Integer, primary_key=True) # every comment gets a primary key + content = db.Column(db.Text) # body + postdate = db.Column(db.DateTime) + user_id = db.Column(db.Integer, db.ForeignKey('user.id')) # lower case looks at a table, upper case looks at a class + post_id = db.Column(db.Integer, db.ForeignKey("post.id")) # parent article + + comments = db.relationship("Comment") # relates to + parent_comment_id = db.Column(db.Integer, db.ForeignKey('comment.id'), default = None) + + lastcheck = None + savedresponce = None + def __init__(self, content, postdate): + self.content = content + self.postdate = postdate + + + + + def get_time_string(self): + #this only needs to be calculated every so often, not for every request + #this can be a rudamentary chache + now = datetime.datetime.now() + if self.lastcheck is None or (now - self.lastcheck).total_seconds() > 30: + self.lastcheck = now + else: + return self.savedresponce + + diff = now - self.postdate + seconds = diff.total_seconds() + if seconds / (60 * 60 * 24 * 30) > 1: + self.savedresponce = " " + str(int(seconds / (60 * 60 * 24 * 30))) + " months ago" + elif seconds / (60 * 60 * 24) > 1: + self.savedresponce = " " + str(int(seconds / (60* 60 * 24))) + " days ago" + elif seconds / (60 * 60) > 1: + self.savedresponce = " " + str(int(seconds / (60 * 60))) + " hours ago" + elif seconds / (60) > 1: + self.savedresponce = " " + str(int(seconds / 60)) + " minutes ago" + else: + self.savedresponce = "Just a moment ago!" + return self.savedresponce + + + + + + + + +''' class Comment(db.Model): id = db.Column(db.Integer, primary_key=True) content = db.Column(db.Text) @@ -323,7 +413,7 @@ def get_time_string(self): self.savedresponce = "Just a moment ago!" return self.savedresponce - +''' def init_site(): admin = add_subforum("Forum", "Announcements, bug reports, and general discussion about the forum belongs here") add_subforum("Announcements", "View forum announcements here",admin) @@ -388,7 +478,7 @@ def setup(): for value in siteconfig: interpret_site_value(value) """ - +#db.drop_all() db.create_all() if not Subforum.query.all(): diff --git a/forum/templates/viewpost copy.html b/forum/templates/viewpost copy.html new file mode 100644 index 0000000..3f489ca --- /dev/null +++ b/forum/templates/viewpost copy.html @@ -0,0 +1,77 @@ +{% extends 'layout.html' %} +{% block body %} +{{ path|safe}} + +
+
+ {{post.title}} +
+ {{ post.user.username }} + +
+
+ {{ post.get_time_string() }} +
+
+
+ {{post.content}} +
+ +
+
+
+
+ +
+
+
+ + + + {% if current_user.is_authenticated %} + + + {% else %} + Login or register to make a comment + {% endif %} +
+{%if comments%} +
+{% for comment in comments %} + +
+
+ ({{ comment.user.username }}) - +
+
+ {{ comment.content }} +
+ +
+ {{ comment.get_time_string() }} +
+
+
+ +{% endfor %} +
+{% endif %} + + + +{% endblock %} + + diff --git a/forum/templates/viewpost.html b/forum/templates/viewpost.html index 3f489ca..5c3d17a 100644 --- a/forum/templates/viewpost.html +++ b/forum/templates/viewpost.html @@ -1,7 +1,7 @@ {% extends 'layout.html' %} {% block body %} {{ path|safe}} - +
{{post.title}} @@ -18,8 +18,11 @@
+
-
+ + +
@@ -38,8 +41,10 @@ {%if comments%}
{% for comment in comments %} - -
+ + +
+
({{ comment.user.username }}) -
@@ -47,18 +52,38 @@ {{ comment.content }}
+
{{ comment.get_time_string() }}
+
+
+ +
+ +
+
+ + + +
+ + +
{% endfor %}
{% endif %} + + + + From 725401beae891ec86585de9d3ae46b58f3d936b3 Mon Sep 17 00:00:00 2001 From: Chuck Date: Fri, 23 Jul 2021 14:10:07 -0400 Subject: [PATCH 11/28] user info --- forum/forum.py | 69 +++++++++++++++++++++++++++++++++++ forum/templates/header.html | 4 +- forum/templates/userinfo.html | 30 +++++++++++++++ 3 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 forum/templates/userinfo.html diff --git a/forum/forum.py b/forum/forum.py index 1645346..49f7ee3 100644 --- a/forum/forum.py +++ b/forum/forum.py @@ -40,6 +40,10 @@ def subforum(): def loginform(): return render_template("login.html") +@login_required +@app.route('/userinfo') +def userinfo(): + return render_template("userinfo.html") @login_required @app.route('/addpost') @@ -158,6 +162,71 @@ def action_createaccount(): login_user(user) return redirect("/") +@login_required +@app.route('/action_changeusername', methods=['POST']) +def action_changeusername(): + + id1 = current_user.id + new_username = request.form['username'] + errors = [] + retry = False + if username_taken(new_username): + errors.append("Username is already taken!") + retry=True + if not valid_username(new_username): + errors.append("Username is not valid!") + retry = True + if retry: + return render_template("userinfo.html", errors=errors) + + db.session.query(User).filter(User.id == id1).update({"username": new_username}, synchronize_session="fetch") + db.session.commit() + + return redirect('/userinfo') + +@login_required +@app.route('/action_changeemail', methods=['POST']) +def action_changeemail(): + + id1 = current_user.id + new_email = request.form['email'] + errors = [] + retry = False + if email_taken(new_email): + errors.append("Email is already taken!") + retry=True + if retry: + return render_template("userinfo.html", errors=errors) + + db.session.query(User).filter(User.id == id1).update({"email": new_email}, synchronize_session="fetch") + db.session.commit() + + return redirect('/userinfo') + +@login_required +@app.route('/action_changepassword', methods=['POST']) +def action_changepassword(): + + id1 = current_user.id + ''' + errors = [] + retry = False + input_current_password = request.form['current_password'] + unhashed_password = User.query.filter(User.password_hash == id1) + input_current_password_hashed = generate_password_hash(input_current_password) + if input_current_password_hashed != unhashed_password: + errors.append("Incorrect current password!") + retry=True + if retry: + return render_template("userinfo.html", errors=errors) + ''' + new_password = request.form['new_password'] + new_password_hash = generate_password_hash(new_password) + db.session.query(User).filter(User.id == id1).update({"password_hash": new_password_hash}, synchronize_session="fetch") + db.session.commit() + + return redirect('/userinfo') + def error(errormessage): return "" + errormessage + "" diff --git a/forum/templates/header.html b/forum/templates/header.html index 9403a0d..4ecc123 100644 --- a/forum/templates/header.html +++ b/forum/templates/header.html @@ -1,8 +1,10 @@ {{ config.SITE_NAME }}{% if config.SITE_DESCRIPTION %} - {% endif %} {{ config.SITE_DESCRIPTION }} \ No newline at end of file diff --git a/forum/templates/userinfo.html b/forum/templates/userinfo.html new file mode 100644 index 0000000..f141d7d --- /dev/null +++ b/forum/templates/userinfo.html @@ -0,0 +1,30 @@ +{% extends 'layout.html' %} +{% block body %} + + +
+

Schooner Account

+ Username: {{current_user.username}} +
+
+ +
+
+ Email: {{current_user.email}} +
+
+ +
+
+ Password: +
+
+
+ +
+
+

+ + + +{% endblock %} \ No newline at end of file From 7a0f5296d77bacc938074208d2da5dd9d2363f62 Mon Sep 17 00:00:00 2001 From: AidanFarhi Date: Fri, 23 Jul 2021 14:14:52 -0400 Subject: [PATCH 12/28] aidan commit --- forum/templates/usermessages.html | 1 + 1 file changed, 1 insertion(+) diff --git a/forum/templates/usermessages.html b/forum/templates/usermessages.html index ebfc0de..8397c3f 100644 --- a/forum/templates/usermessages.html +++ b/forum/templates/usermessages.html @@ -6,6 +6,7 @@

Messages

New Message
+
{% for msg in messages %} From c507343a595cd0a3b2ca3b840b3ad5c44bb99366 Mon Sep 17 00:00:00 2001 From: Chuck Date: Fri, 23 Jul 2021 14:43:03 -0400 Subject: [PATCH 13/28] labeling --- forum/forum.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/forum/forum.py b/forum/forum.py index a01557a..6fdf2af 100644 --- a/forum/forum.py +++ b/forum/forum.py @@ -241,7 +241,7 @@ def action_sendmessage(): db.session.commit() return render_template('messagesentsuccess.html') - +#Chuck stuff start @login_required @app.route('/action_changeusername', methods=['POST']) def action_changeusername(): @@ -306,7 +306,7 @@ def action_changepassword(): db.session.commit() return redirect('/userinfo') - +#chuck stuff end def error(errormessage): return "" + errormessage + "" From 58712d8856fb660fe7548ccc89278761c1aa85be Mon Sep 17 00:00:00 2001 From: AidanFarhi Date: Fri, 23 Jul 2021 14:57:20 -0400 Subject: [PATCH 14/28] aidan added Message Class --- forum/forum.py | 47 +++++++++-------------------------------------- 1 file changed, 9 insertions(+), 38 deletions(-) diff --git a/forum/forum.py b/forum/forum.py index d7a7e11..43a1eae 100644 --- a/forum/forum.py +++ b/forum/forum.py @@ -521,49 +521,20 @@ def get_time_string(self): return self.savedresponce +# AIDAN WAS HERE +class DirectMessage(db.Model): - - - - - -''' -class Comment(db.Model): id = db.Column(db.Integer, primary_key=True) - content = db.Column(db.Text) - postdate = db.Column(db.DateTime) - user_id = db.Column(db.Integer, db.ForeignKey('user.id')) - post_id = db.Column(db.Integer, db.ForeignKey("post.id")) + sender_id = db.Column(db.Integer) + receiver_id = db.Column(db.Integer) + body = db.Column(db.String(256)) # limit 256 chars in message - lastcheck = None - savedresponce = None - def __init__(self, content, postdate): - self.content = content - self.postdate = postdate - def get_time_string(self): - #this only needs to be calculated every so often, not for every request - #this can be a rudamentary chache - now = datetime.datetime.now() - if self.lastcheck is None or (now - self.lastcheck).total_seconds() > 30: - self.lastcheck = now - else: - return self.savedresponce + def __init__(self, sender_id, receiver_id, body): + self.sender_id = sender_id + self.receiver_id = receiver_id + self.body = body - diff = now - self.postdate - seconds = diff.total_seconds() - if seconds / (60 * 60 * 24 * 30) > 1: - self.savedresponce = " " + str(int(seconds / (60 * 60 * 24 * 30))) + " months ago" - elif seconds / (60 * 60 * 24) > 1: - self.savedresponce = " " + str(int(seconds / (60* 60 * 24))) + " days ago" - elif seconds / (60 * 60) > 1: - self.savedresponce = " " + str(int(seconds / (60 * 60))) + " hours ago" - elif seconds / (60) > 1: - self.savedresponce = " " + str(int(seconds / 60)) + " minutes ago" - else: - self.savedresponce = "Just a moment ago!" - return self.savedresponce -''' def init_site(): admin = add_subforum("Forum", "Announcements, bug reports, and general discussion about the forum belongs here") add_subforum("Announcements", "View forum announcements here",admin) From 67092c42438a0279af54540932abdae73408fa47 Mon Sep 17 00:00:00 2001 From: Chuck Date: Fri, 23 Jul 2021 15:02:36 -0400 Subject: [PATCH 15/28] fixed logout bug --- forum/templates/header.html | 2 -- 1 file changed, 2 deletions(-) diff --git a/forum/templates/header.html b/forum/templates/header.html index cd0504e..814ffcf 100644 --- a/forum/templates/header.html +++ b/forum/templates/header.html @@ -1,8 +1,6 @@ {{ config.SITE_NAME }}{% if config.SITE_DESCRIPTION %} - {% endif %} {{ config.SITE_DESCRIPTION }}
-
+
From 4458943bf4e3ff664bf86bad6970490bb71864c6 Mon Sep 17 00:00:00 2001 From: Sean Date: Fri, 23 Jul 2021 18:49:19 -0400 Subject: [PATCH 17/28] commit after demo --- .DS_Store | Bin 6148 -> 6148 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/.DS_Store b/.DS_Store index 5561818c848113912ea635bdc369d8ddadb95588..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 100644 GIT binary patch delta 62 zcmZoMXfc=|#>AjHu~2NHo+2v)5HM~`T*bUufrFi8Gb@K62T*deAjfy+$^0UUjEs{_ QMU*G|^KfjA5m~_u0KiTTI{*Lx literal 6148 zcmeHK!EVzq82-IwTQWfOFljsHg2bV!+QH~yLMo*@?0_^;1P4G{vz9he8jm(^`}@{cQ!V+T+eg8Ti)yT zKu+69CrQW6&gi8ooph2xVEkuNMoYgFJP&)*)6&jk87G}E?v0onc6$hU^&*VBa@v$> z+#Pd2ZQZ~FotE}yv;BIl?C&2O%*+0)Uayw@`}ZEq=bpQJr}pspZ211e?Bo2?SC)tb zHbS=B1~1_ooXiv_?NJ=bxQ|-JaOnhMN;-#JAw@-5Ni9WIERUYj5j~<7Jpoo|NZq`= zybxJNNi7z=r4;=uZ-^9ALSwKKdRJV0@wqVKCRiyL6)*;cv3?a|9hz|OlYAU6dG>`` z#$DG1Urw;F+|X+U%)F}ZjTLwn`v_J6tH5e0p!NqJNnyj_LL+Y-$oL8XbWqI(pMU*< zzN!E=3@$XH1|~EWsHwtSF@(7}2u(+O!^AH%YB~uX8U2`%g}I>!bMX*9hm&Y%w7FHl zDv(!TT^CF0{6G5l{Xb8#C98l{;94mloL0Nl#FWh0dS!Czto4!3kd&#og+`_zGsiJI f>L}hrVnds+9ALxXLL+Km_D6tau$fihzbfzt=o0%X From 68d0d5a5f312393d1513caaa4cce113484ec92a0 Mon Sep 17 00:00:00 2001 From: Sean Date: Fri, 23 Jul 2021 18:50:58 -0400 Subject: [PATCH 18/28] first commit after demo --- .DS_Store | Bin 0 -> 6148 bytes forum/.DS_Store | Bin 0 -> 6148 bytes forum/app.py | 4 +- forum/forum.py | 233 ++++++++++++++++++++++-- forum/templates/createmessage.html | 18 ++ forum/templates/header.html | 7 +- forum/templates/messagesentsuccess.html | 6 + forum/templates/userinfo.html | 30 +++ forum/templates/usermessages.html | 21 +++ forum/templates/viewpost copy.html | 77 ++++++++ forum/templates/viewpost.html | 53 +++++- 11 files changed, 431 insertions(+), 18 deletions(-) create mode 100644 .DS_Store create mode 100644 forum/.DS_Store create mode 100644 forum/templates/createmessage.html create mode 100644 forum/templates/messagesentsuccess.html create mode 100644 forum/templates/userinfo.html create mode 100644 forum/templates/usermessages.html create mode 100644 forum/templates/viewpost copy.html diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f29477f8fcea406db08597f6b3b5d0e82c252e38 GIT binary patch literal 6148 zcmeHK%}xR_5N`R=-54VW6FK(cjRT;_$z+3g@Mf|`4{BgHi?Ru92`p|DG5Z?&Mm~YB z<4ju!1Wh~{BQweLn@(ri^xI9RWsLF0IH)jIV2oLyh#4E2F9gR?S0rORh+NIl_mk1U z?@50pmK=YR0sMA(cE=|$d>?Ezi?um?IFN``vl^g~g2)Vfmqd+DNIgWynn#a`xYN1x4 zIGI%Im6E8|YSWUK)a&JvI6OF-PHk&%zjA!m?ms?Fo~JLbnpqCNppqSfGk61IVT%v$ zFzU(Z9=x-RStKDbKnxHAYr=pz{;aJv*)MIA7$63I&H$bd0u<3Pm}*o<2Q+wn#PJ*= z3fTCTKokZYgQ-Rs0pU6oP^WV9#Nav|{KCXJ22+hXopH4?%wtyO=7qx5>fjeDoN-4Z zwZs51u*^VKcMDkmPrrZvFDFrt7$64z6$3oibej#>lBumLo5NZwK--`w7?*0Cr+}eK gF~njiE`llnzd!@fF_>xu4+vcZ6b;l61Ha0^C%jitOaK4? literal 0 HcmV?d00001 diff --git a/forum/.DS_Store b/forum/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..ad012cd53c99054aa31addf49091550de4191c6f GIT binary patch literal 6148 zcmeHKL5|Zf6#bqlC1Hf<0%>NM4HAnAwF5&JBc!Mdi`gLs!2(bxX#&_-|zf1mBT2N5i)prIELT;p$yTA zmD8Mt6vD?8b3ZlKml~^y+#DCL5VaA+el6FbS0rgdQ##+8|Dl%OqypjDB-U6(go%ouTIY@xpw!FrrzJ8->0`d72bur}Ith>^816uR5;lxYym6!C20M zGAyS>Kb$=0yT@TUj!gVS%Jf$pMo*J?HfY^^D6=w5vUsA%$tXt3i)TqTlC!>?W}`y& z6X*st(4cj&SRD4cZSU~tXxa7_y`i+9WSpCANGV8K>) z!{7=&BiJ(4H^C%JW%e4aE9Qz}@scWFUZk^kNuS?7wpG9?@aGiZ^}&NP`UWeFYUx0s zjsU<0s+A$;p9SW427QB-Mzp|$rUErpm?MVJbkut$&o@|U)N~T&@FC2|!kkcq8Xf(6 zDxHL{(Uw*LtH8PfyZW}p`~Rcgpa0iM_RcC`75J|d5RH@Iq>m|?y>(-9yw`g0GdLUP nRT>oqh1rf(z+3SFTp8Lt4uHPFN+W7u_D4X;U<<3jUsd2InP8(7 literal 0 HcmV?d00001 diff --git a/forum/app.py b/forum/app.py index 1521375..2072b35 100644 --- a/forum/app.py +++ b/forum/app.py @@ -6,5 +6,7 @@ SECRET_KEY=b'kristofer', SITE_NAME = "Schooner", SITE_DESCRIPTION = "a schooner forum", - SQLALCHEMY_DATABASE_URI='sqlite:////tmp/database.db' + SQLALCHEMY_DATABASE_URI='sqlite:////tmp/database.db' #relative pass to physical db location (this has 4 /) ) + + diff --git a/forum/forum.py b/forum/forum.py index 1645346..43a1eae 100644 --- a/forum/forum.py +++ b/forum/forum.py @@ -1,7 +1,9 @@ +# kill -9 40614 from flask import * #from flask.ext.login import LoginManager, login_required, current_user, logout_user, login_user from flask_login import LoginManager, current_user, login_user, logout_user import datetime +import sys from flask_login.utils import login_required from forum.app import app @@ -25,7 +27,7 @@ def index(): @app.route('/subforum') def subforum(): - subforum_id = int(request.args.get("sub")) + subforum_id = int(request.args.get("sub")) subforum = Subforum.query.filter(Subforum.id == subforum_id).first() if not subforum: return error("That subforum does not exist!") @@ -40,6 +42,10 @@ def subforum(): def loginform(): return render_template("login.html") +@login_required +@app.route('/userinfo') +def userinfo(): + return render_template("userinfo.html") @login_required @app.route('/addpost') @@ -53,32 +59,96 @@ def addpost(): @app.route('/viewpost') def viewpost(): - postid = int(request.args.get("post")) + postid = int(request.args.get("post")) # provides dictionary of the post table post = Post.query.filter(Post.id == postid).first() if not post: return error("That post does not exist!") if not post.subforum.path: subforum.path = generateLinkPath(post.subforum.id) comments = Comment.query.filter(Comment.post_id == postid).order_by(Comment.id.desc()) # no need for scalability now + # how you access the database + return render_template("viewpost.html", post=post, path=subforum.path, comments=comments) +# Route to get all private messages for current user +@login_required +@app.route('/get_messages_for_user') +def get_messages_for_user(): + messages = DirectMessage.query.filter_by(receiver_id=current_user.id) + senders = get_sending_usernames(messages) + return render_template('usermessages.html', messages=messages, senders=senders) + +@login_required +@app.route('/createmessage') +def createmessage(): + return render_template('createmessage.html') + +def get_sending_usernames(msgs): + ''' + Returns a dict of: {key: sender_id, value: sender_username} + ''' + sending_usernames = {} + for msg in msgs: + user = User.query.filter_by(id=msg.sender_id).first() + if msg.sender_id not in sending_usernames: + sending_usernames[msg.sender_id] = user.username + return sending_usernames + #ACTIONS @login_required @app.route('/action_comment', methods=['POST', 'GET']) +# '/action_comment' is how viewpost.html calls comment() def comment(): - post_id = int(request.args.get("post")) - post = Post.query.filter(Post.id == post_id).first() + post_id = int(request.args.get("post")) # goes to the post table and gets the post_id + # .args.get("post") is from html + # ?post = {{post.id}} + post = Post.query.filter(Post.id == post_id).first() # checks to make sure post id exists and returns the first + # a query is a select statement + if not post: return error("That post does not exist!") content = request.form['content'] + + # Like button + like_counter = 0 + if request.method == 'POST': + if request.form.get('action1') == 'Like': + print('hello') + + + # replaces key word with emoji + if '*wink*' in content: + content = content.replace('*wink*', '\U0001F609') + if '*smile*' in content: + content = content.replace('*smile*', '\U0001F600') + if '*like*' in content: + content = content.replace('*like*', '\U0001F44D') + + postdate = datetime.datetime.now() + + comment = Comment(content, postdate) + # this creates an instance of comment current_user.comments.append(comment) - post.comments.append(comment) + # inserts comment into users table + post.comments.append(comment) #go to the post table, go to the comments column, and then add the comment db.session.commit() return redirect("/viewpost?post=" + str(post_id)) + +# create a route that sets passes a ?id= {{comment.id}} method = 'POST' +# grab parent comment id with int(request.args.get(comment.id)) +# make sure route name is unique +# 1) make sure you're getting all data in form +# 2) putting data into the database + +@login_required +@app.route('/comment_comment', methods = ['POST', 'GET']) +def comment_comment(): + pass + @login_required @app.route('/action_post', methods=['POST']) def action_post(): @@ -90,6 +160,20 @@ def action_post(): user = current_user title = request.form['title'] content = request.form['content'] + + # replaces key word with emoji + if '*wink*' in content or '*wink*' in title: + content = content.replace('*wink*', '\U0001F609') + title = title.replace('*wink*', '\U0001F609') + if '*smile*' in content or '*smile*' in title: + content = content.replace('*smile*', '\U0001F600') + title = title.replace('*smile*', '\U0001F600') + if '*like*' in content or '*like*' in title: + content = content.replace('*like*', '\U0001F44D') + title = title.replace('*like*', '\U0001F44D') + + + #check for valid posting errors = [] retry = False @@ -108,6 +192,7 @@ def action_post(): return redirect("/viewpost?post=" + str(post.id)) + @app.route('/action_login', methods=['POST']) def action_login(): username = request.form['username'] @@ -158,6 +243,96 @@ def action_createaccount(): login_user(user) return redirect("/") + +# Action to send a message +@login_required +@app.route('/action_sendmessage', methods=['POST']) +def action_sendmessage(): + errors = [] + receiver_username = request.form['username'] + message_body = request.form['message_body'] + # check is user exists + user = User.query.filter_by(username=receiver_username).first() + if user is None: + errors.append('User does not exist') + return render_template('createmessage.html', errors=errors) + # check if message is empty + if len(message_body) == 0: + errors.append('Cannot send empty message') + return render_template('createmessage.html', errors=errors) + # create new message and commit to database + new_message = DirectMessage(current_user.id, user.id, message_body) + db.session.add(new_message) + db.session.commit() + return render_template('messagesentsuccess.html') + +#Chuck stuff start +@login_required +@app.route('/action_changeusername', methods=['POST']) +def action_changeusername(): + + id1 = current_user.id + new_username = request.form['username'] + errors = [] + retry = False + if username_taken(new_username): + errors.append("Username is already taken!") + retry=True + if not valid_username(new_username): + errors.append("Username is not valid!") + retry = True + if retry: + return render_template("userinfo.html", errors=errors) + + db.session.query(User).filter(User.id == id1).update({"username": new_username}, synchronize_session="fetch") + db.session.commit() + + return redirect('/userinfo') + +@login_required +@app.route('/action_changeemail', methods=['POST']) +def action_changeemail(): + + id1 = current_user.id + new_email = request.form['email'] + errors = [] + retry = False + if email_taken(new_email): + errors.append("Email is already taken!") + retry=True + if retry: + return render_template("userinfo.html", errors=errors) + + db.session.query(User).filter(User.id == id1).update({"email": new_email}, synchronize_session="fetch") + db.session.commit() + + return redirect('/userinfo') + +@login_required +@app.route('/action_changepassword', methods=['POST']) +def action_changepassword(): + + id1 = current_user.id + ''' + errors = [] + retry = False + input_current_password = request.form['current_password'] + unhashed_password = User.query.filter(User.password_hash == id1) + input_current_password_hashed = generate_password_hash(input_current_password) + if input_current_password_hashed != unhashed_password: + errors.append("Incorrect current password!") + retry=True + if retry: + return render_template("userinfo.html", errors=errors) + ''' + new_password = request.form['new_password'] + new_password_hash = generate_password_hash(new_password) + db.session.query(User).filter(User.id == id1).update({"password_hash": new_password_hash}, synchronize_session="fetch") + db.session.commit() + + return redirect('/userinfo') +#chuck stuff end + def error(errormessage): return "" + errormessage + "" @@ -275,31 +450,53 @@ def get_time_string(self): return self.savedresponce +# a 'Subforum' model is a table, and all the models make up the database +# a model's attributes are its columns when defined with db.Column + +# so below we have the subforum model +# the order is id, title, description, parent_id +# id is the primary key +# title, description are columns +# parent_id sets subforum.id as the parent key +# subforums has a r + + class Subforum(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.Text, unique=True) description = db.Column(db.Text) subforums = db.relationship("Subforum") parent_id = db.Column(db.Integer, db.ForeignKey('subforum.id')) - posts = db.relationship("Post", backref="subforum") + posts = db.relationship("Post", backref="subforum") # Post's table is going to get a virtual column of subforum path = None hidden = db.Column(db.Boolean, default=False) def __init__(self, title, description): self.title = title self.description = description + +# order is id, content, postdate, user_id, post_id +# we set parent_comment_id as the hcild key, id as the parent_key + class Comment(db.Model): - id = db.Column(db.Integer, primary_key=True) - content = db.Column(db.Text) + id = db.Column(db.Integer, primary_key=True) # every comment gets a primary key + content = db.Column(db.Text) # body postdate = db.Column(db.DateTime) - user_id = db.Column(db.Integer, db.ForeignKey('user.id')) - post_id = db.Column(db.Integer, db.ForeignKey("post.id")) + user_id = db.Column(db.Integer, db.ForeignKey('user.id')) # lower case looks at a table, upper case looks at a class + post_id = db.Column(db.Integer, db.ForeignKey("post.id")) # parent article + + comments = db.relationship("Comment") # relates to + parent_comment_id = db.Column(db.Integer, db.ForeignKey('comment.id'), default = None) lastcheck = None savedresponce = None def __init__(self, content, postdate): self.content = content self.postdate = postdate + + + + def get_time_string(self): #this only needs to be calculated every so often, not for every request #this can be a rudamentary chache @@ -324,6 +521,20 @@ def get_time_string(self): return self.savedresponce +# AIDAN WAS HERE +class DirectMessage(db.Model): + + id = db.Column(db.Integer, primary_key=True) + sender_id = db.Column(db.Integer) + receiver_id = db.Column(db.Integer) + body = db.Column(db.String(256)) # limit 256 chars in message + + def __init__(self, sender_id, receiver_id, body): + self.sender_id = sender_id + self.receiver_id = receiver_id + self.body = body + + def init_site(): admin = add_subforum("Forum", "Announcements, bug reports, and general discussion about the forum belongs here") add_subforum("Announcements", "View forum announcements here",admin) @@ -388,7 +599,7 @@ def setup(): for value in siteconfig: interpret_site_value(value) """ - +#db.drop_all() db.create_all() if not Subforum.query.all(): diff --git a/forum/templates/createmessage.html b/forum/templates/createmessage.html new file mode 100644 index 0000000..710c99f --- /dev/null +++ b/forum/templates/createmessage.html @@ -0,0 +1,18 @@ +{% extends 'layout.html' %} +{% block body %} + +

Send Message

+
+ +
+ + +
+
+ + +
+
+ + +{% endblock %} \ No newline at end of file diff --git a/forum/templates/header.html b/forum/templates/header.html index 9403a0d..814ffcf 100644 --- a/forum/templates/header.html +++ b/forum/templates/header.html @@ -1,7 +1,12 @@ {{ config.SITE_NAME }}{% if config.SITE_DESCRIPTION %} - {% endif %} {{ config.SITE_DESCRIPTION }}