diff --git a/.gitignore b/.gitignore index 580f074..471b22d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ venv/ desktop.ini -static/ +data/ __pycache__/ *.pyc *.pyo diff --git a/admin.py b/src/admin.py similarity index 97% rename from admin.py rename to src/admin.py index 5d316a5..92d222a 100644 --- a/admin.py +++ b/src/admin.py @@ -19,9 +19,10 @@ except ImportError: admin_bp = Blueprint('admin', __name__, url_prefix='/admin') -PRODUCTS_FILE = 'static/products.json' -UPLOAD_FOLDER = 'static/images' -BARCODE_FOLDER = 'static/barcodes' +DATA_FOLDER = os.path.join(os.path.dirname(__file__), 'data') +PRODUCTS_FILE = os.path.join(DATA_FOLDER, 'products.json') +UPLOAD_FOLDER = os.path.join(DATA_FOLDER, 'images') +BARCODE_FOLDER = os.path.join(DATA_FOLDER, 'barcodes') ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'} def allowed_file(filename): diff --git a/app.py b/src/app.py similarity index 82% rename from app.py rename to src/app.py index 5c09c3d..cc4b60a 100644 --- a/app.py +++ b/src/app.py @@ -4,7 +4,8 @@ import json from admin import admin_bp app = Flask(__name__) -app.config['STATIC_FOLDER'] = './static' +# Set DATA_FOLDER to the absolute path of the data directory inside src +app.config['DATA_FOLDER'] = os.path.join(os.path.dirname(__file__), 'data') app.config['SECRET_KEY'] = 'dev-key-for-demo-only' # Register blueprints @@ -13,7 +14,8 @@ app.register_blueprint(admin_bp) # Load product data from products.json def load_products(): try: - with open('static/products.json', 'r') as f: + products_file = os.path.join(app.config['DATA_FOLDER'], 'products.json') + with open(products_file, 'r') as f: return json.load(f) except (FileNotFoundError, json.JSONDecodeError): return {} @@ -47,25 +49,25 @@ def get_ar_info(): @app.route('/images/', methods=['GET']) def serve_image(filename): - image_path = os.path.join(app.config['STATIC_FOLDER'], 'images', filename) + image_path = os.path.join(app.config['DATA_FOLDER'], 'images', filename) if os.path.exists(image_path): return send_file(image_path) return jsonify({"error": "Image not found"}), 404 @app.route('/barcodes/', methods=['GET']) def serve_barcode(filename): - barcode_path = os.path.join(app.config['STATIC_FOLDER'], 'barcodes', filename) + barcode_path = os.path.join(app.config['DATA_FOLDER'], 'barcodes', filename) if os.path.exists(barcode_path): return send_file(barcode_path) return jsonify({"error": "Barcode not found"}), 404 if __name__ == '__main__': # Ensure the required directories exist - os.makedirs(os.path.join(app.config['STATIC_FOLDER'], 'images'), exist_ok=True) - os.makedirs(os.path.join(app.config['STATIC_FOLDER'], 'barcodes'), exist_ok=True) + os.makedirs(os.path.join(app.config['DATA_FOLDER'], 'images'), exist_ok=True) + os.makedirs(os.path.join(app.config['DATA_FOLDER'], 'barcodes'), exist_ok=True) # If products.json doesn't exist, create it with initial data - products_file = os.path.join(app.config['STATIC_FOLDER'], 'products.json') + products_file = os.path.join(app.config['DATA_FOLDER'], 'products.json') if not os.path.exists(products_file): initial_data = { "123456": [ diff --git a/barcode_generator.py b/src/barcode_generator.py similarity index 100% rename from barcode_generator.py rename to src/barcode_generator.py diff --git a/templates/admin/add_product.html b/src/templates/admin/add_product.html similarity index 100% rename from templates/admin/add_product.html rename to src/templates/admin/add_product.html diff --git a/templates/admin/edit_product.html b/src/templates/admin/edit_product.html similarity index 100% rename from templates/admin/edit_product.html rename to src/templates/admin/edit_product.html diff --git a/templates/admin/generate_barcode.html b/src/templates/admin/generate_barcode.html similarity index 100% rename from templates/admin/generate_barcode.html rename to src/templates/admin/generate_barcode.html diff --git a/templates/admin/index.html b/src/templates/admin/index.html similarity index 100% rename from templates/admin/index.html rename to src/templates/admin/index.html diff --git a/templates/index.html b/src/templates/index.html similarity index 100% rename from templates/index.html rename to src/templates/index.html diff --git a/templates/layout.html b/src/templates/layout.html similarity index 100% rename from templates/layout.html rename to src/templates/layout.html