90 lines
3.4 KiB
Python
90 lines
3.4 KiB
Python
# modules/product_page.py
|
|
import flet as ft
|
|
import logging
|
|
from modules import product_filter, export, backend
|
|
|
|
class ProductPage:
|
|
def __init__(self, page: ft.Page, logger: logging.Logger):
|
|
self.page = page
|
|
self.logger = logger
|
|
self.products = [] # 전체 상품 목록
|
|
self.build_content()
|
|
|
|
def build_content(self):
|
|
self.logger.debug("Building ProductPage content")
|
|
# 버튼들
|
|
self.forbidden_filter_btn = ft.ElevatedButton("금지어 필터링", on_click=self.filter_forbidden)
|
|
self.category_filter_btn = ft.ElevatedButton("카테고리 필터링", on_click=self.filter_category)
|
|
self.sourcing_market_dropdown = ft.Dropdown(
|
|
label="소싱몰 목록",
|
|
options=[ft.dropdown.Option("타오바오"), ft.dropdown.Option("1688")],
|
|
key="sourcing_market"
|
|
)
|
|
self.source_btn = ft.ElevatedButton("소싱하기", on_click=self.sourcing_products)
|
|
self.export_btn = ft.ElevatedButton("출력", on_click=self.export_products)
|
|
# 상품 목록 테이블
|
|
self.product_table = ft.DataTable(
|
|
columns=[
|
|
ft.DataColumn(ft.Text("상품명")),
|
|
ft.DataColumn(ft.Text("카테고리")),
|
|
ft.DataColumn(ft.Text("이미지 URL")),
|
|
ft.DataColumn(ft.Text("소싱 URL")),
|
|
],
|
|
rows=[],
|
|
expand=True,
|
|
key="product_table"
|
|
)
|
|
self.content = ft.Column(
|
|
[
|
|
ft.Row([self.forbidden_filter_btn, self.category_filter_btn, self.sourcing_market_dropdown, self.source_btn, self.export_btn]),
|
|
self.product_table
|
|
],
|
|
spacing=10,
|
|
)
|
|
|
|
def set_products(self, products):
|
|
self.logger.debug(f"ProductPage.set_products() 호출됨, 상품 수: {len(products)}")
|
|
self.products = products
|
|
self.update_table()
|
|
|
|
def update_table(self):
|
|
rows = []
|
|
for p in self.products:
|
|
row = ft.DataRow(cells=[
|
|
ft.DataCell(ft.Text(p.get("name", ""))),
|
|
ft.DataCell(ft.Text(p.get("category", ""))),
|
|
ft.DataCell(ft.Text(p.get("image_url", ""))),
|
|
ft.DataCell(ft.Text(p.get("sourcing_url", ""))),
|
|
])
|
|
rows.append(row)
|
|
self.product_table.rows = rows
|
|
self.page.update()
|
|
|
|
def filter_forbidden(self, e):
|
|
self.logger.debug("ProductPage.filter_forbidden() 호출됨")
|
|
self.products = product_filter.filter_forbidden_words(self.products)
|
|
self.update_table()
|
|
|
|
def filter_category(self, e):
|
|
self.logger.debug("ProductPage.filter_category() 호출됨")
|
|
self.products = product_filter.filter_forbidden_categories(self.products)
|
|
self.update_table()
|
|
|
|
def sourcing_products(self, e):
|
|
self.logger.debug("ProductPage.sourcing_products() 호출됨")
|
|
selected_market = self.sourcing_market_dropdown.value
|
|
sourced = []
|
|
for product in self.products:
|
|
sourcing_url = backend.sourcing_product(product.get("image_url", ""), selected_market)
|
|
product["sourcing_url"] = sourcing_url
|
|
sourced.append(product)
|
|
self.products = sourced
|
|
self.update_table()
|
|
|
|
def export_products(self, e):
|
|
self.logger.debug("ProductPage.export_products() 호출됨")
|
|
export.export_to_excel(self.products)
|
|
|
|
def get_content(self):
|
|
return self.content
|