From 9c46cb0b19380cedfea29acd8cda61d76a0bb1ca Mon Sep 17 00:00:00 2001 From: snehas-05 Date: Tue, 22 Oct 2024 14:44:05 +0000 Subject: [PATCH 1/3] commit changes --- 5star_review_system/app.py | 52 ++++++++++++++++++ 5star_review_system/db_config.sql | 12 +++++ 5star_review_system/requirements.txt | 2 + 5star_review_system/satic/app.js | 33 ++++++++++++ 5star_review_system/satic/styles.css | 68 ++++++++++++++++++++++++ 5star_review_system/templates/index.html | 62 +++++++++++++++++++++ 6 files changed, 229 insertions(+) create mode 100644 5star_review_system/app.py create mode 100644 5star_review_system/db_config.sql create mode 100644 5star_review_system/requirements.txt create mode 100644 5star_review_system/satic/app.js create mode 100644 5star_review_system/satic/styles.css create mode 100644 5star_review_system/templates/index.html diff --git a/5star_review_system/app.py b/5star_review_system/app.py new file mode 100644 index 0000000..d8075ef --- /dev/null +++ b/5star_review_system/app.py @@ -0,0 +1,52 @@ +from flask import Flask, render_template, request, jsonify +import mysql.connector +from datetime import datetime + +app = Flask(__name__) + +# MySQL configuration +db_config = { + 'host': 'localhost', + 'user': 'root', + 'password': 'password', + 'database': 'dataverse' +} + +def get_db_connection(): + conn = mysql.connector.connect(**db_config) + return conn + +@app.route('/') +def index(): + # Fetch reviews from the database + conn = get_db_connection() + cursor = conn.cursor(dictionary=True) + cursor.execute('SELECT * FROM reviews ORDER BY timestamp DESC') + reviews = cursor.fetchall() + conn.close() + + return render_template('index.html', reviews=reviews) + +@app.route('/submit-review', methods=['POST']) +def submit_review(): + data = request.get_json() + + name = data['name'] + email = data['email'] + rating = int(data['rating']) + review_text = data['review'] + timestamp = datetime.now() + + conn = get_db_connection() + cursor = conn.cursor() + cursor.execute( + 'INSERT INTO reviews (name, email, rating, review, timestamp) VALUES (%s, %s, %s, %s, %s)', + (name, email, rating, review_text, timestamp) + ) + conn.commit() + conn.close() + + return jsonify({'success': True}) + +if __name__ == '__main__': + app.run(debug=True) diff --git a/5star_review_system/db_config.sql b/5star_review_system/db_config.sql new file mode 100644 index 0000000..ea2e6a6 --- /dev/null +++ b/5star_review_system/db_config.sql @@ -0,0 +1,12 @@ +CREATE DATABASE IF NOT EXISTS dataverse; + +USE dataverse; + +CREATE TABLE IF NOT EXISTS reviews ( + id INT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(255), + email VARCHAR(255), + rating INT, + review TEXT, + timestamp DATETIME +); diff --git a/5star_review_system/requirements.txt b/5star_review_system/requirements.txt new file mode 100644 index 0000000..6c4e10c --- /dev/null +++ b/5star_review_system/requirements.txt @@ -0,0 +1,2 @@ +Flask==2.0.2 +mysql-connector-python==8.0.26 diff --git a/5star_review_system/satic/app.js b/5star_review_system/satic/app.js new file mode 100644 index 0000000..3db1616 --- /dev/null +++ b/5star_review_system/satic/app.js @@ -0,0 +1,33 @@ +const form = document.getElementById('ratingForm'); + +form.addEventListener('submit', async function (event) { + event.preventDefault(); + + const formData = new FormData(form); + const data = { + name: formData.get('name'), + email: formData.get('email'), + rating: formData.get('rating'), + review: formData.get('review') + }; + + const response = await fetch('/submit-review', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(data), + }); + + const result = await response.json(); + + const messageElement = document.getElementById('responseMessage'); + if (result.success) { + messageElement.textContent = "Thank you for your review!"; + messageElement.style.color = 'green'; + form.reset(); + } else { + messageElement.textContent = "There was an error submitting your review."; + messageElement.style.color = 'red'; + } +}); diff --git a/5star_review_system/satic/styles.css b/5star_review_system/satic/styles.css new file mode 100644 index 0000000..39817ea --- /dev/null +++ b/5star_review_system/satic/styles.css @@ -0,0 +1,68 @@ +body { + font-family: Arial, sans-serif; + background-color: #f9f9f9; + color: #333; +} + +.container { + max-width: 700px; + margin: 0 auto; + padding: 20px; + background-color: white; + box-shadow: 0 0 15px rgba(0, 0, 0, 0.1); +} + +h1, h2 { + text-align: center; +} + +form { + margin-bottom: 40px; +} + +label { + font-weight: bold; +} + +input, textarea, button { + width: 100%; + margin-bottom: 15px; + padding: 10px; + border: 1px solid #ccc; + border-radius: 5px; +} + +.rating { + display: flex; + justify-content: center; + margin-bottom: 15px; +} + +.rating input { + display: none; +} + +.rating label { + font-size: 2rem; + color: #ddd; + cursor: pointer; +} + +.rating input:checked ~ label { + color: #f7c41c; +} + +button { + background-color: #4CAF50; + color: white; + border: none; + cursor: pointer; +} + +.review { + margin-bottom: 20px; +} + +.review p { + margin: 5px 0; +} diff --git a/5star_review_system/templates/index.html b/5star_review_system/templates/index.html new file mode 100644 index 0000000..ac126f6 --- /dev/null +++ b/5star_review_system/templates/index.html @@ -0,0 +1,62 @@ + + + + + + Dataset Rating and Reviews + + + + +
+

Rate Dataverse

+ +
+ + + + + + + +
+ + + + + + + + + + +
+ + + + + +
+ +
+ +
+ +

Recent Reviews

+
+ {% for review in reviews %} +
+

{{ review.name }} rated {{ review.rating }}/5

+

{{ review.review }}

+

Submitted on: {{ review.timestamp }}

+
+
+ {% endfor %} +
+ +
+ + + + + From 762f72b341893291bd027de5dc0b7ba85954fc09 Mon Sep 17 00:00:00 2001 From: snehas-05 Date: Tue, 22 Oct 2024 14:48:02 +0000 Subject: [PATCH 2/3] commit --- 5star_review_system/templates/index.html | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/5star_review_system/templates/index.html b/5star_review_system/templates/index.html index ac126f6..bc9b0d2 100644 --- a/5star_review_system/templates/index.html +++ b/5star_review_system/templates/index.html @@ -54,9 +54,8 @@

Recent Reviews

{% endfor %} - - + From 65df151a0f690c1c4119db167b7af5fce3426036 Mon Sep 17 00:00:00 2001 From: snehas-05 Date: Mon, 28 Oct 2024 17:39:05 +0000 Subject: [PATCH 3/3] commit changes --- 5star_review_system/satic/app.js | 40 ++++++++------ 5star_review_system/satic/styles.css | 68 ------------------------ 5star_review_system/templates/index.html | 61 --------------------- index.html | 37 +++++++++++++ website/style.css | 25 +++++++++ 5 files changed, 87 insertions(+), 144 deletions(-) delete mode 100644 5star_review_system/satic/styles.css delete mode 100644 5star_review_system/templates/index.html diff --git a/5star_review_system/satic/app.js b/5star_review_system/satic/app.js index 3db1616..77c584b 100644 --- a/5star_review_system/satic/app.js +++ b/5star_review_system/satic/app.js @@ -11,23 +11,33 @@ form.addEventListener('submit', async function (event) { review: formData.get('review') }; - const response = await fetch('/submit-review', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify(data), - }); + try { + const response = await fetch('/submit-review', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(data), + }); - const result = await response.json(); + if (!response.ok) { + throw new Error(`HTTP error! Status: ${response.status}`); + } - const messageElement = document.getElementById('responseMessage'); - if (result.success) { - messageElement.textContent = "Thank you for your review!"; - messageElement.style.color = 'green'; - form.reset(); - } else { - messageElement.textContent = "There was an error submitting your review."; + const result = await response.json(); + + const messageElement = document.getElementById('responseMessage'); + if (result.success) { + messageElement.textContent = "Thank you for your review!"; + messageElement.style.color = 'green'; + form.reset(); + } else { + messageElement.textContent = "There was an error submitting your review."; + messageElement.style.color = 'red'; + } + } catch (error) { + const messageElement = document.getElementById('responseMessage'); + messageElement.textContent = "There was an error submitting your review: " + error.message; messageElement.style.color = 'red'; } }); diff --git a/5star_review_system/satic/styles.css b/5star_review_system/satic/styles.css deleted file mode 100644 index 39817ea..0000000 --- a/5star_review_system/satic/styles.css +++ /dev/null @@ -1,68 +0,0 @@ -body { - font-family: Arial, sans-serif; - background-color: #f9f9f9; - color: #333; -} - -.container { - max-width: 700px; - margin: 0 auto; - padding: 20px; - background-color: white; - box-shadow: 0 0 15px rgba(0, 0, 0, 0.1); -} - -h1, h2 { - text-align: center; -} - -form { - margin-bottom: 40px; -} - -label { - font-weight: bold; -} - -input, textarea, button { - width: 100%; - margin-bottom: 15px; - padding: 10px; - border: 1px solid #ccc; - border-radius: 5px; -} - -.rating { - display: flex; - justify-content: center; - margin-bottom: 15px; -} - -.rating input { - display: none; -} - -.rating label { - font-size: 2rem; - color: #ddd; - cursor: pointer; -} - -.rating input:checked ~ label { - color: #f7c41c; -} - -button { - background-color: #4CAF50; - color: white; - border: none; - cursor: pointer; -} - -.review { - margin-bottom: 20px; -} - -.review p { - margin: 5px 0; -} diff --git a/5star_review_system/templates/index.html b/5star_review_system/templates/index.html deleted file mode 100644 index bc9b0d2..0000000 --- a/5star_review_system/templates/index.html +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - Dataset Rating and Reviews - - - - -
-

Rate Dataverse

- -
- - - - - - - -
- - - - - - - - - - -
- - - - - -
- -
- -
- -

Recent Reviews

-
- {% for review in reviews %} -
-

{{ review.name }} rated {{ review.rating }}/5

-

{{ review.review }}

-

Submitted on: {{ review.timestamp }}

-
-
- {% endfor %} -
- - - - - - diff --git a/index.html b/index.html index 4ca63e6..b4cca63 100644 --- a/index.html +++ b/index.html @@ -59,6 +59,43 @@
+ + + + +