Exemplo n.º 1
0
def add_product_category():
    json_dict = request.json
    item = ProductCategory()
    error = item.update(json_dict)
    if len(error) > 0:
        return Responses.OPERATION_FAILED()
    return res(item.as_dict())
Exemplo n.º 2
0
def user_get_product_pages_category(
        category=None):  # pagination details for products filtered by category
    """
    get_products meeting criteria
    Args:
        id ([type]): product id

    Returns:
        [type]: [description]
    """
    page, per_page = get_page_from_args()
    sort_by = request.args.get('sort_by')
    is_desc = parse_int(request.args.get('is_desc'))
    category_details = []
    if request.args.get('category') is None:
        category_details = ProductCategory.get_category_from_name(category)
    else:
        category_details = ProductCategory.get_category_from_name(
            request.args.get('category'))
    cat_id = category_details[0].id

    page_details = Product.get_items_pages(category_id=cat_id,
                                           page=page,
                                           per_page=per_page,
                                           sort_by=sort_by,
                                           is_desc=is_desc)

    return res({
        "total_items": page_details.total,
        "no_of_pages": page_details.pages,
        "per_page": page_details.per_page
    })
Exemplo n.º 3
0
def user_get_product_categories(id=None):
    page, per_page = get_page_from_args()
    name = request.args.get('name')
    items = [ProductCategory.query.get(id)
             ] if id else ProductCategory.get_items(
                 name=name, page=page, per_page=per_page)
    return res([item.as_dict() for item in items])
def pump_product_categories_table():
    print('product categories')

    categories = []

    for category in categories:
        try:
            ProductCategory(name=category).save()
        except:
            pass
Exemplo n.º 5
0
def admin_product_category():
    form = ProductCategoryForm()
    categories = ProductCategory.query.all()
    if request.method=='POST':
        category = ProductCategory(
            cat_name=form.cat_name.data
        )
        db.session.add(category)
        db.session.commit()
        return redirect(url_for('admin_product_category'))
    return loginCheck(render_template('admin/product_category.html',form=form,categories=categories))
Exemplo n.º 6
0
def insert_brand_product_relations(bname, brand_dict):
    brand = Brand(bname, float(format(brand_dict['avg_price'], '.2f')),
                  float(format(brand_dict['avg_rating'], '.2f')),
                  len(brand_dict['products']), brand_dict['image_url'])
    db.session.add(brand)
    db.session.flush()
    for prod in brand_dict['products']:
        cur_product = PRODUCTS[prod]
        product = Product(brand.id, cur_product['name'],
                          cur_product['description'],
                          float(format(cur_product['price'], '.2f')),
                          float(format(cur_product['rating'],
                                       '.2f')), cur_product['image_url'])
        db.session.add(product)
        db.session.flush()

        # Add product_tag relation
        for tag in cur_product['tags']:
            product.tags.append(
                Tag.query.filter_by(name=get_tag_name(tag)).first())

        # Add product_color relation
        for color in cur_product['colors']:
            product.colors.append(
                Color.query.filter_by(name=color['colour_name']).first())

        # Add product_category relation
        cid = cur_product['category']
        sid = None
        if 'sub_category' in cur_product:
            sid = cur_product['sub_category']

        product_category = ProductCategory(product.id, get_category_id(cid),
                                           get_sub_category_id(sid))
        db.session.add(product_category)

        brand.products.append(product)
    db.session.commit()
Exemplo n.º 7
0
                                       'adayahouse')
 STRIPE_PUBLISHABLE_KEY = ConfigValues('STRIPE_PK', '')
 STRIPE_S_KEY = ConfigValues('STRIPE_SK', '')
 subtype = SubscriptionType(plan='Adaya Lite', price=10)
 subtype2 = SubscriptionType(plan='Adaya Lifestyle', price=40)
 subtype.stripe_subscription_product = 'prod_HKKYExqtgZlZ0R'
 subtype.stripe_price = 'price_HKKb1y8VgSax36'
 subtype2.stripe_subscription_product = 'prod_HKKboFqONk8aba'
 subtype2.stripe_price = 'price_HKKcUelIoiOo5m'
 usersubscription = UserSubscription()
 usersubscription.user_id = 2
 usersubscription.start_date = datetime.now()
 usersubscription.end_date = datetime.strptime('06-02-2020 05:58:00',
                                               '%d-%m-%Y %H:%M:%S')
 usersubscription.subscription_type = subtype
 food_category = ProductCategory('food')
 clothes_category = ProductCategory('cloth')
 food_article = ArticleCategory('food-article')
 clothes_article = ArticleCategory('cloth-article')
 status = ArticleStatus('draft')
 order_status = OrderStatus('completed')
 db.session.add(order_status)
 db.session.add(food_article)
 db.session.add(clothes_article)
 db.session.add(food_category)
 db.session.add(clothes_category)
 for x in range(10):
     product = Product(randomString(10))
     product.image = 'https://i.imgur.com/xyAZ6sF.jpg,https://i.imgur.com/TcT4srW.jpg,https://i.imgur.com/79QF80y.jpg,https://i.imgur.com/CIAcwiV.jpg'
     product.images_album = 'P95VLN7'
     article = Article(randomString(10))
Exemplo n.º 8
0
def user_get_productcategories(category=None):
    """
    get_products meeting criteria
    Args:
        id ([type]): product id

    Returns:
        [type]: [description]
    """
    page, per_page = get_page_from_args()
    sort_by = request.args.get('sort_by')
    sort_by_price = request.args.get('sort_by_price')
    is_desc = parse_int(request.args.get('is_desc'))

    category_details = []
    if request.args.get('category') is None:
        category_details = ProductCategory.get_category_from_name(category)
    else:
        category_details = ProductCategory.get_category_from_name(
            request.args.get('category'))
    print(category)
    cat_id = category_details[0].id

    # category_details = ProductCategory.get_category_from_name(category)
    # cat_id = category_details[0].id

    items = Product.get_items(category_id=cat_id,
                              page=page,
                              per_page=per_page,
                              sort_by=sort_by,
                              is_desc=is_desc)

    variations = Variation.get_items(
        category_id=None,
        page=1,
        per_page=per_page,
        sort_by=sort_by,
        is_desc=is_desc
    )  # TODO UPDATE from one page, done as only currently small number of prods

    all_product_variations = []

    for item in items:
        available_product_variations = []
        for variation in variations:
            if (item.id == variation.product_id):
                available_product_variations.append(variation)

        product_variations = ProductVariations(product=item)
        product_variations.variations = available_product_variations

        all_product_variations.append(product_variations)

    if sort_by_price == 'price':
        sorted_productVariations_by_price = sorted(
            all_product_variations,
            key=lambda x: x.variations[0].price,
            reverse=False)
        return res([
            product_variation.as_dict()
            for product_variation in sorted_productVariations_by_price
        ])

    return res([
        product_variation.as_dict()
        for product_variation in all_product_variations
    ])
Exemplo n.º 9
0
 def initProductCategory(self):
     product_data = self.readItem("PRODUCTS", "types")
     for item in product_data:
         self.add(ProductCategory(name=item))
         self.initQuantities(item.upper(), "quantities")
Exemplo n.º 10
0
def init_database():
    db = AC().db
    # Create the database and the database table
    db.create_all()
    member = Role("member")
    admin = Role("admin")
    user = User("*****@*****.**", "1q2w3e4r")
    user.email_confirmed = True
    user2 = User("*****@*****.**", "1q2w3e4r")
    user3 = User("*****@*****.**", "1q2w3e4r")
    user4 = User("*****@*****.**", "1q2w3e4r")
    user.role = admin
    user2.email_confirmed = True
    user2.subscribed = True
    user3.email_confirmed = True
    user3.subscribed = True
    user4.email_confirmed = False
    max_no_products_per_month = ConfigValues('max_no_products_per_month', 20)
    max_no_free_products_adayalite_user = ConfigValues(
        'max_no_free_products_adayalite_user', 4)
    max_no_of_items_per_order_adayalifestyle = ConfigValues(
        'max_no_of_items_per_order_adayalifestyle', 4)
    max_no_products_per_order = ConfigValues('max_no_products_per_order', 4)
    min_duration_of_rental = ConfigValues('min_duration_of_rental', 4)
    max_duration_of_rental = ConfigValues('max_duration_of_rental', 7)
    max_no_of_vouchers = ConfigValues('max_no_of_vouchers', 2)
    MAIL_USERNAME = ConfigValues('MAIL_USERNAME', '*****@*****.**')
    MAIL_PASSWORD = ConfigValues('MAIL_PASSWORD', 'adaya1234')
    MAIL_SERVER = ConfigValues('MAIL_SERVER', 'smtp.gmail.com')
    MAIL_PORT = ConfigValues('MAIL_PORT', 465)
    MAIL_DEFAULT_SENDER = ConfigValues('MAIL_DEFAULT_SENDER',
                                       '*****@*****.**')
    EMAIL_PASSWORD_RESET_SECRET_KEY = ConfigValues(
        'EMAIL_PASSWORD_RESET_SECRET_KEY', 'Thisisasecret!')
    SIB_KEY = ConfigValues('SIB_KEY', 'gzryVUPZHa1GW7n6')
    subtype = SubscriptionType(plan='Adaya Lite', price=10)
    subtype2 = SubscriptionType(plan='Adaya Premium', price=40)
    usersubscription = UserSubscription()
    usersubscription.user_id = 2
    usersubscription.current_start_date = datetime.now()
    usersubscription.current_end_date = datetime.strptime(
        '2020-09-06 05:58:00', '%Y-%m-%d %H:%M:%S')
    usersubscription.subscription_type = subtype
    usersubscription2 = UserSubscription()
    usersubscription2.user_id = 3
    usersubscription2.current_start_date = datetime.now()
    usersubscription2.current_end_date = datetime.strptime(
        '2020-08-06 05:58:00', '%Y-%m-%d %H:%M:%S')
    usersubscription2.subscription_type = subtype2
    voucher = Voucher('HAO20')
    voucher.discount_fixed_amount = 100
    voucher.product_id = 3
    voucher.redeem_by = datetime.strptime('2020-8-13 00:00:00',
                                          '%Y-%m-%d %H:%M:%S')
    voucher2 = Voucher('LUO20')
    voucher2.discount_fixed_amount = 8.00
    voucher2.product_id = 1
    voucher2.redeem_by = datetime.strptime('2020-8-13 00:00:00',
                                           '%Y-%m-%d %H:%M:%S')
    for x in range(1, 11):
        variation = Variation('S')
        variation.product_id = x
        variation.price = 10
        variation.stock = 1
        variation1 = Variation('M')
        variation1.product_id = x
        variation1.price = 20
        variation1.stock = 1
        variation2 = Variation('L')
        variation2.product_id = x
        variation2.price = 30
        variation2.stock = 1
        variation3 = Variation('XL')
        variation3.product_id = x
        variation3.price = 40
        variation3.stock = 1
        db.session.add(variation)
        db.session.add(variation1)
        db.session.add(variation2)
        db.session.add(variation3)
    db.session.add(max_no_products_per_order)
    db.session.add(max_no_products_per_month)
    db.session.add(max_no_free_products_adayalite_user)
    db.session.add(max_no_of_items_per_order_adayalifestyle)
    db.session.add(min_duration_of_rental)
    db.session.add(max_duration_of_rental)
    db.session.add(max_no_of_vouchers)
    db.session.add(MAIL_USERNAME)
    db.session.add(MAIL_PASSWORD)
    db.session.add(MAIL_SERVER)
    db.session.add(MAIL_PORT)
    db.session.add(MAIL_DEFAULT_SENDER)
    db.session.add(EMAIL_PASSWORD_RESET_SECRET_KEY)
    db.session.add(SIB_KEY)
    db.session.add(voucher)
    db.session.add(voucher2)
    db.session.add(member)
    db.session.add(user)
    db.session.add(user2)
    db.session.add(user3)
    db.session.add(user4)
    db.session.add(subtype)
    db.session.add(subtype2)
    db.session.add(usersubscription)
    db.session.add(usersubscription2)
    food_category = ProductCategory('food')
    clothes_category = ProductCategory('cloth')
    food_article = ArticleCategory('food-article')
    clothes_article = ArticleCategory('cloth-article')
    status = ArticleStatus('draft')
    order_status = OrderStatus('completed')
    db.session.add(order_status)
    db.session.add(food_article)
    db.session.add(clothes_article)
    db.session.add(food_category)
    db.session.add(clothes_category)
    for x in range(10):
        product = Product('Haoluo')
        article = Article(randomString(10))
        order = Order()
        order_item = OrderItem()
        order_item.quantity = 1
        order_item.variation_id = 2
        order_item.start_date = datetime.strptime('2020-4-1 00:00:00',
                                                  '%Y-%m-%d %H:%M:%S')
        order_item.end_date = datetime.strptime('2020-4-8 00:00:00',
                                                '%Y-%m-%d %H:%M:%S')
        order.order_items = []
        order.order_items.append(order_item)
        article_category = food_article
        category = food_category
        if x % 2 == 0:
            category = clothes_category
            article_category = clothes_article
        product.category = category
        article.category = article_category
        article.status = status
        db.session.add(order)
        db.session.add(product)
        db.session.add(order_item)
        db.session.add(article)
    db.session.commit()
    yield db
    db.drop_all()