From 64a6b14266e8f198accb327a94983c024198c548 Mon Sep 17 00:00:00 2001 From: Perfectfire33 Date: Mon, 11 Jul 2022 19:59:28 -0400 Subject: [PATCH] Added Messages Messages are created with the Contact Us form --- .idea/workspace.xml | 206 ++++++++++--------- flaskr/__pycache__/admin.cpython-37.pyc | Bin 2334 -> 2950 bytes flaskr/__pycache__/auth.cpython-37.pyc | Bin 2488 -> 2628 bytes flaskr/__pycache__/contact_us.cpython-37.pyc | Bin 497 -> 1069 bytes flaskr/admin.py | 23 ++- flaskr/contact_us.py | 49 ++++- flaskr/schema.sql | 43 ++-- flaskr/templates/admin/admin.html | 1 + flaskr/templates/admin/messages.html | 21 ++ instance/flaskr.sqlite | Bin 143360 -> 147456 bytes 10 files changed, 229 insertions(+), 114 deletions(-) create mode 100644 flaskr/templates/admin/messages.html diff --git a/.idea/workspace.xml b/.idea/workspace.xml index cc51bf2..0d128af 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,14 +2,12 @@ + - - - - - - + + + - - - - - - - @@ -510,13 +507,6 @@ - - - - - - - @@ -624,13 +614,6 @@ - - - - - - - @@ -673,13 +656,6 @@ - - - - - - - @@ -687,81 +663,115 @@ - + - - + + - + - - + + - + - - + + - + - - + + - + - - + + - - + + - + - - + + + + + - + - - + + - + - - + + + + + - + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/flaskr/__pycache__/admin.cpython-37.pyc b/flaskr/__pycache__/admin.cpython-37.pyc index d3003e3690b8674b476c850417e01209a883e3ef..9df37b58b993b0147c6bc4d6cff61155db0aef72 100644 GIT binary patch delta 549 zcmbOy)F#g7#LLUY00f0w&Lo}Vp2#P`_-Ug0VUtvW1%fH!3mH>6QzTL(TNs)dn;E0T zQw6dFQ>0RO(-~9vdYMwBQ)ECgQ4%S#!3>&m8$X1y^Hy={=cX1HC#I(sCo@bgU=f)d z&!kZw73}Kc>Kvi~m5R?y(Sft`5_3}#ywu#p%p3%_xHKs%HMs;Kkd&WNso)mm?+epk zC7hU&o0$i!ATJgPfe2v`!3HEWnTkX}Y>mkeIfPAk(o;*~ zVLF0=;>8?5f`OThk%f_qrAQOVuHuK;5ucKplUkBGxq{iJUc&|Gvk+GlCnHRf~|smlpxIWCHYVTs)WE!*F&~jlf4MxSazVbMG_!F5=5|q2#~up86j@xW0-8q z!mGsxaSzP>aX=Nt;7DZxIbVQ@gRw{pDCVarIoX3_1{=sTMOu^ZaHuKC0hubyJd8X* YRb0#*jC?FW%q79e!7aeZrwn2P0O(JSx&QzG delta 80 zcmZn@pC`oU#LLUY00aU$r;_S9C-O-!9+{|qm@P#-m_buwvm9e6JF}mr_~Zp#GbTH6 gE6GRzm8vlFF!C@8FmW++F!HegF_#1<2e$wt0HUuAX#fBK diff --git a/flaskr/__pycache__/auth.cpython-37.pyc b/flaskr/__pycache__/auth.cpython-37.pyc index 5632a2f729af3dae0c3e9b7de9b7e15ffa4e95b8..4727e2d31f116a54df5d941b1ec3e1dad1573948 100644 GIT binary patch delta 888 zcmYk4&ubGw6vt;K`(u)BLQQ{|T5Y${hQ?Nl-n>|<^yCkOQroDwB+ORQA4z<>H7Xk_ z6M;<5PNhT3j+KYZW!y?OH{%$I?0gV{^jY=+@; zr}(3`_c8mHZ`&A2{4V1cd`E7tnCja}b*u_&(GzK ziRD({L!-Ls$Ffxof_4*BoL;R%5R!Q$mK)Wcj7@*DTHnx5#4K;?58~YXjQfxld;hEV zjr}G2ak8-N-kiU>w6N$-&CR&ISN|3-%Qob34j3Q|5{3xFh*+o^?h4R^_YB7L>r}-# zi#`(>PCvbuI+hz04)5oA;Rq?f{Zuk;^ZujMp+Im5Bl?9oS2|Ae1R^$QY8az9!8n=b zM)O|1abEv5r+G;ittD#$?Z+kk$8hzIRX9CK^}T+iP9nYuW< zdOnL~o@IJix&dm1>JIC`sGKuSngv0O~{yFyQ zUlSjBUdPDBa|2KC0THr&E_p}5q57?tp0ePQ)JIy^j(Bic8Y3;zB5#^WA%mC*=}inD zpa-8BV;7jU@xnZ6|`AJQUjIwH23(X4EpZL+OjA-y}i@e;n{NFBf z&}&H-J@| zvE*3`meu{3*F2Bf#CF|o>w)jO6XEqI2H^8P6v9;HBeq!noq8bumqVmC=Uo(Z-`qS0g( zwydwg{6v3=+IUi<0ta)_XP{PjEC@)7!Djf+NsJcgk@ z05HUGh6IkWATbe6>o*FyfdwJe-rb$(zSZj53#bL&E$o zgaxee8O?FL%)%~;nt#DNihR>}nw5Ma$GJA{QPx)@gNG)NoQ)+PXtOGL&bUl87n7{7 zx$!0cSaPL}U&<^wDrAI>H{?2DsR;)~uKNR>lxo_%e`y%!#m<4D`+MC3SnUh0M+H*@ z8-Z;e49Ei7hM~R#XmpGjJ|XfOFv7?Nnpur72NB(;>2$3FbFHyz*>piFS$n#^V;5f6 zZgv;DuB#hwxl;WhZ&_E@r`T?%yYud#wc9z^Yl-t^o98640o}WhlRB_V^E|*y!FrEc z@1MLm-08M9AKh!6f6=rtDgR##>a;P`Cm@Hmv0HPkd0q9q|T* z5MwQEVWk5Qd2+?_RSP#PtN}pkq%5Q%Ed7b(El~cw-hR+KR9vdwt3vU~sQ0WGl!E74 z^*lmJ`qF`mlx9p#kb$ypEk@sU~GiI4`n8SrRK{`Q3FfbMI07*Yh zp2=&NwOns;#K-3)=BCES-(pHCxW!tOUs{q1Rsq!wR10Bo16j8?Y;yBcN^?@}Kt>g_ K00|WqE@lAqT04FK diff --git a/flaskr/admin.py b/flaskr/admin.py index 3bbcedb..48ad0e1 100644 --- a/flaskr/admin.py +++ b/flaskr/admin.py @@ -77,4 +77,25 @@ def update_user(user_id): db.commit() return redirect(url_for('admin.index')) - return render_template('admin/user_edit.html', user=user) \ No newline at end of file + return render_template('admin/user_edit.html', user=user) + + +@bp.route('/messages') +@login_required +def get_messages(): + db = get_db() + messages = db.execute( + 'SELECT message_id, message_name, message_email, message_subject, message_body' + ' FROM message' + ).fetchall() + + return render_template('admin/messages.html', messages=messages) + +@bp.route('/message_delete', methods=['POST']) +def delete_message(): + db = get_db() + db.execute( + 'DELETE FROM message WHERE message_id = ?', [request.form['message_to_delete']] + ) + db.commit() + return redirect(url_for('admin.get_messages')) \ No newline at end of file diff --git a/flaskr/contact_us.py b/flaskr/contact_us.py index f558908..8f3b8f0 100644 --- a/flaskr/contact_us.py +++ b/flaskr/contact_us.py @@ -2,10 +2,55 @@ from flask import ( Blueprint, flash, g, redirect, render_template, request, url_for ) +# import smtplib +from flaskr.db import get_db bp = Blueprint('contact_us', __name__) #Display Data - About -@bp.route('/contact_us') +@bp.route('/contact_us', methods=['GET', 'POST']) def index(): - return render_template('contact_us.html') \ No newline at end of file + if request.method == 'POST': + + name = request.form['name'] + email = request.form['email'] + subject = request.form['subject'] + body = request.form['body'] + + #message = "Thank you!" + + #server = smtplib.SMTP("smtp.gmail.com", 587) + #server.starttls() + # set environmental variable here for password + #server.login('chas@gmail.com', 'password') + #send email from server to person who filled out the contact us form + #server.sendmail('chas@gmail.com', email, message) + error = None + db = get_db() + if not name: + error = 'Name is required.' + elif not email: + error = 'Email is required.' + elif not subject: + error = 'Subject is required.' + elif not body: + error = 'Message body is required.' + + if error is None: + db.execute( + 'INSERT INTO message (message_name, message_email, message_subject, message_body) VALUES (?, ?, ?, ?)', + [name, email, subject, body] + ) + db.commit() + + return render_template('home.html') + else: + flash(error) + + + return render_template('contact_us.html') + + +#create messages within the flaskr app: messages from people filling out contact_us form +#add a new message to the sqlite database when a user hits submit on the web form +#this way, we don't need to send an email from chas@gmail.com to chas@gmail.com essentially \ No newline at end of file diff --git a/flaskr/schema.sql b/flaskr/schema.sql index 634b8ab..6a82113 100644 --- a/flaskr/schema.sql +++ b/flaskr/schema.sql @@ -16,6 +16,23 @@ create table xuser ( xuser_email ); +drop table if exists item; +create table item ( + item_id integer primary key autoincrement, + item_name text not null, + item_price numeric not null, + item_description text not null +); + +drop table if exists message; +create table message ( + message_id integer primary key autoincrement, + message_name text not null, + message_email text not null, + message_subject text not null, + message_body text not null +); + drop table if exists post; CREATE TABLE post ( post_id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -33,19 +50,19 @@ CREATE TABLE post ( --Basic info about an item -drop table if exists item; -create table item ( - item_id integer primary key autoincrement, - item_name text, - item_subtitle text, - item_desc text, - item_category text, - item_condition text, - item_conditionDesc text, - item_cost numeric, - item_returnPolicyDesc text, - item_insertDate datetime -); +--drop table if exists item; +--create table item ( +-- item_id integer primary key autoincrement, +-- item_name text, +-- item_subtitle text, +-- item_desc text, +-- item_category text, +-- item_condition text, +-- item_conditionDesc text, +-- item_cost numeric, +-- item_returnPolicyDesc text, +-- item_insertDate datetime +--); --File Upload/Download Data diff --git a/flaskr/templates/admin/admin.html b/flaskr/templates/admin/admin.html index 7b3a15a..0c58dc6 100644 --- a/flaskr/templates/admin/admin.html +++ b/flaskr/templates/admin/admin.html @@ -3,4 +3,5 @@

Admin Panel


User List

+

Messages

{% endblock %} \ No newline at end of file diff --git a/flaskr/templates/admin/messages.html b/flaskr/templates/admin/messages.html new file mode 100644 index 0000000..74f0707 --- /dev/null +++ b/flaskr/templates/admin/messages.html @@ -0,0 +1,21 @@ +{% extends "base.html" %} +{% block content %} +

Admin Panel

+

Messages

+
+ {% for message in messages %} +
+
+ Person's Name: {{ message.message_name }} +
Person's Email Address: {{ message.message_email }} +
Message Subject: {{ message.message_subject }} +
Message Body:
{{ message.message_body }} +
+ + +
+
+
+ {% endfor %} +
+{% endblock %} \ No newline at end of file diff --git a/instance/flaskr.sqlite b/instance/flaskr.sqlite index 3235b5afa3a53ac49563ad2042bd79a367258a80..ad0d3a9eda3e7713b45d5500da197b3b94a5f47a 100644 GIT binary patch delta 1167 zcmaJ=Uu;uV7(d^=r|WHR+p|vCzcO}UV`D9_wOzXn4O3&szlD( zK|(dzm+D$Q`Lm7nCxZJj-lKy9sb*hSpex?tk1G*hAgaccShUj{4@5g+s@l^L^L0l9 ziZ{~Z3wCt*Nx zN?Ar^83|;Gk8j9QVHI5>gcF$DMC32>2U#RH3(lc=Qb!h%496x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