Add 3 files
Browse files- README.md +7 -5
- index.html +542 -18
- prompts.txt +0 -0
README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: sma
|
| 3 |
+
emoji: 🐳
|
| 4 |
+
colorFrom: gray
|
| 5 |
+
colorTo: blue
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite
|
| 10 |
---
|
| 11 |
|
| 12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
index.html
CHANGED
|
@@ -1,19 +1,543 @@
|
|
| 1 |
-
<!
|
| 2 |
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
<html>
|
| 3 |
+
<head>
|
| 4 |
+
<title>Temu Clone - Backend Setup</title>
|
| 5 |
+
<style>
|
| 6 |
+
body {
|
| 7 |
+
font-family: Arial, sans-serif;
|
| 8 |
+
line-height: 1.6;
|
| 9 |
+
margin: 0;
|
| 10 |
+
padding: 20px;
|
| 11 |
+
background-color: #f5f5f5;
|
| 12 |
+
}
|
| 13 |
+
.container {
|
| 14 |
+
max-width: 1200px;
|
| 15 |
+
margin: 0 auto;
|
| 16 |
+
background: white;
|
| 17 |
+
padding: 20px;
|
| 18 |
+
border-radius: 5px;
|
| 19 |
+
box-shadow: 0 0 10px rgba(0,0,0,0.1);
|
| 20 |
+
}
|
| 21 |
+
h1, h2, h3 {
|
| 22 |
+
color: #333;
|
| 23 |
+
}
|
| 24 |
+
code {
|
| 25 |
+
background: #f4f4f4;
|
| 26 |
+
padding: 2px 5px;
|
| 27 |
+
border-radius: 3px;
|
| 28 |
+
font-family: monospace;
|
| 29 |
+
}
|
| 30 |
+
pre {
|
| 31 |
+
background: #333;
|
| 32 |
+
color: #fff;
|
| 33 |
+
padding: 10px;
|
| 34 |
+
border-radius: 5px;
|
| 35 |
+
overflow-x: auto;
|
| 36 |
+
}
|
| 37 |
+
.section {
|
| 38 |
+
margin-bottom: 30px;
|
| 39 |
+
padding-bottom: 20px;
|
| 40 |
+
border-bottom: 1px solid #eee;
|
| 41 |
+
}
|
| 42 |
+
.note {
|
| 43 |
+
background: #fffde7;
|
| 44 |
+
padding: 10px;
|
| 45 |
+
border-left: 4px solid #ffd600;
|
| 46 |
+
margin: 10px 0;
|
| 47 |
+
}
|
| 48 |
+
</style>
|
| 49 |
+
</head>
|
| 50 |
+
<body>
|
| 51 |
+
<div class="container">
|
| 52 |
+
<h1>Temu Clone - Backend Setup</h1>
|
| 53 |
+
|
| 54 |
+
<div class="section">
|
| 55 |
+
<h2>1. Backend Setup</h2>
|
| 56 |
+
|
| 57 |
+
<h3>Python Requirements</h3>
|
| 58 |
+
<p>Create a <code>requirements.txt</code> file:</p>
|
| 59 |
+
<pre>
|
| 60 |
+
Flask==2.3.2
|
| 61 |
+
Flask-SQLAlchemy==3.0.3
|
| 62 |
+
Flask-Login==0.6.2
|
| 63 |
+
Flask-Admin==1.6.1
|
| 64 |
+
Flask-WTF==1.0.1
|
| 65 |
+
python-dotenv==1.0.0
|
| 66 |
+
Pillow==9.5.0
|
| 67 |
+
</pre>
|
| 68 |
+
|
| 69 |
+
<h3>Configuration</h3>
|
| 70 |
+
<p>Create <code>config.py</code>:</p>
|
| 71 |
+
<pre>
|
| 72 |
+
import os
|
| 73 |
+
from dotenv import load_dotenv
|
| 74 |
+
|
| 75 |
+
load_dotenv()
|
| 76 |
+
|
| 77 |
+
class Config:
|
| 78 |
+
SECRET_KEY = os.getenv('SECRET_KEY') or 'your-secret-key-here'
|
| 79 |
+
SQLALCHEMY_DATABASE_URI = os.getenv('DATABASE_URL') or 'sqlite:///site.db'
|
| 80 |
+
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
| 81 |
+
UPLOAD_FOLDER = 'uploads'
|
| 82 |
+
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}
|
| 83 |
+
|
| 84 |
+
# Admin credentials
|
| 85 |
+
ADMIN_EMAIL = os.getenv('ADMIN_EMAIL') or 'admin@example.com'
|
| 86 |
+
ADMIN_PASSWORD = os.getenv('ADMIN_PASSWORD') or 'admin123'
|
| 87 |
+
</pre>
|
| 88 |
+
|
| 89 |
+
<h3>Database Models</h3>
|
| 90 |
+
<p>Create <code>models.py</code>:</p>
|
| 91 |
+
<pre>
|
| 92 |
+
from datetime import datetime
|
| 93 |
+
from flask_sqlalchemy import SQLAlchemy
|
| 94 |
+
from flask_login import UserMixin
|
| 95 |
+
from werkzeug.security import generate_password_hash, check_password_hash
|
| 96 |
+
|
| 97 |
+
db = SQLAlchemy()
|
| 98 |
+
|
| 99 |
+
class User(db.Model, UserMixin):
|
| 100 |
+
id = db.Column(db.Integer, primary_key=True)
|
| 101 |
+
username = db.Column(db.String(50), unique=True, nullable=False)
|
| 102 |
+
email = db.Column(db.String(120), unique=True, nullable=False)
|
| 103 |
+
password_hash = db.Column(db.String(128))
|
| 104 |
+
is_admin = db.Column(db.Boolean, default=False)
|
| 105 |
+
date_created = db.Column(db.DateTime, default=datetime.utcnow)
|
| 106 |
+
orders = db.relationship('Order', backref='customer', lazy=True)
|
| 107 |
+
|
| 108 |
+
def set_password(self, password):
|
| 109 |
+
self.password_hash = generate_password_hash(password)
|
| 110 |
+
|
| 111 |
+
def check_password(self, password):
|
| 112 |
+
return check_password_hash(self.password_hash, password)
|
| 113 |
+
|
| 114 |
+
class Product(db.Model):
|
| 115 |
+
id = db.Column(db.Integer, primary_key=True)
|
| 116 |
+
name = db.Column(db.String(100), nullable=False)
|
| 117 |
+
description = db.Column(db.Text)
|
| 118 |
+
price = db.Column(db.Float, nullable=False)
|
| 119 |
+
original_price = db.Column(db.Float)
|
| 120 |
+
image = db.Column(db.String(100))
|
| 121 |
+
category = db.Column(db.String(50))
|
| 122 |
+
flash_sale = db.Column(db.Boolean, default=False)
|
| 123 |
+
rating = db.Column(db.Float, default=0)
|
| 124 |
+
reviews = db.Column(db.Integer, default=0)
|
| 125 |
+
date_added = db.Column(db.DateTime, default=datetime.utcnow)
|
| 126 |
+
order_items = db.relationship('OrderItem', backref='product', lazy=True)
|
| 127 |
+
|
| 128 |
+
class Order(db.Model):
|
| 129 |
+
id = db.Column(db.Integer, primary_key=True)
|
| 130 |
+
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
|
| 131 |
+
total = db.Column(db.Float, nullable=False)
|
| 132 |
+
status = db.Column(db.String(20), default='Pending')
|
| 133 |
+
payment_method = db.Column(db.String(50))
|
| 134 |
+
shipping_address = db.Column(db.Text)
|
| 135 |
+
billing_address = db.Column(db.Text)
|
| 136 |
+
date_ordered = db.Column(db.DateTime, default=datetime.utcnow)
|
| 137 |
+
items = db.relationship('OrderItem', backref='order', lazy=True)
|
| 138 |
+
|
| 139 |
+
class OrderItem(db.Model):
|
| 140 |
+
id = db.Column(db.Integer, primary_key=True)
|
| 141 |
+
order_id = db.Column(db.Integer, db.ForeignKey('order.id'), nullable=False)
|
| 142 |
+
product_id = db.Column(db.Integer, db.ForeignKey('product.id'), nullable=False)
|
| 143 |
+
quantity = db.Column(db.Integer, nullable=False)
|
| 144 |
+
price = db.Column(db.Float, nullable=False)
|
| 145 |
+
</pre>
|
| 146 |
+
</div>
|
| 147 |
+
|
| 148 |
+
<div class="section">
|
| 149 |
+
<h2>2. Flask Application</h2>
|
| 150 |
+
|
| 151 |
+
<p>Create <code>app.py</code>:</p>
|
| 152 |
+
<pre>
|
| 153 |
+
import os
|
| 154 |
+
from flask import Flask, render_template, request, redirect, url_for, flash, send_from_directory
|
| 155 |
+
from flask_sqlalchemy import SQLAlchemy
|
| 156 |
+
from flask_login import LoginManager, login_user, login_required, logout_user, current_user
|
| 157 |
+
from flask_admin import Admin
|
| 158 |
+
from flask_admin.contrib.sqla import ModelView
|
| 159 |
+
from werkzeug.utils import secure_filename
|
| 160 |
+
from models import db, User, Product, Order, OrderItem
|
| 161 |
+
from config import Config
|
| 162 |
+
|
| 163 |
+
app = Flask(__name__)
|
| 164 |
+
app.config.from_object(Config)
|
| 165 |
+
|
| 166 |
+
# Initialize extensions
|
| 167 |
+
db.init_app(app)
|
| 168 |
+
login_manager = LoginManager(app)
|
| 169 |
+
login_manager.login_view = 'login'
|
| 170 |
+
|
| 171 |
+
# Create upload folder if not exists
|
| 172 |
+
if not os.path.exists(app.config['UPLOAD_FOLDER']):
|
| 173 |
+
os.makedirs(app.config['UPLOAD_FOLDER'])
|
| 174 |
+
|
| 175 |
+
@login_manager.user_loader
|
| 176 |
+
def load_user(user_id):
|
| 177 |
+
return User.query.get(int(user_id))
|
| 178 |
+
|
| 179 |
+
# Admin setup
|
| 180 |
+
class AdminModelView(ModelView):
|
| 181 |
+
def is_accessible(self):
|
| 182 |
+
return current_user.is_authenticated and current_user.is_admin
|
| 183 |
+
|
| 184 |
+
def inaccessible_callback(self, name, **kwargs):
|
| 185 |
+
return redirect(url_for('login'))
|
| 186 |
+
|
| 187 |
+
admin = Admin(app, name='Admin Panel', template_mode='bootstrap3')
|
| 188 |
+
admin.add_view(AdminModelView(User, db.session))
|
| 189 |
+
admin.add_view(AdminModelView(Product, db.session))
|
| 190 |
+
admin.add_view(AdminModelView(Order, db.session))
|
| 191 |
+
admin.add_view(AdminModelView(OrderItem, db.session))
|
| 192 |
+
|
| 193 |
+
# Routes
|
| 194 |
+
@app.route('/')
|
| 195 |
+
def home():
|
| 196 |
+
return render_template('admin/index.html')
|
| 197 |
+
|
| 198 |
+
@app.route('/login', methods=['GET', 'POST'])
|
| 199 |
+
def login():
|
| 200 |
+
if request.method == 'POST':
|
| 201 |
+
email = request.form.get('email')
|
| 202 |
+
password = request.form.get('password')
|
| 203 |
+
user = User.query.filter_by(email=email).first()
|
| 204 |
+
|
| 205 |
+
if user and user.check_password(password):
|
| 206 |
+
login_user(user)
|
| 207 |
+
next_page = request.args.get('next')
|
| 208 |
+
return redirect(next_page or url_for('admin.index'))
|
| 209 |
+
else:
|
| 210 |
+
flash('Invalid email or password', 'danger')
|
| 211 |
+
|
| 212 |
+
return render_template('auth/login.html')
|
| 213 |
+
|
| 214 |
+
@app.route('/logout')
|
| 215 |
+
@login_required
|
| 216 |
+
def logout():
|
| 217 |
+
logout_user()
|
| 218 |
+
return redirect(url_for('login'))
|
| 219 |
+
|
| 220 |
+
# API Endpoints
|
| 221 |
+
@app.route('/api/products', methods=['GET'])
|
| 222 |
+
def get_products():
|
| 223 |
+
products = Product.query.all()
|
| 224 |
+
return {'products': [{
|
| 225 |
+
'id': p.id,
|
| 226 |
+
'name': p.name,
|
| 227 |
+
'price': p.price,
|
| 228 |
+
'original_price': p.original_price,
|
| 229 |
+
'image': url_for('uploaded_file', filename=p.image) if p.image else None,
|
| 230 |
+
'category': p.category,
|
| 231 |
+
'flash_sale': ,
|
| 232 |
+
'rating': p.rating,
|
| 233 |
+
'reviews': p.reviews
|
| 234 |
+
} for p in products]}
|
| 235 |
+
|
| 236 |
+
@app.route('/api/orders', methods=['POST'])
|
| 237 |
+
def create_order():
|
| 238 |
+
data = request.get_json()
|
| 239 |
+
|
| 240 |
+
# In a real app, you would validate the data and process payment
|
| 241 |
+
order = Order(
|
| 242 |
+
user_id=data.get('user_id'),
|
| 243 |
+
total=data['total'],
|
| 244 |
+
payment_method=data.get('payment_method', 'Credit Card'),
|
| 245 |
+
shipping_address=data.get('shipping_address', ''),
|
| 246 |
+
billing_address=data.get('billing_address', '')
|
| 247 |
+
)
|
| 248 |
+
|
| 249 |
+
db.session.add(order)
|
| 250 |
+
|
| 251 |
+
for item in data['items']:
|
| 252 |
+
order_item = OrderItem(
|
| 253 |
+
order_id=order.id,
|
| 254 |
+
product_id=item['product_id'],
|
| 255 |
+
quantity=item['quantity'],
|
| 256 |
+
price=item['price']
|
| 257 |
+
)
|
| 258 |
+
db.session.add(order_item)
|
| 259 |
+
|
| 260 |
+
db.session.commit()
|
| 261 |
+
|
| 262 |
+
return {'success': True, 'order_id': order.id}
|
| 263 |
+
|
| 264 |
+
@app.route('/uploads/<filename>')
|
| 265 |
+
def uploaded_file(filename):
|
| 266 |
+
return send_from_directory(app.config['UPLOAD_FOLDER'], filename)
|
| 267 |
+
|
| 268 |
+
# Create admin user on first run
|
| 269 |
+
def create_admin_user():
|
| 270 |
+
admin_email = app.config['ADMIN_EMAIL']
|
| 271 |
+
admin_password = app.config['ADMIN_PASSWORD']
|
| 272 |
+
|
| 273 |
+
if not User.query.filter_by(email=admin_email).first():
|
| 274 |
+
admin_user = User(
|
| 275 |
+
username='admin',
|
| 276 |
+
email=admin_email,
|
| 277 |
+
is_admin=True
|
| 278 |
+
)
|
| 279 |
+
admin_user.set_password(admin_password)
|
| 280 |
+
db.session.add(admin_user)
|
| 281 |
+
db.session.commit()
|
| 282 |
+
print("Admin user created successfully!")
|
| 283 |
+
|
| 284 |
+
if __name__ == '__main__':
|
| 285 |
+
with app.app_context():
|
| 286 |
+
db.create_all()
|
| 287 |
+
create_admin_user()
|
| 288 |
+
app.run(debug=True)
|
| 289 |
+
</pre>
|
| 290 |
+
</div>
|
| 291 |
+
|
| 292 |
+
<div class="section">
|
| 293 |
+
<h2>3. Admin Panel Templates</h2>
|
| 294 |
+
|
| 295 |
+
<h3>Login Template (templates/auth/login.html)</h3>
|
| 296 |
+
<pre>
|
| 297 |
+
<!DOCTYPE html>
|
| 298 |
+
<html>
|
| 299 |
+
<head>
|
| 300 |
+
<title>Admin Login</title>
|
| 301 |
+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
| 302 |
+
</head>
|
| 303 |
+
<body>
|
| 304 |
+
<div class="container mt-5">
|
| 305 |
+
<div class="row justify-content-center">
|
| 306 |
+
<div class="col-md-6 col-lg-4">
|
| 307 |
+
<div class="card shadow">
|
| 308 |
+
<div class="card-body">
|
| 309 |
+
<h3 class="card-title text-center mb-4">Admin Login</h3>
|
| 310 |
+
{% with messages = get_flashed_messages(with_categories=true) %}
|
| 311 |
+
{% if messages %}
|
| 312 |
+
{% for category, message in messages %}
|
| 313 |
+
<div class="alert alert-{{ category }}">{{ message }}</div>
|
| 314 |
+
{% endfor %}
|
| 315 |
+
{% endif %}
|
| 316 |
+
{% endwith %}
|
| 317 |
+
<form method="POST" action="{{ url_for('login') }}">
|
| 318 |
+
<div class="mb-3">
|
| 319 |
+
<label for="email" class="form-label">Email</label>
|
| 320 |
+
<input type="email" class="form-control" id="email" name="email" required>
|
| 321 |
+
</div>
|
| 322 |
+
<div class="mb-3">
|
| 323 |
+
<label for="password" class="form-label">Password</label>
|
| 324 |
+
<input type="password" class="form-control" id="password" name="password" required>
|
| 325 |
+
</div>
|
| 326 |
+
<button type="submit" class="btn btn-primary w-100">Login</button>
|
| 327 |
+
</form>
|
| 328 |
+
</div>
|
| 329 |
+
</div>
|
| 330 |
+
</div>
|
| 331 |
+
</div>
|
| 332 |
+
</div>
|
| 333 |
+
</body>
|
| 334 |
+
</html>
|
| 335 |
+
</pre>
|
| 336 |
+
|
| 337 |
+
<h3>Admin Dashboard (templates/admin/index.html)</h3>
|
| 338 |
+
<pre>
|
| 339 |
+
{% extends 'admin/master.html' %}
|
| 340 |
+
|
| 341 |
+
{% block body %}
|
| 342 |
+
<div class="container">
|
| 343 |
+
<h1>Admin Dashboard</h1>
|
| 344 |
+
<div class="row mt-4">
|
| 345 |
+
<div class="col-md-4">
|
| 346 |
+
<div class="card text-white bg-primary mb-3">
|
| 347 |
+
<div class="card-body">
|
| 348 |
+
<h5 class="card-title">Total Products</h5>
|
| 349 |
+
<p class="card-text" style="font-size: 2rem;">{{ Product.query.count() }}</p>
|
| 350 |
+
</div>
|
| 351 |
+
</div>
|
| 352 |
+
</div>
|
| 353 |
+
<div class="col-md-4">
|
| 354 |
+
<div class="card text-white bg-success mb-3">
|
| 355 |
+
<div class="card-body">
|
| 356 |
+
<h5 class="card-title">Total Orders</h5>
|
| 357 |
+
<p class="card-text" style="font-size: 2rem;">{{ Order.query.count() }}</p>
|
| 358 |
+
</div>
|
| 359 |
+
</div>
|
| 360 |
+
</div>
|
| 361 |
+
<div class="col-md-4">
|
| 362 |
+
<div class="card text-white bg-info mb-3">
|
| 363 |
+
<div class="card-body">
|
| 364 |
+
<h5 class="card-title">Total Users</h5>
|
| 365 |
+
<p class="card-text" style="font-size: 2rem;">{{ User.query.count() }}</p>
|
| 366 |
+
</div>
|
| 367 |
+
</div>
|
| 368 |
+
</div>
|
| 369 |
+
</div>
|
| 370 |
+
|
| 371 |
+
<div class="row mt-4">
|
| 372 |
+
<div class="col-md-6">
|
| 373 |
+
<div class="card">
|
| 374 |
+
<div class="card-header">
|
| 375 |
+
Recent Orders
|
| 376 |
+
</div>
|
| 377 |
+
<div class="card-body">
|
| 378 |
+
<table class="table">
|
| 379 |
+
<thead>
|
| 380 |
+
<tr>
|
| 381 |
+
<th>ID</th>
|
| 382 |
+
<th>Date</th>
|
| 383 |
+
<th>Total</th>
|
| 384 |
+
<th>Status</th>
|
| 385 |
+
</tr>
|
| 386 |
+
</thead>
|
| 387 |
+
<tbody>
|
| 388 |
+
{% for order in Order.query.order_by(Order.date_ordered.desc()).limit(5).all() %}
|
| 389 |
+
<tr>
|
| 390 |
+
<td><a href="{{ url_for('order.edit_view', id=order.id) }}">{{ order.id }}</a></td>
|
| 391 |
+
<td>{{ order.date_ordered.strftime('%Y-%m-%d') }}</td>
|
| 392 |
+
<td>${{ "%.2f"|format(order.total) }}</td>
|
| 393 |
+
<td>{{ order.status }}</td>
|
| 394 |
+
</tr>
|
| 395 |
+
{% endfor %}
|
| 396 |
+
</tbody>
|
| 397 |
+
</table>
|
| 398 |
+
</div>
|
| 399 |
+
</div>
|
| 400 |
+
</div>
|
| 401 |
+
<div class="col-md-6">
|
| 402 |
+
<div class="card">
|
| 403 |
+
<div class="card-header">
|
| 404 |
+
Recent Products
|
| 405 |
+
</div>
|
| 406 |
+
<div class="card-body">
|
| 407 |
+
<table class="table">
|
| 408 |
+
<thead>
|
| 409 |
+
<tr>
|
| 410 |
+
<th>Name</th>
|
| 411 |
+
<th>Price</th>
|
| 412 |
+
<th>Category</th>
|
| 413 |
+
</tr>
|
| 414 |
+
</thead>
|
| 415 |
+
<tbody>
|
| 416 |
+
{% for product in Product.query.order_by(Product.date_added.desc()).limit(5).all() %}
|
| 417 |
+
<tr>
|
| 418 |
+
<td><a href="{{ url_for('product.edit_view', id=product.id) }}">{{ product.name }}</a></td>
|
| 419 |
+
<td>${{ "%.2f"|format(product.price) }}</td>
|
| 420 |
+
<td>{{ product.category }}</td>
|
| 421 |
+
</tr>
|
| 422 |
+
{% endfor %}
|
| 423 |
+
</tbody>
|
| 424 |
+
</table>
|
| 425 |
+
</div>
|
| 426 |
+
</div>
|
| 427 |
+
</div>
|
| 428 |
+
</div>
|
| 429 |
+
</div>
|
| 430 |
+
{% endblock %}
|
| 431 |
+
</pre>
|
| 432 |
+
</div>
|
| 433 |
+
|
| 434 |
+
<div class="section">
|
| 435 |
+
<h2>4. Integration with Frontend</h2>
|
| 436 |
+
|
| 437 |
+
<h3>Update your frontend JavaScript to use the API</h3>
|
| 438 |
+
<p>Modify your existing JavaScript to fetch products from the backend:</p>
|
| 439 |
+
<pre>
|
| 440 |
+
// Fetch products from backend
|
| 441 |
+
async function fetchProducts() {
|
| 442 |
+
try {
|
| 443 |
+
const response = await fetch('/api/products');
|
| 444 |
+
const data = await response.json();
|
| 445 |
+
return data.products;
|
| 446 |
+
} catch (error) {
|
| 447 |
+
console.error('Error fetching products:', error);
|
| 448 |
+
return [];
|
| 449 |
+
}
|
| 450 |
+
}
|
| 451 |
+
|
| 452 |
+
// Example of creating an order
|
| 453 |
+
async function createOrder(orderData) {
|
| 454 |
+
try {
|
| 455 |
+
const response = await fetch('/api/orders', {
|
| 456 |
+
method: 'POST',
|
| 457 |
+
headers: {
|
| 458 |
+
'Content-Type': 'application/json',
|
| 459 |
+
},
|
| 460 |
+
body: JSON.stringify(orderData)
|
| 461 |
+
});
|
| 462 |
+
return await response.json();
|
| 463 |
+
} catch (error) {
|
| 464 |
+
console.error('Error creating order:', error);
|
| 465 |
+
return { success: false, error: 'Failed to create order' };
|
| 466 |
+
}
|
| 467 |
+
}
|
| 468 |
+
|
| 469 |
+
// Update your existing code to use these functions
|
| 470 |
+
document.addEventListener('DOMContentLoaded', async function() {
|
| 471 |
+
const products = await fetchProducts();
|
| 472 |
+
// Render products to the page
|
| 473 |
+
renderProducts(products);
|
| 474 |
+
|
| 475 |
+
// When user checks out
|
| 476 |
+
checkoutButton.addEventListener('click', async function() {
|
| 477 |
+
const orderData = {
|
| 478 |
+
user_id: currentUser?.id || null,
|
| 479 |
+
total: calculateCartTotal(),
|
| 480 |
+
items: cart.map(item => ({
|
| 481 |
+
product_id: item.id,
|
| 482 |
+
quantity: item.quantity,
|
| 483 |
+
price: item.price
|
| 484 |
+
})),
|
| 485 |
+
payment_method: 'Credit Card',
|
| 486 |
+
shipping_address: '123 Main St, Anytown, USA'
|
| 487 |
+
};
|
| 488 |
+
|
| 489 |
+
const result = await createOrder(orderData);
|
| 490 |
+
if (result.success) {
|
| 491 |
+
alert(`Order #${result.order_id} created successfully!`);
|
| 492 |
+
// Clear cart
|
| 493 |
+
cart = [];
|
| 494 |
+
localStorage.setItem('cart', JSON.stringify(cart));
|
| 495 |
+
updateCartCount();
|
| 496 |
+
renderCartItems();
|
| 497 |
+
} else {
|
| 498 |
+
alert('Failed to create order: ' + (result.error || 'Unknown error'));
|
| 499 |
+
}
|
| 500 |
+
});
|
| 501 |
+
});
|
| 502 |
+
</pre>
|
| 503 |
+
</div>
|
| 504 |
+
|
| 505 |
+
<div class="section">
|
| 506 |
+
<h2>5. Deployment Instructions</h2>
|
| 507 |
+
|
| 508 |
+
<div class="note">
|
| 509 |
+
<p><strong>Note:</strong> For production, you should use a proper web server like Gunicorn with Nginx, and a production database like PostgreSQL.</p>
|
| 510 |
+
</div>
|
| 511 |
+
|
| 512 |
+
<h3>Local Development</h3>
|
| 513 |
+
<ol>
|
| 514 |
+
<li>Install Python 3.8+</li>
|
| 515 |
+
<li>Create and activate a virtual environment:
|
| 516 |
+
<pre>python -m venv venv
|
| 517 |
+
source venv/bin/activate # On Windows: venv\Scripts\activate</pre>
|
| 518 |
+
</li>
|
| 519 |
+
<li>Install dependencies:
|
| 520 |
+
<pre>pip install -r requirements.txt</pre>
|
| 521 |
+
</li>
|
| 522 |
+
<li>Run the application:
|
| 523 |
+
<pre>python app.py</pre>
|
| 524 |
+
</li>
|
| 525 |
+
<li>Access the admin panel at <code>http://localhost:5000/admin</code></li>
|
| 526 |
+
<li>Login with the admin credentials from <code>config.py</code></li>
|
| 527 |
+
</ol>
|
| 528 |
+
|
| 529 |
+
<h3>Production Deployment</h3>
|
| 530 |
+
<p>For production, you'll need to:</p>
|
| 531 |
+
<ol>
|
| 532 |
+
<li>Set proper environment variables (SECRET_KEY, DATABASE_URL, etc.)</li>
|
| 533 |
+
<li>Use a production WSGI server like Gunicorn:
|
| 534 |
+
<pre>gunicorn -w 4 -b 0.0.0.0:5000 app:app</pre>
|
| 535 |
+
</li>
|
| 536 |
+
<li>Configure a reverse proxy like Nginx</li>
|
| 537 |
+
<li>Set up a production database (PostgreSQL recommended)</li>
|
| 538 |
+
<li>Configure HTTPS with Let's Encrypt</li>
|
| 539 |
+
</ol>
|
| 540 |
+
</div>
|
| 541 |
+
</div>
|
| 542 |
+
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Marv12/sma" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
|
| 543 |
+
</html>
|
prompts.txt
ADDED
|
File without changes
|