def test_func_get_name(self): business = Business(name='name', password='******', email='email', confirmed=True) db.session.add(business) db.session.commit() self.assertEqual(business.name, Business.get_name(business.id))
def created_process(process_id): if session.get('id', '') == '': return redirect('/business/') elif not Process.is_real(process_id): return redirect('/business/created_process_list') elif Process.get_business(process_id) != session.get('id', ''): return redirect('/business/created_process_list') elif not Business.check_confirmed(session.get('id', '')): return redirect('/business/unconfirmed') form = ChangeForm() s_form = SelectFieldStageForm() d_form = DateForm() if form.validate_on_submit() and d_form.validate_on_submit(): if int(Process.get_stages(process_id)) != int(s_form.select_stage.data): Business.send_stages(Client.get_email(Process.get_client_id(process_id)), s_form.select_stage.data, Business.get_name(session.get('id', '')), Process.get_number(process_id), PossibleProcess.get_type(Process.get_type_id(process_id))) rows = Process.query.filter_by(id=process_id).update({'desc': form.desc.data}) rows = Process.query.filter_by(id=process_id).update({'current_stage': s_form.select_stage.data}) rows = Process.query.filter_by(id=process_id).update({'data': d_form.dt.data}) rows = Process.query.filter_by(id=process_id).update({'percent': round(form.percent.data)}) rows = Process.query.filter_by(id=process_id).update({'price': form.price.data}) db.session.commit() return redirect('/business/created_process_list') number = Process.get_number(process_id) client = Client.get_email(Process.get_client_id(process_id)) type = PossibleProcess.get_type(Process.get_type_id(process_id)) form.desc.data = Process.get_desc(process_id) percent = Process.get_percent(process_id) form.percent.data = percent form.price.data = Process.get_price(process_id) s_form.select_stage.choices = [(s.id, s.type) for s in Stage.sort_by_id_for_business(Process.get_type_id(process_id))] s_form.select_stage.default = Process.get_stages(process_id) s_form.process() d_form.dt.data = Process.get_data(process_id) desc_type = PossibleProcess.get_desc(Process.get_type_id(process_id)) star = Process.get_star(process_id) chat = Chat.get_by_proc(process_id).id picture = PossibleProcess.get_picture(Process.get_type_id(process_id)) is_picture = (PossibleProcess.get_picture(Process.get_type_id(process_id)) != "-1") return render_template('created_process.html', title='Созданная услуга', desc_type=desc_type, percent=percent, d_form=d_form, id=process_id, form=form, s_form=s_form, number=number, type=type, client=client, Process=Process, chat=chat, rating=star, picture=picture, is_picture=is_picture)
def change_business(): if session.get('id', '') == '': return redirect('/business') if not Business.check_confirmed(session.get('id', '')): return redirect('/business/unconfirmed') changename = "" changepassword = "" form_name = ChangeBusinessNameForm() form_password = ChangeBusinessPasswordForm() id = session.get('id', '') if form_name.submit1.data and form_name.validate_on_submit(): free_name = Business.name_is_free(form_name.new_name.data) b_password = Business.query.filter_by(id=id).first().password b_name = Business.get_name(id) if free_name or b_name == form_name.new_name.data \ and check_password_hash(b_password, form_name.password.data): rows = Business.query.filter_by(id=id).update({'name': form_name.new_name.data}) db.session.commit() if BusinessCard.is_real(session.get('id', '')): rows = BusinessCard.query.filter_by(business_id=session.get('id', '')).update( {'name': form_name.new_name.data}) db.session.commit() changename = "Название было изменено" # return redirect('/change_business') elif not free_name and form_name.new_name.data != b_name: form_name.new_name.errors = ('Название занято', '') elif not check_password_hash(b_password, form_name.password.data): form_name.password.errors = ('Неправильный пароль', '') if form_password.submit2.data and form_password.validate_on_submit(): b_password = Business.query.filter_by(id=id).first().password check_new = form_password.new_password.data == form_password.check_new_password.data check_old = check_password_hash(b_password, form_password.old_password.data) password_is_valid = Business.password_is_valid(form_password.new_password.data) if check_old and check_new and password_is_valid: new_password = generate_password_hash(form_password.new_password.data) rows = Business.query.filter_by(id=id).update({'password': new_password}) db.session.commit() changepassword = "******" # return redirect('/change_business') elif not password_is_valid: form_password.new_password.errors = ('Пароль не может содержать пробелы', '') elif not check_new: form_password.check_new_password.errors = ('Пароли не совпадают', '') elif not check_old: form_password.old_password.errors = ('Неправильный пароль', '') form_name.new_name.data = Business.query.filter_by(id=id).first().name return render_template('change_business.html', title='Изменить настройки бизнеса', form=form_name, p_form=form_password, changename=changename, changepassword=changepassword)
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 creation_card(): if session.get('id', '') == '': return redirect('/business/') elif not Business.check_confirmed(session.get('id', '')): return redirect('/business/unconfirmed') form = CreationCardForm() business_id = session.get('id', '') name = Business.get_name(business_id) if form.validate_on_submit(): if not BusinessCard.is_real(business_id): card = BusinessCard("", "", "", "", business_id) BusinessCard.save(card) rows = BusinessCard.query.filter_by(business_id=business_id).update({'name': name}) rows = BusinessCard.query.filter_by(business_id=business_id).update({'description': form.description.data}) rows = BusinessCard.query.filter_by(business_id=business_id).update( {'contact_information': form.contact_information.data}) rows = BusinessCard.query.filter_by(business_id=business_id).update({'address': form.address.data}) db.session.commit() if 'file' in request.files: file = request.files['file'] if file.filename != '': if file and allowed_file(file.filename): pic = Pictures(business_id) id_picture = Pictures.save(pic) picture = str(id_picture) filename = secure_filename(file.filename) picture += "." + filename.rsplit('.', 1)[1].lower() rows = Pictures.query.filter_by(id=id_picture).update({'picture': picture}) rows = BusinessCard.query.filter_by(business_id=business_id).update({'picture': picture}) db.session.commit() file.save(os.path.join(UPLOAD_FOLDER, str(picture))) return redirect(url_for('business.business_card', business_id=session.get('id', ''))) if BusinessCard.is_real(business_id): form.description.data = BusinessCard.get_description(business_id) form.contact_information.data = BusinessCard.get_contact_information(business_id) form.address.data = BusinessCard.get_address(business_id) else: form.description.data = "" form.contact_information.data = "" form.address.data = "" return render_template('create_business_card.html', title='Изменить страничку бизнеса', form=form, name=name)
def status(process_id): if session.get('id', '') != '': return redirect(url_for('business.business_card', business_id=session.get('id', ''))) elif session.get('id_client', '') == '': return redirect('/business_client/login') elif Process.get_client_id(process_id) != session.get('id_client', ''): return redirect('/business_client/login') form_stage = StatusEmailForm() form_check = CheckBoxForm() form_star = RatingForm() starsave = "" stagesave = "" if form_stage.submit1.data: if Process.get_send(process_id): rows = Process.query.filter_by(id=process_id).update({'send_all_stages': 0}) db.session.commit() else: rows = Process.query.filter_by(id=process_id).update({'send_all_stages': 1}) db.session.commit() stagesave = "Изменения были сохранены" if form_star.submit2.data: rows = Process.query.filter_by(id=process_id).update({"star": form_star.star.data}) db.session.commit() starsave = "Спасибо за оценку" rating = Process.get_star(process_id) form_check.checkbox.data = False send_stages = Process.get_send(process_id) number = Process.get_number(process_id) client_email = Client.get_email(Process.get_client_id(process_id)) business_name = Business.get_name(Process.get_business(process_id)) data = Process.get_data(process_id).strftime("%B %d, %Y") type = PossibleProcess.get_type(Process.get_type_id(process_id)) desc_type = PossibleProcess.get_desc(Process.get_type_id(process_id)) desc = Process.get_desc(process_id) percent = Process.get_percent(process_id) current_stage = Process.get_stages(process_id) current_stage_name = Process.get_stage_name(current_stage) client_id = Process.get_client_id(process_id) price = Process.get_price(process_id) business_id = Process.get_business(process_id) business_card_exists = BusinessCard.is_real(Process.get_business(process_id)) # получение всех стадий процесса stages = Stage.sort_by_id_for_business(Process.get_type_id(process_id)) chat = Chat.get_by_proc(process_id).id is_picture = (PossibleProcess.get_picture(Process.get_type_id(process_id)) != "-1") picture = PossibleProcess.get_picture(Process.get_type_id(process_id)) return render_template('Status.html', title='Статус заказа', number=number, client_email=client_email, business_name=business_name, type=type, desc=desc, desc_type=desc_type, percent=percent, data=data, current_stage=current_stage, current_stage_name=current_stage_name, stages=stages, price=price, business_id=business_id, form_stage=form_stage, form_check=form_check, send_stages=send_stages, form_star=form_star, rating=rating, starsave=starsave, stagesave=stagesave, business_card_exists=business_card_exists, client_id=client_id, chat=chat, is_picture=is_picture, picture=picture, Widget=Widget)