def business_card(business_id): if int(business_id) == session.get('id', '') and (not BusinessCard.is_real(business_id)): not_created = True return render_template('business_card.html', title='Страница бизнеса', name="", description="", contact_information="", not_created=not_created, Widget=Widget, bid=business_id) elif session.get('id', '') == '' and not BusinessCard.is_real(business_id): return redirect('/business/business_card_list') elif not BusinessCard.is_real(business_id): return redirect('/business/business_card_list') session['id_client'] = '' not_created = False name = BusinessCard.get_name(business_id) description = BusinessCard.get_description(business_id) contact_information = BusinessCard.get_contact_information(business_id) address = BusinessCard.get_address(business_id) form = CommentsForm() if form.validate_on_submit(): if not Client.is_real(form.email.data, business_id): form.email.errors = ( "Вы не можете отправлять комментарии, потому что вы не являетесь клиентом этого бизнеса", "") else: comments = Comments(form.text.data, Client.get_id(form.email.data), business_id, form.name.data, form.star.data) Comments.save(comments) rating = BusinessCard.get_new_rating(business_id) rows = BusinessCard.query.filter_by(business_id=business_id).update( {'rating': rating}) db.session.commit() return redirect(url_for('business.business_card', business_id=business_id)) comment_list = Comments.query.filter_by(business_id=business_id).all() if session.get('id', '') == int(business_id): business_account = True else: business_account = False form.star.data = 1 howmuchcomments = BusinessCard.how_much_comments(business_id) rating = BusinessCard.get_new_rating(business_id) return render_template('business_card.html', title='Страничка бизнеса', name=name, description=description, contact_information=contact_information, rating=rating, howmuchcomments=howmuchcomments, business_account=business_account, business_id=business_id, not_created=not_created, form=form, comment_list=comment_list[::-1], address=address, Comments=Comments, BusinessCard=BusinessCard, Widget=Widget, bid=business_id)
def create_process(): if session.get('id', '') == '': return redirect('/business/') elif not Business.check_confirmed(session.get('id', '')): return redirect('/business/unconfirmed') b_id = session['id'] form = CreateProcessForm() s_form = SelectFieldTypeForm() h = HelpForm() s_form.select_type.choices = [(p.id, p.type) for p in PossibleProcess.query.filter_by(business_id=b_id).all()] d_form = DateForm() if form.validate_on_submit() and d_form.validate_on_submit(): if Client.email_is_free(form.client_email.data): client = Client(form.client_email.data) cl_id = client.save() else: cl_id = Client.get_id(form.client_email.data) client_password = Client.random_password(10) number = Process.random_number() process = Process(s_form.select_type.data, form.description.data, b_id, cl_id, number, form.price.data, client_password, d_form.dt.data, 0) pr_id = process.save() id_stage = Stage.get_not_started(s_form.select_type.data) process = Process.query.filter_by(id=pr_id).first() process.current_stage = id_stage chat = Chat(pr_id, b_id) chat.save() process.save() Process.send_number(form.client_email.data, Business.get_name(b_id), number, client_password) # string = "Услуга была создана под номером: " + number return redirect(url_for('business.created_process', process_id=pr_id)) elif form.validate_on_submit() and not d_form.validate_on_submit(): d_form.dt.errors = ("Выберите дату", "") h.desc.choices = [(p.desc, p.desc) for p in PossibleProcess.query.filter_by(business_id=b_id).all()] h.price.choices = [(p.price, p.price) for p in PossibleProcess.query.filter_by(business_id=b_id).all()] h.pic.choices = [(p.picture, p.picture) for p in PossibleProcess.query.filter_by(business_id=b_id).all()] return render_template('create_process.html', form=form, h=h, s_form=s_form, d_form=d_form, title='Создание заказа')
def test_func_get_id(self): client = Client(email='email') db.session.add(client) db.session.commit() self.assertEqual(client.id, Client.get_id(client.email))