Example #1
0
def update_product(id):
    item = Product.query.get(id)
    if not item:
        return Responses.NOT_EXIST()
    json_dict = request.json
    if len(item.update(json_dict['product'])) > 0:
        return Responses.OPERATION_FAILED()

    current_variations = Variation.query.filter_by(product_id=item.id).all()
    current_variations_names = []
    for variation in current_variations:
        current_variations_names.append(variation.name)

    variations_dict = json_dict['variations']
    for variation_dict in variations_dict:
        variation = Variation()
        variation.update_from_dict(variation_dict)
        if variation.next_available_date != None:  # ensure this is a date string
            if is_date(variation.next_available_date):
                variation.next_available_date = datetime.datetime.strptime(
                    variation.next_available_date, '%Y-%m-%d %H:%M:%S')

        if variation.name in current_variations_names:
            for current_variation in current_variations:
                if variation.name == current_variation.name:
                    if len(current_variation.update(variation_dict)) > 0:
                        return Responses.OPERATION_FAILED()
        else:  #a new variation is being added to this product
            if len(variation.update()) > 0:
                return Responses.OPERATION_FAILED()
    return Responses.SUCCESS()
Example #2
0
def update_order(id):
    item = Order.query.get(id)
    if not item:
        return Responses.NOT_EXIST()
    json_dict = request.json
    order_items_dict = json_dict['order_items']

    for order_item_dict in order_items_dict:
        order_item = OrderItem()
        if "id" in order_item_dict.keys():
            order_item = OrderItem.query.get(order_item_dict['id'])        
        order_item.update_from_dict(order_item_dict)
        if order_item.date_returned != None: # ensure this is a date string
            if is_date(order_item.date_returned):
                order_item.date_returned = datetime.datetime.strptime(order_item.date_returned, '%Y-%m-%d %H:%M:%S')   
        
        if not "id" in order_item_dict.keys():
             item.order_items.append(order_item)
        # else:
        #     for oid in item.order_items:
        #         if(oid.id == order_item_dict['id']):
        #             oid = order_item
    
    item.update_from_dict(json_dict)
    # re enable if customers can call in to order
    # currently orders can only be made from customer UI 
    # only edit on the order is to the status
    #item.calculate_cost()
        
    if len(item.update(force_insert=True)) > 0:
        return Responses.OPERATION_FAILED()
    return Responses.SUCCESS()
Example #3
0
def confirm_user_subscription(token):
    secret_key = ConfigValues.get_config_value(
        'EMAIL_PASSWORD_RESET_SECRET_KEY')

    confirm_serializer = URLSafeTimedSerializer(secret_key)
    try:
        email = confirm_serializer.loads(token,
                                         salt='email-confirm',
                                         max_age=3600)
    except SignatureExpired:
        return Responses.TOKEN_EXPIRED()
    json_dict = request.json
    email = json_dict['email']
    user = User.get_user_by_email(email)
    if not user:
        return Responses.NOT_EXIST()

    subscription_type = json_dict['subscription_type']
    subscription = SubscriptionType.get_items(subscription_type)

    start_date = date.today()
    end_date = start_date + relativedelta(months=int(1))
    #end_date = start_date + relativedelta(months=int(subscription.plan))

    user_subscription = UserSubscription(user.id, end_date, subscription.id)
    error = user_subscription.update()
    if len(error) > 0:
        Responses.OPERATION_FAILED()

    user.subscribed = True
    user_error = user.update()
    if len(user_error) > 0:
        Responses.OPERATION_FAILED()
    return Responses.SUCCESS()
Example #4
0
def update_user_order():
    item = Order.query.get(id)
    if not item:
        return Responses.NOT_EXIST()
    json_dict = request.json
    if json_dict['order_items']:
        order_items_dict = json_dict['order_items']

        for order_item_dict in order_items_dict:
            order_item = OrderItem()
            if "id" in order_item_dict.keys():
                order_item = OrderItem.query.get(order_item_dict['id'])
            order_item.update_from_dict(order_item_dict)

            if not "id" in order_item_dict.keys():
                item.order_items.append(order_item)
            else:
                for oid in item.order_items:
                    if (oid.id == order_item_dict['id']):
                        oid = order_item

    item.calculate_cost()

    if len(item.update(force_insert=True)) > 0:
        return Responses.OPERATION_FAILED()
    return Responses.SUCCESS()
def update_order_status(id):
    item = OrderStatus.query.get(id)
    if not item:
        return Responses.NOT_EXIST()
    json_dict = request.json
    if len(item.update(json_dict)) > 0:
        return Responses.OPERATION_FAILED()
    return Responses.SUCCESS()
def update_article_categories(id):
    item = ArticleCategory.query.get(id)
    if not item:
        return Responses.NOT_EXIST()
    json_dict = request.json
    if len(item.update(json_dict)) > 0:
        return Responses.OPERATION_FAILED()
    return Responses.SUCCESS()
Example #7
0
def update_product_category(id):
    item = ProductCategory.query.get(id)
    if not item:
        return Responses.NOT_EXIST()
    json_dict = request.json
    if len(item.update(json_dict)) > 0:
        return Responses.OPERATION_FAILED()
    return Responses.SUCCESS()
Example #8
0
def remove_unconfirmed_user_order(id):
    item = Order.query.get(id)
    if not item:
        return Responses.NOT_EXIST()
    item.delete()

    if len(item.delete()) > 0:
        return Responses.OPERATION_FAILED()
    return Responses.SUCCESS()
Example #9
0
def update_confirmed_user_order(id):
    item = Order.query.get(id)
    if not item:
        return Responses.NOT_EXIST()
    json_dict = request.json
    item.update_from_dict(json_dict)

    # if not json_dict['payment_ref']:
    #     return Responses.OPERATION_FAILED()

    if len(item.update(force_insert=True)) > 0:
        return Responses.OPERATION_FAILED()
    return Responses.SUCCESS()
def update_config_value(name):
    """
    update_config_value updates setting by using name

    """
    item = ConfigValues.query.filter_by(name=name).first()

    if not item:
        return Responses.NOT_EXIST()
    json_dict = request.json

    if len(item.update(json_dict)) > 0:
        return Responses.OPERATION_FAILED()
    return Responses.SUCCESS()
Example #11
0
def update_user(email):
    """
    update_user updates user by using email

    Args:
        email (string): 

    Returns:
        (string,int): user info if update succesful, otherwise response no need to update
    """
    item = User.get_user_by_email(email)
    if not item:
        return Responses.NOT_EXIST()
    json_dict = request.json
    if len(item.update(json_dict)) > 0:
        return Responses.OPERATION_FAILED()
    return Responses.SUCCESS()
Example #12
0
def update_subscription(id):
    """
    update_subscription updates user subscription by using id

    Args:
        id (int): 

    Returns:
        (string,int): update succesful, otherwise response no need to update
    """
    item = UserSubscription.query.get(id)
    if not item:
        return Responses.NOT_EXIST()
    json_dict = request.json
    if len(item.update(json_dict)) > 0:
        return Responses.OPERATION_FAILED()
    return Responses.SUCCESS()
Example #13
0
def update_subscription_type(plan):
    """
    update_subscription_type updates subscription type by using duration in months

    Args:
        plan (string): 

    Returns:
        (string,int): update succesful, otherwise response no need to update
    """
    item = SubscriptionType.get_items(plan=plan)[0]
    if not item:
        return Responses.NOT_EXIST()
    json_dict = request.json
    if len(item.update(json_dict)) > 0:
        return Responses.OPERATION_FAILED()
    return Responses.SUCCESS()
Example #14
0
def user_subscribe():
    json_dict = request.json
    email = json_dict['email']
    user = User.get_user_by_email(email)
    if not user:
        return Responses.NOT_EXIST()
    if not user.email_confirmed:
        return Responses.UNCONFIRMED_USER()

    subscription_type = json_dict['subscription_type']
    subscription = SubscriptionType.get_items(plan=subscription_type)[0]
    subscription_price = subscription.price

    start_date = date.today()
    end_date = start_date + relativedelta(months=1)
    user_subscription_detail = UserSubscriptionDetail(start_date, end_date,
                                                      subscription.plan,
                                                      subscription_price)

    return res(user_subscription_detail.as_dict())
Example #15
0
def update_vouchers(name):
    """
    update_voucher updates voucher by using name

    Args:
        name (string): 

    Returns:
        (string,int): update succesful, otherwise response no need to update
    """
    item = Voucher.get_voucher(name)
    if not item:
        return Responses.NOT_EXIST()
    json_dict = request.json

    if (('discount_percent_off' in json_dict
         and float(json_dict['discount_percent_off']) > 0)
            and ('discount_fixed_amount' in json_dict
                 and float(json_dict['discount_fixed_amount']) > 0)):
        return Responses.OPERATION_FAILED(Messages.VOUCHER_DETAILS_WRONG)

    if len(item.update(json_dict)) > 0:
        return Responses.OPERATION_FAILED()
    return Responses.SUCCESS()