From 2b41dc0fa6a4b4605612cc385b6a0941498ce8e2 Mon Sep 17 00:00:00 2001 From: Abdur-RahmaanJ Date: Fri, 27 Sep 2024 00:33:46 +0400 Subject: [PATCH 1/3] chore(deps): Add marshmallow-sqlalchemy --- reqs/app.in | Bin 424 -> 472 bytes reqs/app.txt | 12 +++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/reqs/app.in b/reqs/app.in index 80ebe502cfc409262d1aef5be6a34e79935121f1..e56dc327c02030ba43de57451151aa6681221d6c 100644 GIT binary patch delta 53 ycmZ3%e1mzyF6~@~M1~@UVulO`5Gw}=^BKw+bb%s;KsHDu87P+ul&ze&^)mo_Z4NvD delta 9 Rcmcb?yn=bcu8FVS0RR?|1v&r# diff --git a/reqs/app.txt b/reqs/app.txt index 7936622..6c215c9 100644 --- a/reqs/app.txt +++ b/reqs/app.txt @@ -32,7 +32,7 @@ flask-login==0.6.2 # shopyo flask-mailman==0.3.0 # via shopyo -flask-marshmallow==0.14.0 +flask-marshmallow==1.0.0 # via shopyo flask-migrate==3.1.0 # via shopyo @@ -71,7 +71,9 @@ marshmallow==3.14.1 # marshmallow-sqlalchemy # shopyo marshmallow-sqlalchemy==0.26.1 - # via shopyo + # via + # -r reqs/app.in + # shopyo mkdocs-material-extensions==1.0.3 # via flask-mailman numpy==2.1.1 @@ -80,6 +82,8 @@ numpy==2.1.1 # pandas openpyxl==3.0.10 # via -r reqs/app.in +packaging==24.1 + # via flask-marshmallow pandas==2.2.2 # via -r reqs/app.in pillow==10.4.0 @@ -95,9 +99,7 @@ pytz==2022.2.1 shopyo==4.8.6 # via pythoncms six==1.16.0 - # via - # flask-marshmallow - # python-dateutil + # via python-dateutil sqlalchemy==1.4.46 # via # alembic From 7d4b5dc62bb8dd1e826448235b8464a15a512cf5 Mon Sep 17 00:00:00 2001 From: Abdur-RahmaanJ Date: Fri, 27 Sep 2024 00:34:08 +0400 Subject: [PATCH 2/3] chore: rm marshmallow --- src/shopcube/init.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/shopcube/init.py b/src/shopcube/init.py index ae50082..8b4b566 100644 --- a/src/shopcube/init.py +++ b/src/shopcube/init.py @@ -5,7 +5,6 @@ from flask_login import LoginManager from flask_mailman import Mail -#from flask_marshmallow import Marshmallow from flask_migrate import Migrate from flask_sqlalchemy import SQLAlchemy from flask_uploads import DOCUMENTS @@ -21,9 +20,7 @@ installed_packages = [] db = SQLAlchemy() -# ma = Marshmallow() - -ma = None + login_manager = LoginManager() migrate = Migrate() mail = Mail() @@ -46,7 +43,6 @@ def configure_all_uploads(app): def load_extensions(app): migrate.init_app(app, db) db.init_app(app) - # ma.init_app(app) mail.init_app(app) login_manager.init_app(app) csrf.init_app(app) From 98ffd9c2e9c30361df8b356a7b8bc1d149ebea14 Mon Sep 17 00:00:00 2001 From: Abdur-RahmaanJ Date: Fri, 27 Sep 2024 00:34:40 +0400 Subject: [PATCH 3/3] feat: schemas use marshmallow-sqlalchemy --- .../modules/box__ecommerce/product/view.py | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/shopcube/modules/box__ecommerce/product/view.py b/src/shopcube/modules/box__ecommerce/product/view.py index ba9651c..73f1280 100644 --- a/src/shopcube/modules/box__ecommerce/product/view.py +++ b/src/shopcube/modules/box__ecommerce/product/view.py @@ -19,7 +19,6 @@ from werkzeug.utils import secure_filename from init import db -from init import ma from init import productphotos from modules.box__ecommerce.category.models import SubCategory @@ -28,6 +27,9 @@ from modules.box__ecommerce.product.models import Size from modules.resource.models import Resource +from marshmallow_sqlalchemy import SQLAlchemySchema, auto_field + + dirpath = os.path.dirname(os.path.abspath(__file__)) module_info = {} @@ -42,23 +44,23 @@ url_prefix=module_info["url_prefix"], ) - -class Productchema(ma.Schema): +class ProductSchema(SQLAlchemySchema): class Meta: - # Fields to expose - fields = ( - "barcode", - "name", - "description", - "price", - "selling_price", - "in_stock", - "discontinued", - ) + model = Product + load_instance = True # Optional: deserialize to model instances + + barcode = auto_field() + name = auto_field() + description = auto_field() + price = auto_field() + selling_price = auto_field() + in_stock = auto_field() + discontinued = auto_field() + -product_schema = Productchema() -product_schema = Productchema(many=True) +product_schema = ProductSchema() +product_schema = ProductSchema(many=True) module_blueprint = globals()["{}_blueprint".format(module_info["module_name"])]