Example #1
0
    def get_data(self, page, remove_form, url_args):
        all_images_name = self.get_images_name_sorted()

        n_items = len(all_images_name)

        per_page = app.config["ADMIN_N_IMAGES_PER_PAGE"]

        range = Utils.get_page_range(page=page, n_items=n_items, per_page=per_page)
        sliced_images_name = all_images_name[range[0]:range[1]]

        return {
            "navbar_data": navbar_data_provider.get_data(active_tab_name=NavbarTabNames.images),
            "super_table_data": {
                "n_items": n_items,
                "paginator_data": paginator_data_provider.get_data(
                    page=page,
                    n_items=n_items,
                    per_page=per_page,
                    url_endpoint="admin_images",
                ),
                "table_data": self.get_table_data(
                    images_name=sliced_images_name,
                    remove_form=remove_form,
                ),
                "empty_msg": "Nenhuma imagem foi encontrada.",
            },
        }
Example #2
0
 def sample_data_0(self):
     data = {
         "navbar_data": navbar_data_provider.get_data(active_tab_name=NavbarTabNames.home),
         "n_new_orders": 3,
         "new_orders_href": url_for("admin_orders", order_status=OrderStatus.PAID, page=1),
     }
     return data
Example #3
0
 def get_add_data(self, form):
     data = {
         "navbar_data":
         navbar_data_provider.get_data(
             active_tab_name=NavbarTabNames.products),
         "form":
         form,
     }
     return data
    def get_data(self, page, simple_submit_form, filter_subcategory_form,
                 category_id, active, url_args):
        q = self.get_filtered_query(category_id=category_id, active=active)
        q = q.order_by(asc(Subcategory.name))

        n_items = q.count()

        filter_subcategory_form.category_id.data = int(category_id)
        filter_subcategory_form.active.data = str(active)

        per_page = app.config["ADMIN_N_SUBCATEGORIES_PER_PAGE"]

        return {
            "navbar_data":
            navbar_data_provider.get_data(
                active_tab_name=NavbarTabNames.products),
            "super_table_data": {
                "filter_data": {
                    "form":
                    filter_subcategory_form,
                    "action":
                    url_for("admin_product_subcategories",
                            **(Utils.new_merged_dic(url_args, {"page": 1}))),
                    "n_items":
                    n_items
                },
                "paginator_data":
                paginator_data_provider.get_data(
                    page=page,
                    n_items=n_items,
                    per_page=per_page,
                    url_endpoint="admin_product_subcategories",
                    url_args=url_args),
                "table_data":
                self.get_table_data(
                    subcategories=q.slice(*Utils.get_page_range(
                        page=page, n_items=n_items, per_page=per_page)).all(),
                    url_args=url_args,
                    simple_submit_form=simple_submit_form),
                "empty_msg":
                "Nenhuma subcategoria foi encontrada.",
            }
        }
Example #5
0
    def get_edit_data(self, form, category_id, url_args):
        category = db_manager.get_category(category_id=category_id)

        if not category:
            raise InvalidParamError(message="Category not found")

        form.category.data = category.name

        data = {
            "navbar_data":
            navbar_data_provider.get_data(
                active_tab_name=NavbarTabNames.products),
            "form":
            form,
            "category_id":
            category_id,
            "url_args":
            url_args,
        }
        return data
    def get_edit_data(self, form, subcategory_id, url_args):
        subcategory = Subcategory.query.filter(
            Subcategory.id == subcategory_id).one_or_none()

        if not subcategory:
            raise InvalidParamError(message="Subcategory not found")

        form.subcategory.data = subcategory.name
        form.category_id.data = subcategory.category_id

        data = {
            "url_args":
            url_args,
            "navbar_data":
            navbar_data_provider.get_data(
                active_tab_name=NavbarTabNames.products),
            "form":
            form,
            "subcategory_id":
            subcategory_id,
        }
        return data
    def get_edit_data(self, form, product_id, url_args):
        product = db_manager.get_product(product_id=product_id)

        if not product:
            raise InvalidParamError()

        category_id = product.category_id
        if not category_id:
            category_id = 0
        subcategory_id = product.subcategory_id
        if not subcategory_id:
            subcategory_id = 0

        form.title.data = product.title
        form.category_subcategory.data = str(category_id) + "/" + str(
            subcategory_id)
        form.price.data = str(product.price)
        form.stock_quantity.data = str(product.stock_quantity)
        form.stop_sell_stock_quantity.data = str(
            product.stop_sell_stock_quantity)
        form.summary.data = product.summary

        form.image_1.data = product.image_1
        form.image_2.data = product.image_2
        form.image_3.data = product.image_3
        form.image_4.data = product.image_4
        form.image_5.data = product.image_5
        form.image_6.data = product.image_6
        form.image_7.data = product.image_7
        form.image_8.data = product.image_8
        form.image_9.data = product.image_9
        form.image_10.data = product.image_10

        form.tab_1_title.data = product.tab_1_title
        form.tab_1_content.data = product.tab_1_content
        form.tab_2_title.data = product.tab_2_title
        form.tab_2_content.data = product.tab_2_content
        form.tab_3_title.data = product.tab_3_title
        form.tab_3_content.data = product.tab_3_content
        form.tab_4_title.data = product.tab_4_title
        form.tab_4_content.data = product.tab_4_content
        form.tab_5_title.data = product.tab_5_title
        form.tab_5_content.data = product.tab_5_content
        form.tab_6_title.data = product.tab_6_title
        form.tab_6_content.data = product.tab_6_content
        form.tab_7_title.data = product.tab_7_title
        form.tab_7_content.data = product.tab_7_content
        form.tab_8_title.data = product.tab_8_title
        form.tab_8_content.data = product.tab_8_content
        form.tab_9_title.data = product.tab_9_title
        form.tab_9_content.data = product.tab_9_content
        form.tab_10_title.data = product.tab_10_title
        form.tab_10_content.data = product.tab_10_content

        data = {
            "url_args":
            url_args,
            "navbar_data":
            navbar_data_provider.get_data(
                active_tab_name=NavbarTabNames.products),
            "form":
            form,
            "product_id":
            product_id,
        }
        return data
    def get_data(self, page, simple_submit_form, stock_operation_form,
                 filter_product_form, category_id, subcategory_id, active,
                 category_subcategory, url_args, selected_sort_method):
        q = self.get_filtered_query(category_id=category_id,
                                    subcategory_id=subcategory_id,
                                    active=active)
        q = q.order_by(self.get_order_by_arg(sort_method=selected_sort_method))

        n_items = q.count()

        filter_product_form.category_subcategory.data = category_subcategory
        filter_product_form.active.data = str(active)

        per_page = app.config["ADMIN_N_PRODUCTS_PER_PAGE"]

        return {
            "navbar_data":
            navbar_data_provider.get_data(
                active_tab_name=NavbarTabNames.products),
            "super_table_data": {
                "filter_data": {
                    "form":
                    filter_product_form,
                    "action":
                    url_for("admin_products",
                            **(Utils.new_merged_dic(url_args, {"page": 1}))),
                    "n_items":
                    n_items
                },
                "paginator_data":
                paginator_data_provider.get_data(page=page,
                                                 n_items=n_items,
                                                 per_page=per_page,
                                                 url_endpoint="admin_products",
                                                 url_args=url_args),
                "sort_method_query_arg_name":
                String.QueryArgName.SORT_METHOD,
                "sort_methods": [
                    self.get_sort_method(selected_sort_method, "Título",
                                         int(AdminProductsSortMethod.TITLE)),
                    self.get_sort_method(
                        selected_sort_method, "Menor preço",
                        int(AdminProductsSortMethod.LOWEST_PRICE)),
                    self.get_sort_method(
                        selected_sort_method, "Maior preço",
                        int(AdminProductsSortMethod.BIGGEST_PRICE)),
                    self.get_sort_method(
                        selected_sort_method, "Menor estoque",
                        int(AdminProductsSortMethod.LOWEST_STOCK)),
                    self.get_sort_method(
                        selected_sort_method, "Maior estoque",
                        int(AdminProductsSortMethod.HIGHER_STOCK)),
                    self.get_sort_method(
                        selected_sort_method, "Mais vendido",
                        int(AdminProductsSortMethod.BEST_SELLER)),
                    self.get_sort_method(
                        selected_sort_method, "Menos vendido",
                        int(AdminProductsSortMethod.LESS_SOLD)),
                ],
                "table_data":
                self.get_table_data(products=q.slice(*Utils.get_page_range(
                    page=page, n_items=n_items, per_page=per_page)).all(),
                                    url_args=url_args,
                                    simple_submit_form=simple_submit_form,
                                    stock_operation_form=stock_operation_form),
                "empty_msg":
                "Nenhum produto foi encontrado.",
            }
        }