From: Perfectfire33 Date: Mon, 11 Jul 2022 23:59:28 +0000 (-0400) Subject: Added Messages X-Git-Url: http://openhouseparty.us:13001/gitweb/?a=commitdiff_plain;h=64a6b14266e8f198accb327a94983c024198c548;p=openhouseparty.online%2F.git Added Messages Messages are created with the Contact Us form --- 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 d3003e3..9df37b5 100644 Binary files a/flaskr/__pycache__/admin.cpython-37.pyc and b/flaskr/__pycache__/admin.cpython-37.pyc differ diff --git a/flaskr/__pycache__/auth.cpython-37.pyc b/flaskr/__pycache__/auth.cpython-37.pyc index 5632a2f..4727e2d 100644 Binary files a/flaskr/__pycache__/auth.cpython-37.pyc and b/flaskr/__pycache__/auth.cpython-37.pyc differ diff --git a/flaskr/__pycache__/contact_us.cpython-37.pyc b/flaskr/__pycache__/contact_us.cpython-37.pyc index 779a853..7d88ef8 100644 Binary files a/flaskr/__pycache__/contact_us.cpython-37.pyc and b/flaskr/__pycache__/contact_us.cpython-37.pyc differ 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 3235b5a..ad0d3a9 100644 Binary files a/instance/flaskr.sqlite and b/instance/flaskr.sqlite differ