Beispiel #1
0
def count_orders(user=None):
    if user is not None:
        user = User.get_by_username(user)
        res = Order.objects(user=user)
    else:
        res = Order.objects
    return res.count()
Beispiel #2
0
def get_orders(user=None, limit=None, offset=None, sorting='-number'):
    if user is not None:
        user = User.get_by_username(user)
        res = Order.objects(user=user)
    else:
        res = Order.objects
    if offset:
        res = res.skip(offset)
    if limit:
        res = res.limit(limit)
    return res.order_by(sorting)
Beispiel #3
0
def create_order(sid: str) -> Order:
    session = session_utility.get_session(sid)
    order = Order()
    if session.cart is None:
        raise ValueError('В корзине нет товаров')
    order.cart = session.cart
    order.user = User.get_by_username(session.user)
    order.contragent = session.contragent
    order.comment = session.comment
    order._price = session.cart.subtotal
    order.sale = session.sale
    order.time_created = datetime.datetime.now(
        tz=pytz.timezone('Europe/Moscow'))
    num = utility.find_last_order_num()
    order.order_num = 'РВ-' + str(num + 1)
    order._number = num + 1
    order.save()
    return order
Beispiel #4
0
    def dispatch_request(self):
        context = {'commit_hash': commit_hash}

        if request.method == 'POST':
            if current_user.is_authenticated:
                return redirect(url_for('frontend.create_order.create_order'))
            username = request.form.get('username')
            password = request.form.get('password')
            user = User.get_by_username(username)
            user: User
            if user is not None and user.check_password(password):
                login_user(user, remember=True)
                next_page = request.args.get('next')
                if not next_page or url_parse(next_page).netloc != '':
                    next_page = url_for('frontend.create_order.create_order')
                return redirect(next_page)
        elif current_user.is_authenticated:
            return redirect(url_for('frontend.create_order.create_order'))
        return self.render_template(context)