コード例 #1
0
def add_product(request):
    product_dto = ProductDTO()
    if request.method == 'POST':
        product_dto.name = request.POST['product_name']
        product_dto.price = request.POST['product_price']
        product_dto.currency = request.POST['product_currency']
        product_dto.username = request.POST['username']
        product_dto.email = request.POST['email']
        product_dto.url = request.POST['link']
        product_dto.duration = request.POST.get('duration') # int, in days
        up = request.POST.get('upwards')  # float, in currency
        if up == '':
            product_dto.threshold_up = '0.01'
        else:
            product_dto.threshold_up = up.replace('£', '')
        down = request.POST.get('downwards')  # float, in currency
        if down == '':
            product_dto.threshold_down = '0.01'
        else:
            product_dto.threshold_down = down.replace('£', '')
        product_dto.promocode = request.POST['promocode']
    print(product_dto)
    user_check = service_add.user_limit_duplicate_check(product_dto)
    print(user_check)
    if user_check[0]:
        user = user_check[1]
        context = service_add.get_add_product_context(user, product_dto)
        return render(request, 'pricecheck/add_product_result.html', context)
    else:
        errors = user_check[1]
        errors['email'] = product_dto.email
        errors['url'] = product_dto.url
        context = {**service.get_base_context(), **errors}
        return render(request, 'pricecheck/add_product_error_duplicate.html', context)
コード例 #2
0
ファイル: service_info.py プロジェクト: latidude99/latidude99
def get_product_info_context(product_dto, flag):
    info = get_product_info(product_dto, flag)
    context = {
        'product_dto': info[0],
        'prices': info[1],
    }
    ctx = {
        **service.get_base_context(),
        **service.get_index_context(),
        **context
    }
    return ctx
コード例 #3
0
ファイル: service_add.py プロジェクト: latidude99/latidude99
def get_add_product_context(user, product):
    product_dto = add_product(user, product)
    context = {
        'product_dto': product_dto,
        'success_info_1': SUCCESS_INFO_1,
        'success_info_2': SUCCESS_INFO_2,
        'success_info_3': SUCCESS_INFO_3,
        'success_info_4': SUCCESS_INFO_4,
        'success_info_5': SUCCESS_INFO_5,
        'success_info_6': SUCCESS_INFO_6,
    }
    ctx = {**service.get_base_context(), **context}
    return ctx
コード例 #4
0
ファイル: service_add.py プロジェクト: latidude99/latidude99
def get_context_confirm(confirm_code):
    if Product.objects.using('pricecheck_34').filter(
            confirm_code=confirm_code).exists():
        product_db = Product.objects.using('pricecheck_34').get(
            confirm_code=confirm_code)
        product_db.confirmed = True
        product_db.save(using='pricecheck_34')
        product_dto = service_converters.convert_product_db2dto(product_db)
        user = product_db.user
        product_dto.product_max_count = user.max_items_tracked
        context = {
            'product_dto': product_dto,
            'success_info': SUCCESS_INFO,
            'failure_info': FAILURE_INFO,
        }
        ctx = {**service.get_base_context(), **context}
        print(user)
        #print(product_db)
        print(context)
        return [True, ctx]
    else:
        context = {'failure_info': FAILURE_INFO}
        ctx = {**service.get_base_context(), **context}
        return [False, ctx]
コード例 #5
0
ファイル: service_info.py プロジェクト: latidude99/latidude99
def get_product_list_context(email, user_id):
    info = get_product_list(email, user_id)
    context = {
        'status': info[0],
        'error_msg': info[1],
        'products': info[2],
        'user': info[3]
    }
    print(info)
    ctx = {
        **service.get_base_context(),
        **service.get_index_context(),
        **context
    }
    return ctx