Skip to content

Commit

Permalink
Merge pull request #21 from BhuvanSA/main
Browse files Browse the repository at this point in the history
Remove unnecessary dependencies
  • Loading branch information
nishith-p-shetty authored Mar 8, 2024
2 parents 851ff7f + 63185bc commit a7d949d
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 42 deletions.
33 changes: 27 additions & 6 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import psycopg2
import os
from datetime import datetime as dt
from flask import Flask, render_template, request, session, redirect, url_for, flash, send_from_directory
from flask import Flask, render_template, request, session, redirect, url_for, flash
from flask_cors import CORS
from dotenv import load_dotenv

Expand All @@ -19,7 +19,8 @@


conn = psycopg2.connect(
host=DB_HOST, user=DB_USER, password=DB_PASSWORD, database=DB_NAME)
host=DB_HOST, user=DB_USER, password=DB_PASSWORD, database=DB_NAME,
sslmode='require')


cursor = conn.cursor()
Expand Down Expand Up @@ -132,7 +133,7 @@ def login():
@app.route('/dashboard', methods=['GET', 'POST'])
def dashboard():
page = request.args.get('page', 1, type=int)
search = request.args.get('search', '', type=str).strip()
search = request.args.get('search', '', type=str).strip().lower()

conn = psycopg2.connect(database=DB_NAME, user=DB_USER,
password=DB_PASSWORD, host=DB_HOST)
Expand All @@ -142,7 +143,7 @@ def dashboard():
cursor.execute('''SELECT COUNT(*) FROM feedbacks JOIN reviewer
ON
feedbacks.reviewer_id = reviewer.reviewer_id
WHERE reviewer_name LIKE %s''',
WHERE LOWER(reviewer_name) LIKE %s''',
('%' + search + '%',))
total_feedbacks = cursor.fetchone()
total_feedbacks = total_feedbacks[0] if total_feedbacks is not None else 0
Expand All @@ -151,7 +152,7 @@ def dashboard():
# Fetch all feedbacks with reviewer and team details
cursor.execute('''
SELECT
feedbacks.reviewer_id,
feedbacks.feedback_id,
reviewer.reviewer_name,
team.team_number,
feedbacks.field1_rating,
Expand All @@ -164,7 +165,7 @@ def dashboard():
FROM feedbacks
INNER JOIN reviewer ON feedbacks.reviewer_id = reviewer.reviewer_id
INNER JOIN team ON feedbacks.team_id = team.team_id
WHERE reviewer.reviewer_name LIKE %s
WHERE LOWER(reviewer.reviewer_name) LIKE %s
ORDER BY reviewer.review_time DESC
LIMIT 5 OFFSET %s;
''', ('%' + search + '%', (page-1)*5))
Expand Down Expand Up @@ -220,6 +221,26 @@ def logout():
return redirect(url_for('login'))


@app.route('/delete_feedback/<int:feedback_id>', methods=['GET'])
def delete_feedback(feedback_id):
if not session.get('logged_in'):
flash('Please login to delete feedback.')
return redirect(url_for('login'))

conn = psycopg2.connect(database=DB_NAME, user=DB_USER,
password=DB_PASSWORD, host=DB_HOST)
cursor = conn.cursor()

cursor.execute(
'DELETE FROM feedbacks WHERE feedback_id = %s', (feedback_id,))
conn.commit()
cursor.close()
conn.close()

flash('Feedback deleted successfully.')
return redirect(url_for('dashboard'))


@app.route('/favicon.ico')
def favicon():
# return redirect(url_for('static', filename='images/favicon.ico'))
Expand Down
8 changes: 8 additions & 0 deletions public/templates/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ <h2>Recent Feedbacks</h2>
<th>Average Rating</th>
<th>Review Time</th>
<th>Feedback</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
Expand All @@ -62,6 +63,13 @@ <h2>Recent Feedbacks</h2>
<td>{{ row[7] }}</td>
<td>{{ row[8] }}</td>
<td>{{ row[9] }}</td>
<td>
<a
href="{{ url_for('delete_feedback', feedback_id=row[0]) }}">
<i class="fa fa-trash"
style="color: lightcoral;"></i>
</a>
</td>
</tr>
{% endfor %}
</tbody>
Expand Down
3 changes: 2 additions & 1 deletion public/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ <h2>Team {{ i }}</h2>
id="team_id{{ i }}_field4_rating"
name="team_id{{ i }}_field4_rating">
<input type="text" rows="3" placeholder="Enter feedback" class="ntext"
id="team_id{{ i }}_feedback" name="team_id{{ i }}_feedback">
id="team_id{{ i }}_feedback" name="team_id{{ i }}_feedback"
maxlength="255">
</div>
</div>
<br>
Expand Down
53 changes: 33 additions & 20 deletions public/templates/login.html
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
<!DOCTYPE html>
<html>

<head>
<title>Login</title>
<!-- <link rel="stylesheet" href="static/login-style.css"> -->
<link rel="stylesheet" href="{{ url_for('static', filename='css/login-style.css') }}">
<link rel="icon" type="image/png" sizes="30x30" href="static/star.png">
</head>
<head>
<title>Login</title>
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<link rel="icon" type="image/png" sizes="30x30" href="static/star.png">
<link rel="stylesheet"
href="{{ url_for('static', filename='css/styles.css') }}">
</head>

<body>
{% if error %}
<p><strong>{{ error }}</strong></p>
{% endif %}
<form class="form" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<br>
<input class="loginbtn" type="submit" value="Login">
</form>
</body>
<body>
{% if error %}
<p><strong>{{ error }}</strong></p>
{% endif %}
<div class="form user_page">
<h1> Login </h1>
</div>
<br />
<form class="form user_page" method="post">
<label for="username">Username:</label>
<div
style="border-radius: 20px; border: 2px solid; border-color:aquamarine; margin-left: 80px; margin-right: 80px ">
<input type="text" id="username" name="username"
required>
</div>
<br>
<label for="password">Password:</label>
<div
style="border-radius: 20px; border: 2px solid; border-color:aquamarine; margin-left: 80px; margin-right: 80px">
<input type="password" id="password" name="password" required>
</div>
<br>
<button type="submit" class="btn btn-primary">Login</button>
</form>
</body>

</html>
30 changes: 16 additions & 14 deletions public/templates/success.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
<!DOCTYPE html>
<html lang="en">

<head>
<title>Feedback Submitted</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}">
<link rel="icon" type="image/png" sizes="30x30" href="static/star.png">
</head>
<head>
<title>Feedback Submitted</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"
href="{{ url_for('static', filename='css/styles.css') }}">
<link rel="icon" type="image/png" sizes="30x30" href="static/star.png">
</head>

<body>
<a href="/dashboard" class="dashboard-button">Dashboard</a>
<a href="https://github.com/bhuvansa/flask-feedback-form" class="github-link"> </a>
<div class="form">
<h1> Thankyou for your feedback! {{ name }} </h1>
</div>
</body>
<body>
<a href="/dashboard" class="dashboard-button">Dashboard</a>
<a href="https://github.com/bhuvansa/flask-feedback-form"
class="github-link"> </a>
<div class="form user_page">
<h1> Thankyou for your feedback! {{ name }} </h1>
</div>
</body>

</html>
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ MarkupSafe==2.1.2
psycopg2-binary==2.9.9
python-dotenv==1.0.1
six==1.16.0
waitress==2.1.2
Werkzeug==2.2.3

0 comments on commit a7d949d

Please sign in to comment.