Exemplo n.º 1
0
def admin_product_categories(page):
    simple_submit_form = SimpleSubmitForm()
    filter_form = CategoryFilterForm()

    try:
        # Getting optional parameters
        active = request.args.get('active')

        # Setting default value to optional parameters
        if not active:
            active = "True"

        url_args = {
            "active": active,
            "page": page,
        }

        # Converting query parameters from string type to his respective python type
        active = ast.literal_eval(active)

        data = categories_data_provider.get_data(
            page=page,
            filter_form=filter_form,
            simple_submit_form=simple_submit_form,
            url_args=url_args,
            active=active)
        return render_template("admin/products/categories.html", data=data)
    except Exception as e:
        log_unrecognized_exception(e)
        abort(500)
Exemplo n.º 2
0
def admin_remove_image(image_name):
    remove_form = SimpleSubmitForm()

    try:
        if not remove_form.validate_on_submit():
            raise InsecurePostException()

        file_path = os.path.join(app.config['UPLOADED_IMAGES_FOLDER'],
                                 image_name)
        if os.path.exists(file_path):
            os.remove(file_path)

        return ('', 204)
    except Exception as e:
        log_unrecognized_exception(e)
        return ("", 500)
Exemplo n.º 3
0
def admin_activate_product(product_id):
    reactivate_form = SimpleSubmitForm()

    try:
        if not reactivate_form.validate_on_submit():
            raise InsecurePostException()

        product = db_manager.get_product(product_id=product_id)

        if not product:
            raise InvalidUrlArgError("Product not found")

        product.active = True
        db_manager.add(product)
        db_manager.commit()

        return "", 204
    except Exception as e:
        db_manager.rollback()
        log_unrecognized_exception(e)
        abort(500)
Exemplo n.º 4
0
def admin_activate_product_subcategory(subcategory_id):
    simple_submit_form = SimpleSubmitForm()

    try:
        if not simple_submit_form.validate_on_submit():
            raise InsecurePostException()

        subcategory = db_manager.get_subcategory(subcategory_id=subcategory_id)

        if not subcategory:
            raise InvalidUrlArgError("Subcategory not found")

        subcategory.active = True

        db_manager.add(subcategory)
        db_manager.commit()

        return "", 204
    except Exception as e:
        db_manager.rollback()
        log_unrecognized_exception(e)
        return "", 500
Exemplo n.º 5
0
def admin_disable_product_category(category_id):
    disable_form = SimpleSubmitForm()

    try:
        if not disable_form.validate_on_submit():
            raise InsecurePostException()

        category = db_manager.get_category(category_id=category_id)

        if not category:
            raise InvalidUrlArgError("Category not found")

        category.active = False

        db_manager.add(category)
        db_manager.commit()

        return "", 204
    except Exception as e:
        db_manager.rollback()
        log_unrecognized_exception(e)
        abort(500)
Exemplo n.º 6
0
def admin_images(page):
    remove_form = SimpleSubmitForm()

    url_args = {"page": page}

    try:
        data = images_data_provider.get_data(page=page,
                                             remove_form=remove_form,
                                             url_args=url_args)
        return render_template("admin/images/images.html", data=data)
    except Exception as e:
        log_unrecognized_exception(e)
        abort(500)
Exemplo n.º 7
0
def admin_product_subcategories(page):
    filter_subcategory_form = FilterSubcategoryForm()
    simple_submit_form = SimpleSubmitForm()

    try:
        # Getting optional parameters
        category_id = request.args.get('category_id')
        active = request.args.get('active')

        # Setting default value to optional parameters
        if not category_id:
            category_id = "0"
        if not active:
            active = "True"

        url_args = {
            "page": page,
            "category_id": category_id,
            "active": active,
        }

        # Converting query parameters from string type to his respective python type
        category_id = int(category_id)
        active = ast.literal_eval(active)

        filter_subcategory_form.add_category_choices()

        data = subcategories_data_provider.get_data(
            page=page,
            simple_submit_form=simple_submit_form,
            filter_subcategory_form=filter_subcategory_form,
            category_id=category_id,
            active=active,
            url_args=url_args)
        return render_template("admin/products/subcategories.html", data=data)
    except Exception as e:
        log_unrecognized_exception(e)
        abort(500)
Exemplo n.º 8
0
def admin_products(page):
    filter_product_form = FilterProductForm()
    simple_submit_form = SimpleSubmitForm()
    stock_operation_form = StockOperationForm()

    try:
        # Getting optional parameters
        category_subcategory = request.args.get('category_subcategory')
        active = request.args.get('active')
        sort_method = request.args.get(String.QueryArgName.SORT_METHOD)

        # Setting default value to optional parameters
        if not category_subcategory:
            category_subcategory = "0/0"
        if not active:
            active = "True"
        if not sort_method:
            sort_method = int(AdminProductsSortMethod.TITLE)

        url_args = {
            "category_subcategory": category_subcategory,
            "active": active,
            "page": page,
            String.QueryArgName.SORT_METHOD: sort_method,
        }

        # Converting query parameters from string type to his respective python type
        category_id = None
        subcategory_id = None
        try:
            category_id = int(category_subcategory.split('/')[0])
            if category_id == 0:
                category_id = None

            subcategory_id = int(category_subcategory.split('/')[1])
            if subcategory_id == 0:
                subcategory_id = None

            active = ast.literal_eval(active)

            sort_method = int(sort_method)
        except:
            abort(422)

        filter_product_form.add_category_subcategory_choices()

        data = products_data_provider.get_data(
            page=page,
            simple_submit_form=simple_submit_form,
            stock_operation_form=stock_operation_form,
            filter_product_form=filter_product_form,
            category_id=category_id,
            subcategory_id=subcategory_id,
            active=active,
            category_subcategory=category_subcategory,
            url_args=url_args,
            selected_sort_method=sort_method,
        )
        return render_template("admin/products/products.html", data=data)
    except Exception as e:
        log_unrecognized_exception(e)
        abort(500)