Exemple #1
0
def confirm_order(order_id):
    confirmed_status = select('order_statuses', {'id': 3})
    try:
        update('orders', {'id': order_id},
               {'status_id': confirmed_status[0].id})
    except:
        abort(404)
Exemple #2
0
def edit(id):
    user = select_one_or_404('users', {'id': id})
    form = UserForm(obj=user)
    if form.validate_on_submit():
        try:
            data = {}
            if form.data['password'] != '' and form.data['confirm'] != '':
                m = hashlib.md5()
                password = form.data['password'].encode('utf-8')
                m.update(password)
                hashpass = m.hexdigest()
                data['password'] = hashpass

            if form.data['username'] != user.username:
                data['username'] = form.data['username']

            if data:
                update('users', {'id': id}, data)
        except IntegrityError as e:
            if 'username_unique' in e.pgerror:
                getattr(form, 'username').errors = (
                    'User with given name already exists.',
                )
            else:
                flash('Something went wrong, try again.', 'error')
    return render_template('users/create.html', form=form)
Exemple #3
0
def edit(id):
    product = select_row_from_table_by_id("products", id)
    images = []
    try:
        product = product[0]
    except IndexError:
        abort(404)

    form = ProductForm()
    if request.method == 'GET':
        form.prepopulate_data(product)
        images = get_product_images(id)

    if form.validate_on_submit():
        data = form.data.copy()
        data.pop("images", None)
        try:
            update("products", {"id": id}, data)
        except IntegrityError:
            form.name.errors = ('Product with given name already exists',)
            render_template('products/create.html', form=form)
        images = request.files.getlist("images")
        if images:
            for image in images:
                if image.filename:
                    save_image(image, product.id)
            return redirect(url_for('product.edit', id=id))

    return render_template('products/edit.html', form=form, images=images)
Exemple #4
0
def cancel_order(order_id):
    cancelled_status = select('order_statuses', {'id': 2})
    try:
        update('orders', {'id': order_id},
               {'status_id': cancelled_status[0].id})
    except:
        abort(404)
Exemple #5
0
def edit(id):
    user = select_one_or_404('users', {'id': id})
    form = UserForm(obj=user)
    if form.validate_on_submit():
        try:
            data = {}
            if form.data['password'] != '' and form.data['confirm'] != '':
                m = hashlib.md5()
                password = form.data['password'].encode('utf-8')
                m.update(password)
                hashpass = m.hexdigest()
                data['password'] = hashpass

            if form.data['username'] != user.username:
                data['username'] = form.data['username']

            if data:
                update('users', {'id': id}, data)
        except IntegrityError as e:
            if 'username_unique' in e.pgerror:
                getattr(form, 'username').errors = (
                    'User with given name already exists.', )
            else:
                flash('Something went wrong, try again.', 'error')
    return render_template('users/create.html', form=form)
Exemple #6
0
def cancel_order(order_id):
    cancelled_status = select('order_statuses', {'id': 2})
    try:
        update(
            'orders',
            {'id': order_id},
            {'status_id': cancelled_status[0].id}
        )
    except:
        abort(404)
Exemple #7
0
def confirm_order(order_id):
    confirmed_status = select('order_statuses', {'id': 3})
    try:
        update(
            'orders',
            {'id': order_id},
            {'status_id': confirmed_status[0].id}
        )
    except:
        abort(404)
Exemple #8
0
def update(pid=None):
    """ Updates the database

    Args:
        pid (str): Package id of the package to update.
    """
    kwargs = {k: parse(v) for k, v in request.args.to_dict().items()}
    sync = kwargs.pop('sync', False)
    whitelist = [
        'CHUNK_SIZE', 'ROW_LIMIT', 'ERR_LIMIT', 'MOCK_FREQ', 'TIMEOUT',
        'RESULT_TTL']

    with app.app_context():
        defaults = {
            k.lower(): v for k, v in app.config.items() if k in whitelist}

        opts = defaultdict(int, pid=pid, **defaults)
        opts.update(kwargs)
        base = 'http://%(HOST)s:%(PORT)s%(API_URL_PREFIX)s' % app.config
        endpoint = '%s/age' % base

        if sync:
            resp = {'result': utils.update(endpoint, **opts)}
        else:
            job = q.enqueue(utils.update, endpoint, **opts)
            result_url = '%s/result/%s/' % (base, job.id)

            resp = {
                'job_id': job.id,
                'job_status': job.get_status(),
                'result_url': result_url}

        return jsonify(**resp)
Exemple #9
0
def update_order(order_id, data):
    order_data = {
        'client_id': data['client'],
    }
    statuses = select('order_statuses', {'status_name': data['status']})
    if statuses:
        order_data['status_id'] = statuses[0].id
    update('orders', {'id': order_id}, order_data)

    delete('order_products', {'order_id': order_id})

    for product in data['products']:
        data_products = {
            'order_id': order_id,
            'product_id': product['product'],
            'price': product['price'],
            'quantity': product['quantity'],
        }
        insert('order_products', data_products)
Exemple #10
0
def update_order(order_id, data):
    order_data = {
        'client_id': data['client'],
    }
    statuses = select('order_statuses', {'status_name': data['status']})
    if statuses:
        order_data['status_id'] = statuses[0].id
    update('orders', {'id': order_id}, order_data)

    delete('order_products', {'order_id': order_id})

    for product in data['products']:
        data_products = {
            'order_id': order_id,
            'product_id': product['product'],
            'price': product['price'],
            'quantity': product['quantity'],
        }
        insert('order_products', data_products)
Exemple #11
0
def edit_client(form, client_id):
    client_data = {
        'name': form.data['name'],
        'surname': form.data['surname'],
        'email': form.data['email'],
    }

    utils.run_custom_query(
            """DELETE FROM CLIENT_PHONES WHERE CLIENT_ID = {}""".format(
                client_id
            ),
            fetch=False
        )
    utils.update('clients', {'id': client_id},  client_data)
    for phone in form.data['phones']:
        if phone['phone']:
            utils.insert(
                'client_phones',
                {'client_id': client_id, 'phone': phone['phone']}
            )
    if form.data['billing_address']:
        billing = utils.select('client_addresses', {'client_id': client_id, 'type': 'billing'})
        data = form.data['billing_address']
        utils.update(
            'addresses',
            {
                'id': billing[0].id,
            },
            {
                'country': data['country'],
                'city': data['city'],
                'street': data['street']
            }
        )
    if form.data['delivery_address']:
        delivery = utils.select('client_addresses', {'client_id': client_id, 'type': 'delivery'})
        data = form.data['delivery_address']
        utils.update(
            'addresses',
            {
                'id': delivery[0].id,
            },
            {
                'country': data['country'],
                'city': data['city'],
                'street': data['street']
            }
        )
Exemple #12
0
def edit(request, name):
    """ API edit. (<str:name>/edit) """
    api = API.objects.get(user=request.user, name=name)
    endpoints = Endpoint.objects.filter(api=api)
    if not api:
        context = {'permanent': True}
        return redirect('app:apis', **context)

    if request.method == 'POST':
        post = request.POST.get

        api = update(api, post)

        api.auth = 1 if post('auth') == 'None' else api.auth
        api.auth = 2 if post('auth') == 'Basic' else api.auth
        api.auth = 3 if post('auth') == 'Header' else api.auth
        api.auth = 4 if post('auth') == 'Params' else api.auth

        api.save()

    context = {'api': api, 'endpoints': endpoints}
    return render(request, 'edit.html', context)
Exemple #13
0
def update(pid=None):
    """ Updates the database

    Args:
        pid (str): Package id of the package to update.
    """
    kwargs = {k: parse(v) for k, v in request.args.to_dict().items()}
    sync = kwargs.pop('sync', False)
    whitelist = [
        'CHUNK_SIZE', 'ROW_LIMIT', 'ERR_LIMIT', 'MOCK_FREQ', 'TIMEOUT',
        'RESULT_TTL'
    ]

    with app.app_context():
        defaults = {
            k.lower(): v
            for k, v in app.config.items() if k in whitelist
        }

        opts = defaultdict(int, pid=pid, **defaults)
        opts.update(kwargs)
        base = 'http://%(HOST)s:%(PORT)s%(API_URL_PREFIX)s' % app.config
        endpoint = '%s/age' % base

        if sync:
            resp = {'result': utils.update(endpoint, **opts)}
        else:
            job = q.enqueue(utils.update, endpoint, **opts)
            result_url = '%s/result/%s/' % (base, job.id)

            resp = {
                'job_id': job.id,
                'job_status': job.get_status(),
                'result_url': result_url
            }

        return jsonify(**resp)
Exemple #14
0
def edit_client(form, client_id):
    client_data = {
        'name': form.data['name'],
        'surname': form.data['surname'],
        'email': form.data['email'],
    }

    utils.run_custom_query(
        """DELETE FROM CLIENT_PHONES WHERE CLIENT_ID = {}""".format(client_id),
        fetch=False)
    utils.update('clients', {'id': client_id}, client_data)
    for phone in form.data['phones']:
        if phone['phone']:
            utils.insert('client_phones', {
                'client_id': client_id,
                'phone': phone['phone']
            })
    if form.data['billing_address']:
        billing = utils.select('client_addresses', {
            'client_id': client_id,
            'type': 'billing'
        })
        data = form.data['billing_address']
        utils.update('addresses', {
            'id': billing[0].id,
        }, {
            'country': data['country'],
            'city': data['city'],
            'street': data['street']
        })
    if form.data['delivery_address']:
        delivery = utils.select('client_addresses', {
            'client_id': client_id,
            'type': 'delivery'
        })
        data = form.data['delivery_address']
        utils.update('addresses', {
            'id': delivery[0].id,
        }, {
            'country': data['country'],
            'city': data['city'],
            'street': data['street']
        })
Exemple #15
0
def update_status(status_id, data):
    utils.update('order_statuses', {'id': status_id}, data)
Exemple #16
0
def update_status(status_id, data):
    utils.update("order_statuses", {"id": status_id}, data)