Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
commit
commit
  • Loading branch information
gopakumara committed Aug 1, 2024
0 parents commit b0df7c2
Show file tree
Hide file tree
Showing 32 changed files with 4,444 additions and 0 deletions.
Binary file not shown.
Binary file added ToolBox/__pycache__/app.cpython-311.pyc
Binary file not shown.
Binary file added ToolBox/__pycache__/test_app.cpython-311.pyc
Binary file not shown.
Binary file not shown.
407 changes: 407 additions & 0 deletions ToolBox/app.py

Large diffs are not rendered by default.

97 changes: 97 additions & 0 deletions ToolBox/app2.py
@@ -0,0 +1,97 @@
from flask import Flask, render_template, request, redirect, url_for, flash
from flask_mysqldb import MySQL
from flask_bcrypt import Bcrypt

app = Flask(__name__)
app.secret_key = 'eH6BjKbFtJg4yP0Q1rWXu89Zc2aVs7Y3sLhNopkD'

# MySQL configurations
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_USER'] = 'root'
app.config['MYSQL_PASSWORD'] = ''
app.config['MYSQL_DB'] = 'toolbox'

mysql = MySQL(app)
bcrypt = Bcrypt(app)

@app.route('/')
def admin_dashboard():
cur = mysql.connection.cursor()
cur.execute("SELECT id, name FROM brands")
brands = cur.fetchall()
cur.execute("SELECT id, name FROM categories")
categories = cur.fetchall()
cur.execute("SELECT id, image_url FROM carousel")
carousel = cur.fetchall()
cur.execute("SELECT id, image_url FROM offers")
offers = cur.fetchall()

cur.close()
return render_template('admin.html', brands=brands, categories=categories,carousel=carousel, offers=offers)




@app.route('/admin/carousel/add', methods=['GET', 'POST'])
def add_carousel():
cur = mysql.connection.cursor()

if request.method == 'POST':
image_url = request.form['image_url']
category_id = request.form['category_id']
brand_id = request.form['brand_id']

cur.execute(
"INSERT INTO carousel (image_url, category_id, brand_id) VALUES (%s, %s, %s)",
(image_url, category_id, brand_id)
)
mysql.connection.commit()
cur.close()

flash('Carousel item added successfully!', 'success')
return redirect(url_for('admin_dashboard'))

# Fetch categories and brands for dropdowns
cur.execute("SELECT id, name FROM categories")
categories = cur.fetchall()
cur.execute("SELECT id, name FROM brands")
brands = cur.fetchall()
cur.close()

return render_template('Admin_add.html', categories=categories, brands=brands)

@app.route('/admin/carousel/delete/<int:carousel_id>', methods=['POST'])
def delete_carousel(carousel_id):
cur = mysql.connection.cursor()
cur.execute("DELETE FROM carousel WHERE id = %s", (carousel_id,))
mysql.connection.commit()
cur.close()

flash('Carousel item deleted successfully!', 'success')
return redirect(url_for('admin_dashboard'))


@app.route('/admin/offer', methods=['POST'])
def add_offer():
image_url = request.form['offer_image']
category_id = request.form['category_id']
brand_id = request.form['brand_id']
cur = mysql.connection.cursor()
cur.execute("INSERT INTO offers (image_url, category_id, brand_id) VALUES (%s, %s, %s)", (image_url, category_id, brand_id))
mysql.connection.commit()
cur.close()
flash('Offer added successfully!', 'success')
return redirect(url_for('admin_dashboard'))

@app.route('/admin/offer/delete/<int:id>', methods=['POST'])
def delete_offer(id):
cur = mysql.connection.cursor()
cur.execute("DELETE FROM offers WHERE id = %s", (id,))
mysql.connection.commit()
cur.close()
flash('Offer deleted successfully!', 'success')
return redirect(url_for('admin_dashboard'))


if __name__ == '__main__':
app.run(debug=True)

0 comments on commit b0df7c2

Please sign in to comment.