Пример #1
0
def add_product():
    if current_user.permission != 'seller':
        abort(403)
    form = ProductForm()
    if form.validate_on_submit():
        if not set(form.image_source.data.filename.lower()) <=\
               set('abcdefghijklmnopqrstuvwxyz0123456789!\'#$'
                   '%&\'()*+,-./:;<=>?@[\]^_`{|}~'):
            return render_template('product.html',
                                   form=form,
                                   message='Недопустимое название файла')
        session = db_session.create_session()
        product = Product(user_id=current_user.id,
                          title=form.title.data,
                          short_about=form.short_about.data,
                          about=form.about.data,
                          price=form.price.data,
                          purchased_content=form.purchased_content.data,
                          is_published=form.is_published.data)
        if form.image_source.data.filename:
            product.image_source = images.save(form.image_source.data)
        for category_name in form.categories.data.lower().split(' '):
            if category_name not in map(lambda x: x.name,
                                        session.query(Category).all()):
                category = Category(name=category_name)
                session.add(category)
                session.commit()
            product.categories.append(
                session.query(Category).filter(
                    Category.name == category_name).first())
        session.add(product)
        session.commit()
        return redirect('/')
    return render_template('product.html', form=form)
Пример #2
0
def add_product():
    form = AddProductForm()
    if form.validate_on_submit():

        if form.image.data:
            product_img_path = save_image_and_get_path(request)
        else:
            product_img_path = None

        db_sess = db_session.create_session()
        product = Product(
            user_id=current_user.id,
            cost=form.cost.data,
            title=form.title.data,
            content=form.content.data,
            created_date=datetime.datetime.now(),
            path_to_img=product_img_path,
            contact_number=form.contact_number.data,
            is_showing_by_user=form.is_showing_by_user.data,
            is_showing_by_admin=form.is_showing_by_admin.data,
        )
        product.reinitialized_indexes()
        db_sess.add(product)
        db_sess.commit()
        return redirect('/')
    return render_template('add_product.html',
                           title='Добавление объявления',
                           form=form)
Пример #3
0
def add_product():
    form = ProductsAddForm()
    if form.validate_on_submit():
        db_sess = db_session.create_session()
        product = Product()
        product.product = form.product.data
        product.price = form.price.data
        current_user.products.append(product)
        db_sess.merge(current_user)
        db_sess.commit()
        return redirect('/index')
    return render_template('add_product.html',
                           title='Добавление товара',
                           form=form)
Пример #4
0
def add_product():
    form = ProductForm()
    session = db_session.create_session()
    if form.validate_on_submit():
        # noinspection PyArgumentList
        product = Product(title=form.title.data,
                          description=form.title.description,
                          price=form.price.data)
        for category_title in form.categories.data.split(', '):
            category = session.query(Category).filter(
                Category.title == category_title).first()
            if category:
                product.categories.append(category)
            else:
                # noinspection PyArgumentList
                category = Category(title=category_title)
                session.add(category)
                product.categories.append(category)
        session.add(product)
        session.commit()
        return redirect('/')
    if flask_login.current_user.is_seller:
        return render_template('form.html',
                               title='Add Job',
                               form=form,
                               current_user=flask_login.current_user)
    return redirect('/')
Пример #5
0
def update_product(name: str, newName: str, newPrice: float, newQuantity: int):
    product = Product.objects(name=name).first()
    product.name = newName
    product.price = newPrice
    product.quantity = newQuantity

    product.save()
Пример #6
0
def get_product_by_price_range(priceLowest: float,
                               priceHighest: float) -> List[Product]:
    query = Product.objects() \
        .filter(price__gte=priceLowest) \
        .filter(price__lte=priceHighest)
    products = query.order_by('price')

    return list(products)
Пример #7
0
 def post(self):
     args = parser.parse_args()
     session = db_session.create_session()
     product = Product(title=args['title'],
                       content=args['content'],
                       count=args['count'],
                       image=args['image'])
     session.add(product)
     session.commit()
     return jsonify({'success': 'OK'})
Пример #8
0
def add_products():
    db_sess = db_session.create_session()
    product = Product(name='Jeans',
                      price=3000,
                      path_photo='products/jeans.jpg')
    db_sess.add(product)
    product = Product(name='shirt',
                      price=1500,
                      path_photo='products/shirt.jpg')
    db_sess.add(product)
    product = Product(name='skirt',
                      price=2000,
                      path_photo='products/skirt.jpg')
    db_sess.add(product)
    product = Product(name='shoes',
                      price=4000,
                      path_photo='products/shoes.jpg')
    db_sess.add(product)
    db_sess.commit()
Пример #9
0
 def post(self):
     args = parser.parse_args()
     session = db_session.create_session()
     product = Product(name=args['name'],
                       description=args['description'],
                       price=args['price'],
                       picture_url=args['picture'])
     session.add(product)
     session.commit()
     return jsonify({'success': 'OK'})
Пример #10
0
def add_product(name: str, price: float, quantity: int) -> Product:
    product = Product()
    product.name = name
    product.price = price
    product.quantity = quantity

    product.save()

    return product
Пример #11
0
def add_product():
    if request.method == "POST":
        db_sess = db_session.create_session()
        req = request.form
        name = req.get("name")
        image = req.get("image")
        price = req.get("price")
        description = req.get("description")
        if name and price and image:
            if price.isdigit():
                product = Product()
                product.name = name
                product.image = image
                product.price = price
                product.description = description
                db_sess.add(product)
                db_sess.commit()
                db_sess.close()
                return redirect('/admin')
            else:
                return render_template("admin_create_product.html",
                                       wrong_data=True)
        else:
            return render_template("admin_create_product.html",
                                   empty_form=True)
    return render_template("admin_create_product.html")
Пример #12
0
def add_product():
    db_sess = db_session.create_session()
    product_data = json.loads(request.data)['content']
    product = Product(
        title=product_data['title'],
        price=product_data['price'],
        count=product_data['count'],
        image=
        "['https://sun9-57.userapi.com/impf/c626118/v626118034/745ca/LEGJY4cuLG0.jpg?size=640x640&quality=96&sign=8da868aa7dcb22613d43c3157da4be6f&type=album', 'https://sun9-57.userapi.com/impf/c626118/v626118034/745ca/LEGJY4cuLG0.jpg?size=640x640&quality=96&sign=8da868aa7dcb22613d43c3157da4be6f&type=album']"
    )
    db_sess.add(product)
    db_sess.commit()
    return {'200': 'Accept'}
Пример #13
0
def add_product():
    form = ProductForm()
    db_sess = db_session.create_session()
    categories = db_sess.query(Category)
    category_flag = 'None'
    if form.validate_on_submit():
        product = Product(title=form.title.data,
                          description=form.description.data,
                          producer=form.producer.data,
                          price=float(form.price.data),
                          count=int(form.count.data),
                          advantage=form.advantage.data)
        if form.picture.data:
            f = form.picture.data
            parent_dir = path.dirname(path.abspath(__file__))
            basename = parent_dir + '\\static\\pictures\\pic'
            suffix = datetime.now().strftime("%y%m%d_%H%M%S")
            filename = "_".join([basename, suffix, '.png'])
            g = open(filename, 'wb')
            g.write(f.getbuffer())
            g.close()
            product.picture = '/static/pictures/pic_' + suffix + '_.png'

        cat = db_sess.query(Category).filter(
            Category.title == form.category.data).first()
        if not cat:
            cat = db_sess.query(Category).filter(
                Category.id == form.category.data).first()
        product.category = cat.id

        db_sess.add(product)
        db_sess.commit()
        return redirect('/')
    return render_template('product.html',
                           title='Добавление товара',
                           form=form,
                           categories=categories,
                           category=category_flag)
def create():
    if current_user.is_admin:
        form = ProductForm()
        if form.validate_on_submit():
            product = Product()
            product.name = form.name.data
            product.description = form.description.data
            product.price_cents = int(form.price.data * 100)
            product.picture_url = form.picture_url.data
            db_sess = db_session.create_session()
            db_sess.add(product)
            db_sess.commit()
            return redirect(url_for('.details', product_id=product.id))
        return render_template('products/new.html', form=form)
    return redirect('/')
Пример #15
0
def create_products():
    if not flask.request.json:
        return flask.jsonify({'error': 'Empty request'})
    elif not all(key in flask.request.json for key in
                 ['name', 'seller', 'price', 'address']):
        return flask.jsonify({'error': 'Bad request'})
    session = db_session.create_session()
    prod = Product()
    prod.name = flask.request.json['name']
    prod.seller = flask.request.json['seller']
    prod.price = flask.request.json['price']
    prod.address = flask.request.json['address']
    session.add(prod)
    session.commit()
    return flask.jsonify({'success': 'OK'})
Пример #16
0
def change_product(product_id):
    if request.method == "POST":
        db_sess = db_session.create_session()
        req = request.form
        name = req.get("name")
        image = req.get("image")
        price = req.get("price")
        description = req.get("description")
        if name and image and price:
            if price.isdigit():
                product = Product()
                product.name = name
                product.image = image
                product.price = price
                product.description = description
                db_sess.query(Product).filter(Product.id == product_id).update(
                    {
                        Product.name: product.name,
                        Product.image: product.image,
                        Product.price: product.price,
                        Product.description: description
                    })
                db_sess.commit()
                db_sess.close()
                return redirect("/admin")
            else:
                return render_template("admin_change_product.html",
                                       wrong_data=True)
        else:
            return render_template("admin_change_product.html",
                                   empty_form=True)
    db_sess = db_session.create_session()
    product = db_sess.query(Product).filter(Product.id == product_id).first()
    return render_template("admin_change_product.html",
                           product_id=product_id,
                           name=product.name,
                           image=product.image,
                           price=product.price,
                           description=product.description)
Пример #17
0
def get_product(name: str) -> Product:
    product = Product.objects(name=name).first()
    return product
Пример #18
0
                         passport='8017',
                         address='Pushkina dom kalatuchkina')
cook.set_password('121321')
global_session.add(cook)
global_session.add(worker_data)
global_session.commit()

order = Order(
    id=0,
    client_id=0,
    address_data="no",
)

product = Product(id=0,
                  back_name='aaa',
                  front_name='Aaa',
                  description='sadsaas',
                  ingredients='1, 2, 3',
                  cost=100)
global_session.add(order)
global_session.add(product)
global_session.commit()
position = Position(order=order,
                    product=product,
                    count=2,
                    extra_wishes='asd',
                    point_cost=product.cost * 2)
global_session.add(position)
global_session.commit()
print(order.positions)
print(product in order)
print(order.status)
Пример #19
0
def remove_product(name: str):
    product = Product.objects(name=name).first()
    product.delete()
Пример #20
0
def adminka():
    global inform, TOKEN_ADMINKI
    categorid = pass_catal()[0]
    list_product = pass_catal()[1]
    id_treners = pass_treners()[0]
    message = None
    message_2 = None
    message_4 = None
    message_3 = None
    message_dop = None
    message_del = None
    message_prod = None
    message_prodel = None
    message_cate = None
    message_delcate = None
    redcate_form = RedcateForm()
    delcate_form = DelcateForm()
    delprod_form = DelprodForm()
    redprod_form = RedprodForm()
    form = InfoForm()
    form_product = ProductForm()
    form_trainer = TrainerForm()
    form_categories = CategoriesForm()
    redtren_form = RedtrenForm()
    deltren_form = DeltrenForm()
    if form.validate_on_submit():
        try:
            inform.name = form.name.data
            inform.start_text = form.start_text.data
            inform.telefon = form.telefon.data
            inform.admin = form.admin.data
            inform.derektor = form.admin.data
            session.commit()
        except Exception as er:
            abort(404, message=f"Product {er} not found")
    if form_product.validate_on_submit():
        try:
            if session.query(Product).filter(
                    Product.name == form_product.nameprod.data).first():
                message_2 = f'такой Product уже есть'
            else:
                product = Product(name=form_product.nameprod.data,
                                  coin=form_product.coin.data,
                                  count=form_product.count.data,
                                  info=form_product.info.data)
                session.add(product)
                session.commit()
        except Exception as ex:
            abort(404, message=f"Product {ex} not found")

    if form_trainer.validate_on_submit():
        try:
            if session.query(Trainer).filter(
                    Trainer.email == form_trainer.email.data).first():
                message_3 = f'такой email уже есть'
            else:
                trainer = Trainer(surname=form_trainer.surname.data,
                                  name=form_trainer.nametren.data,
                                  age=form_trainer.age.data,
                                  email=form_trainer.email.data,
                                  telefon=form_trainer.telefon.data)
                session.add(trainer)
                session.commit()
        except Exception as ex:
            abort(404, message=f"Product {ex} not found")
    if form_categories.validate_on_submit():
        try:
            for prod in form_categories.products.data.split(', '):
                try:
                    int(prod)
                except Exception as er:
                    abort(404, message=f'error prod_list')
            if session.query(Categories).filter(
                    Categories.name == form_categories.namecat.data).first():
                message_4 = f'такая Categories уже есть'
            else:
                categories = Categories(name=form_categories.namecat.data,
                                        products=form_categories.products.data)
                session.add(categories)
                session.commit()
        except Exception as ex:
            abort(404, message=f"categories {ex} not found")
    if redtren_form.validate_on_submit():
        try:
            trainers = session.query(Trainer).get(int(redtren_form.id.data))
            if not trainers:
                message_dop = f'Такого id нет'
            elif session.query(Trainer).filter(Trainer.email == redtren_form.emai.data).first() \
                    and trainers.email != redtren_form.emai.data:
                message_dop = f'такой email уже есть'
            else:
                trainers.surname = redtren_form.surnam.data
                trainers.name = redtren_form.nam.data
                trainers.age = redtren_form.ag.data
                trainers.telefon = redtren_form.telefo.data
                trainers.email = redtren_form.emai.data
                session.commit()
        except Exception as ex:
            abort(404, message=f"error {ex} redtren")
    if deltren_form.validate_on_submit():
        trainersdel = session.query(Trainer).get(
            int(deltren_form.id_trendelet.data))
        if not trainersdel:
            message_del = f'Такого id нет'
        else:
            session.delete(trainersdel)
            session.commit()
    if redprod_form.validate_on_submit():
        try:
            prodct = session.query(Product).get(int(redprod_form.idd.data))
            if not prodct:
                message_prod = f'Такого id нет'
            else:
                if session.query(Product).filter(Product.name == redprod_form.namep.data).first() and \
                        prodct.name != redprod_form.namep.data:
                    message_prod = f'Такой Product уже есть'
                else:
                    prodct.name = redprod_form.namep.data
                    prodct.info = redprod_form.infoo.data
                    prodct.count = redprod_form.counts.data
                    prodct.coin = redprod_form.coins.data
                    session.commit()
        except Exception as ex:
            abort(404, message=f'error {ex} prodel')
    if delprod_form.validate_on_submit():
        try:
            prodd = session.query(Product).get(int(delprod_form.idt.data))
            if not prodd:
                message_prodel = f'Такого id нет'
            else:
                session.delete(prodd)
                session.commit()
        except Exception as ex:
            abort(404, message=f'error {ex} prodel')
    if redcate_form.validate_on_submit():
        try:
            cate = session.query(Categories).get(int(redcate_form.idcate.data))
            if not cate:
                message_cate = f'Такого id нет'
            else:
                if session.query(Categories).filter(Categories.name == redcate_form.namecate.data).first() and \
                        cate.name != redcate_form.namecate.data:
                    message_cate = f'Такая категория уже есть'
                else:
                    cate.name = redcate_form.namecate.data
                    cate.products = redcate_form.productcate.data
                    session.commit()
        except Exception as ex:
            abort(404, message=f'error {ex} prodel')
    if delcate_form.validate_on_submit():
        try:
            dcate = session.query(Categories).get(
                int(delcate_form.iddelcate.data))
            if not dcate:
                message_delcate = f'Такого id нет'
            else:
                session.delete(dcate)
                session.commit()
        except Exception as ex:
            abort(404, message=f'error {ex} prodel')
    return render_template('adminka.html',
                           title='adminka',
                           form=form,
                           form_product=form_product,
                           message=message,
                           message_2=message_2,
                           message_3=message_3,
                           message_4=message_4,
                           form_trainer=form_trainer,
                           form_categories=form_categories,
                           inform=inform,
                           categorid=categorid,
                           list_product=list_product,
                           message_dop=message_dop,
                           redtren_form=redtren_form,
                           message_del=message_del,
                           deltren_form=deltren_form,
                           delprod_form=delprod_form,
                           redprod_form=redprod_form,
                           message_prod=message_prod,
                           message_prodel=message_prodel,
                           message_cate=message_cate,
                           message_delcate=message_delcate,
                           redcate_form=redcate_form,
                           delcate_form=delcate_form,
                           id_treners=id_treners)