P5-4794 optimize listprice code and fix wallpaper listprice
This commit is contained in:
@@ -4,7 +4,6 @@ from datetime import datetime
|
||||
from api.extensions import db
|
||||
from flask_sqlalchemy import BaseQuery
|
||||
from sqlalchemy import or_
|
||||
from sqlalchemy.orm import joinedload
|
||||
|
||||
|
||||
class Product(db.Model):
|
||||
@@ -99,9 +98,6 @@ class PrintProductQuery(BaseQuery):
|
||||
def framed_prints(self):
|
||||
return self.filter(PrintProduct.groupid == 8)
|
||||
|
||||
def with_relations(self):
|
||||
return self.options(joinedload("*"))
|
||||
|
||||
|
||||
class PrintProduct(db.Model):
|
||||
|
||||
@@ -115,4 +111,4 @@ class PrintProduct(db.Model):
|
||||
)
|
||||
groupid = db.Column(db.Integer, nullable=False)
|
||||
|
||||
product = db.relationship("Product", backref="printproducts")
|
||||
product = db.relationship("Product", backref="printproducts", lazy="joined")
|
||||
|
||||
@@ -512,15 +512,13 @@ def inquiry(inquiry_id):
|
||||
|
||||
@mod.route("/list-prices/<string:territory>/wallpaper")
|
||||
def list_prices_wallpaper(territory):
|
||||
wallpapers = PrintProduct.query.wallpapers().with_relations().all()
|
||||
wallpapers = PrintProduct.query.wallpapers().all()
|
||||
result = {}
|
||||
material = Material.query.filter(Material.name == "standard-wallpaper").one()
|
||||
market = market_model.from_territory(territory)
|
||||
|
||||
for wallpaper in wallpapers:
|
||||
result[wallpaper.id] = wallpaper_price(
|
||||
width=100,
|
||||
height=100,
|
||||
result[wallpaper.id] = m2_price(
|
||||
material=material,
|
||||
market=market,
|
||||
designer=wallpaper.product.designer,
|
||||
@@ -530,7 +528,7 @@ def list_prices_wallpaper(territory):
|
||||
|
||||
@mod.route("/list-prices/<string:territory>/canvas")
|
||||
def list_prices_canvas(territory):
|
||||
canvases = PrintProduct.query.canvases().with_relations().all()
|
||||
canvases = PrintProduct.query.canvases().all()
|
||||
market = market_model.from_territory(territory)
|
||||
|
||||
result = {}
|
||||
@@ -547,7 +545,7 @@ def list_prices_canvas(territory):
|
||||
|
||||
@mod.route("/list-prices/<string:territory>/poster")
|
||||
def list_prices_posters(territory):
|
||||
posters = PrintProduct.query.posters().with_relations().all()
|
||||
posters = PrintProduct.query.posters().all()
|
||||
market = market_model.from_territory(territory)
|
||||
|
||||
result = {}
|
||||
@@ -564,7 +562,7 @@ def list_prices_posters(territory):
|
||||
|
||||
@mod.route("/list-prices/<string:territory>/framed-print")
|
||||
def list_prices_framed_prints(territory):
|
||||
framed_prints = PrintProduct.query.framed_prints().with_relations().all()
|
||||
framed_prints = PrintProduct.query.framed_prints().all()
|
||||
market = market_model.from_territory(territory)
|
||||
|
||||
result = {}
|
||||
|
||||
Reference in New Issue
Block a user