Beispiel #1
0
 def test_func_get_name(self):
     BC = BusinessCard(name='name',
                       description='description',
                       contact_information='contact_information',
                       business_id=1)
     db.session.add(BC)
     db.session.commit()
     self.assertEqual(BC.name, BusinessCard.get_name(BC.business_id))
Beispiel #2
0
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)