Exemplo n.º 1
0
 def test_get_rating(self):
     db.session.add(models.Levels(difficulty=self.DIFFICULTY))
     db.session.add(models.Users(**self.TEST_ADD_USER))
     db.session.add(models.Users(**self.TEST_ADD_USER_2))
     db.session.add(models.Recipe(**self.TEST_ADD_RECIPE))
     db.session.add(models.Rating(**self.RATING_1))
     db.session.add(models.Rating(**self.RATING_2))
     recipe = db.session.query(models.Recipe).get(self.TEST_RECIPE_ID)
     recipe_rating = db_queries.get_rating(recipe.id)
     self.assertEqual(recipe_rating, 2.0)
Exemplo n.º 2
0
async def update_order_rating(
    order_id: int,
    rating_in_db: schemas.RatingInDB,
    current_account: schemas.Account = Depends(get_current_account),
    db: Session = Depends(get_db)):
    if current_account.role_id != 0:
        raise HTTPException(status_code=403)

    db_order = db.query(
        models.Order).filter(models.Order.order_id == order_id).first()
    db_rating = db.query(
        models.Rating).filter(models.Rating.order_id == order_id).first()

    if db_order.status_id != 3:
        raise HTTPException(status_code=409, detail="Order not done yet!")
    else:
        if not db_rating:
            db_rating = models.Rating(order_id=order_id,
                                      stars=rating_in_db.stars,
                                      comment=rating_in_db.comment)
            db.add(db_rating)
            db.commit()
            db.refresh(db_rating)

        db_rating.stars = rating_in_db.stars
        db_rating.comment = rating_in_db.comment
        db.commit()
        db.refresh(db_rating)

    return schemas.Rating(rating_id=db_rating.rating_id,
                          student_id=db_order.student_id,
                          teacher_id=db_order.teacher_id,
                          order_id=db_rating.order_id,
                          stars=db_rating.stars,
                          comment=db_rating.comment)
Exemplo n.º 3
0
def subsec(news):
    news = db.session.query(models.Contents).filter_by(Title=news).first()
    rating = db.session.query(models.Rating).filter_by(contents_id=news.id)
    temp = 0.0
    count = 0.0
    for r in rating:
        count += 1
        temp = r.rating + temp
        db.session.delete(r)
    if (count != 0):
        temp = temp / count
        query = models.Rating(temp, news.id)
        db.session.add(query)
        db.session.commit()

    imagac = news.images.split(";")
    print(imagac)
    imagac = imagac[:-1]
    for im in imagac:
        print(im)

    Subsections = db.session.query(models.Contents.subsection).distinct()
    comments = db.session.query(models.Comment).filter_by(contents_id=news.id)
    return render_template('subsec.html',
                           rating=temp,
                           comments=comments,
                           news=news,
                           imagac=imagac,
                           subsection=Subsections)
Exemplo n.º 4
0
    def post(self, request, project_id):
        session_key = request.session.session_key

        if request.POST.get("passed"): # Save a mostly empty db entry with
            # passed set to True
            rating_model = models.Rating()
            rating_model.passed = True
        else:
            rating_form = forms.RatingForm(request.POST)
            if rating_form.is_valid():
                rating_model = rating_form.save(commit=False)
            else:  # this should never happen bc javascript validation
                return self.get(request, project_id)

        try:
            models.Rating.objects.get(project_id=project_id,
                                      judge_id=session_key).delete()
            # if there's an existing record, kill it.
        except models.Rating.DoesNotExist:
            pass

        rating_model.project_id = project_id
        rating_model.judge_id = session_key
        rating_model.save()
        return self.get(request, project_id)
Exemplo n.º 5
0
def add_rating(movie_id, rating, current_user: schemas.User):
    with session_scope() as s:
        user = s.query(
            models.User).filter_by(username=current_user.username).first()
        rating = models.Rating(user_id=user.id,
                               movie_id=movie_id,
                               rating=rating,
                               timestamp=dt.date.today())
        s.add(rating)
        s.commit()
    return 201, {"status": "sukses"}
Exemplo n.º 6
0
def add_rating(user_id, recipe_id, rating):
    existing_rating = models.Rating.query.filter_by(
        user_id=user_id, recipe_id=recipe_id).first()
    if existing_rating:
        existing_rating.rate = rating
        db.session.commit()
    else:
        new_rating = models.Rating(user_id=user_id,
                                   recipe_id=recipe_id,
                                   rate=rating)
        db.session.add(new_rating)
        db.session.commit()
Exemplo n.º 7
0
def rating(news):
    global registered_user
    if registered_user is None:
        return redirect(url_for('signup'))

    query = db.session.query(models.Contents).filter_by(Title=news).first()
    if request.method == 'GET':
        return redirect(url_for('subsec', news=news))
    else:
        if str(query.id) not in registered_user.ratelist:
            registered_user.ratelist += str(query.id) + ";"
            rating = request.form['rating']
            ratings = models.Rating(rating, query.id)
            db.session.add(ratings)
            db.session.commit()
    return redirect(url_for('subsec', news=news))
Exemplo n.º 8
0
async def create_order_rating(
    order_id: int,
    rating_in_db: schemas.RatingInDB,
    current_account: schemas.Account = Depends(get_current_account),
    db: Session = Depends(get_db)):
    if current_account.role_id == 2:
        raise HTTPException(status_code=403)

    db_order = db.query(
        models.Order).filter(models.Order.order_id == order_id).first()

    if not db_order:
        raise HTTPException(status_code=404, detail="Order not found!")

    if db_order.status_id != 3:
        raise HTTPException(status_code=409, detail="Order not done yet!")

    db_rating = db.query(
        models.Rating).filter(models.Rating.order_id == order_id).first()

    if db_rating:
        raise HTTPException(status_code=409, detail="Rating already exists!")

    try:
        db_rating = models.Rating(order_id=order_id,
                                  stars=rating_in_db.stars,
                                  comment=rating_in_db.comment)
        db.add(db_rating)
        db.commit()
        db.refresh(db_rating)
    except RuntimeError:
        raise HTTPException(status_code=500)

    return schemas.Rating(rating_id=db_rating.rating_id,
                          student_id=db_order.student_id,
                          teacher_id=db_order.teacher_id,
                          order_id=db_rating.order_id,
                          stars=db_rating.stars,
                          comment=db_rating.comment)
def create_testdata():
    click.echo('Create test data.')

    member = models.Member()
    member.username = '******'
    member.password = views.membership.bcrypt.generate_password_hash('123123')
    member.realname = 'Liszt'
    member.email = '*****@*****.**'
    member.sex = 'male'
    member.phone = '0356225446'
    member.permission = 0x1
    models.db.session.add(member)

    goods_type = models.GoodsType()
    goods_type.size = 'L'
    goods_type.state = 'test'
    goods_type.price = 682
    models.db.session.add(goods_type)

    goods_type_m = models.GoodsType()
    goods_type_m.size = 'M'
    goods_type_m.state = 'test'
    goods_type_m.price = 881
    models.db.session.add(goods_type_m)

    for i in range(1,730):
        goods = models.Goods()
        goods_image1 = models.GoodsImages()
        goods_image1.goods = goods
        goods.state = 'To sell'
        if i % 2 == 0:
            goods_image2 = models.GoodsImages()
            goods_image2.goods = goods
            goods.name = 'KITTEN 曉貓'+ str(i)
            goods.type = goods_type
            goods_image1.image = '/static/images/cat4.jpg'
            models.db.session.add(goods_image1)
            goods_image2.image = '/static/images/cat2.jpg'
            models.db.session.add(goods_image2)
        else:
            goods.name = 'BIRD_AND_CAT 鳥&貓 '+ str(i)
            goods.type = goods_type_m
            goods_image1.image = '/static/images/cat3.jpg'
            models.db.session.add(goods_image1)
        goods.author = member
        goods.description = '''ka[dsg ks[dkfm[aosdkr]papsk f]pok kapflklkalks [pk[
            dgkds sd;lf';l d;s
            [ a[lsdf'
            sd; klsdk; lfkps;dlpfl, sp;l
            sdf ;lkl;sdk ;lksd;lkf[pqle[prk '''
        models.db.session.add(goods)

    order = models.Order()
    order.amount = 881
    order.purchaser = member
    models.db.session.add(order)

    order_item = models.OrderItem()
    order_item.quantity = 1
    order_item.goods = goods
    order_item.order = order
    models.db.session.add(order_item)

    comment1 = models.Comment()
    comment1.author = member
    comment1.goods = goods
    comment1.message = '?????????渣SA{DQ@ㄉ@``CSCf;ll;z;'
    models.db.session.add(comment1)

    comment2 = models.Comment()
    comment2.author = member
    comment2.goods = goods
    comment2.message = '爛!!!!!!!!!afgbbxvxv豬ad45675O--i092I0U302909JPJR3'
    models.db.session.add(comment2)

    comment3 = models.Comment()
    comment3.author = member
    comment3.goods = goods
    comment3.message = 'xafaxoooooofafos@肥豬鷹!XXXXXXXXXXXXXXXXXXXXX'
    models.db.session.add(comment3)

    rating2 = models.Rating()
    rating2.author = member
    rating2.for_order_item = order_item
    rating2.score = 1
    rating2.message = '爛!!!!!!!!!afasjfjKJEPKRJPO--i092I0U302909JPJR3'
    models.db.session.add(rating2)

    rating = models.Rating()
    rating.author = member
    rating.for_order_item = order_item
    rating.score = 3
    rating.message = 'sdogkpa!I@(_)_)UafF())I#){(RU)USJOJIJLKJlj ojroqi *&:((((('
    models.db.session.add(rating)

    rating2 = models.Rating()
    rating2.author = member
    rating2.for_order_item = order_item
    rating2.score = 1
    rating2.message = '爛!!!!!!!!!afasjfjKJEPKRJPO--i092I0U302909JPJR3'
    models.db.session.add(rating2)

    models.db.session.commit()