Esempio n. 1
0
def barbershop():
    user = session['user'] if 'user' in session else None
    if not user:
        return redirect(url_for('login'))
    else:
        try:
            barbershop_name = request.values['name']
            barbershop = models.BarberShopTable().get_barbershop(
                barbershop_name)
            reviews = models.ReviewTable().get_all_review()
            total = 0
            count = 0
            for review in reviews:
                if review['barbershop'] == barbershop_name:
                    total += int(review['rating'])
                    count += 1
            if count != 0:
                avg1 = round(total / count, 1)
                avg2 = total // count
            else:
                avg1 = 0
                avg2 = 0
            return render_template('barbershop.html',
                                   barbershop=barbershop,
                                   avg1=avg1,
                                   avg2=avg2)
        except Exception as e:
            print(e)
            traceback.print_tb(e.__traceback__)
            return render_template('error.html', msg='something goes wrong~')
Esempio n. 2
0
def get_review():
    user = session['user'] if 'user' in session else None
    if not user:
        return redirect(url_for('login'))
    else:
        try:
            barbershop_name = request.data.decode('utf-8')
            review_table = models.ReviewTable()
            reviews = review_table.get_all_review()

            res = []
            for review in reviews:
                if review['barbershop'] == barbershop_name:
                    res.append({
                        'Customer': review['customer'],
                        'Rating': review['rating'],
                        'Text': review['text'],
                    })
            print(res)
            return json.dumps({"data": res})

        except Exception as e:
            print(e)
            traceback.print_tb(e.__traceback__)
            return None
Esempio n. 3
0
def put_review():
    user = session['user'] if 'user' in session else None
    if not user:
        return redirect(url_for('login'))
    else:
        try:
            ret = json.loads(request.data.decode('utf-8'))
            print(ret)
            review_table = models.ReviewTable()
            review_table.put_review(user['name'], ret['barbershop'],
                                    ret['text'], ret['rating'])
            return "1"

        except Exception as e:
            print(e)
            traceback.print_tb(e.__traceback__)
            return "0"