コード例 #1
0
def add(tasting_id):
    form = ReviewForm(tasting_id=tasting_id)
    current_time = datetime.utcnow()
    if form.validate_on_submit():
        filename = secure_filename(form.image.data.filename)
        # set age to 0 if it has not been entered
        if form.age.data == "":
            age = 0
        else:
            age = int(form.age.data)
        if form.brand_id.data is '0':
            brand = Brand(name=form.brand_name.data)
            db.session.add(brand)
            db.session.flush()
            review = Review(order=form.order.data,
                            notes=form.notes.data,
                            tasting_note=form.tasting_note.data,
                            img_name=filename,
                            name=form.name.data,
                            age=age,
                            max_rating=form.max_rating.data,
                            avg_rating=form.avg_rating.data,
                            min_rating=form.min_rating.data,
                            author=current_user,
                            brand_id=brand.id,
                            tasting_id=form.tasting_id.data)
        else:
            review = Review(order=form.order.data,
                            notes=form.notes.data,
                            tasting_note=form.tasting_note.data,
                            img_name=filename,
                            name=form.name.data,
                            age=form.age.data,
                            max_rating=form.max_rating.data,
                            avg_rating=form.avg_rating.data,
                            min_rating=form.min_rating.data,
                            author=current_user,
                            brand_id=form.brand_id.data,
                            tasting_id=form.tasting_id.data)
        db.session.add(review)
        db.session.commit()

        pathlib.Path(current_app.config['UPLOAD_FOLDER'] + '/' +
                     str(review.id)).mkdir(parents=True, exist_ok=True)
        form.image.data.save(current_app.config['UPLOAD_FOLDER'] + '/' +
                             str(review.id) + '/' + filename)
        rotateImage(
            current_app.config['UPLOAD_FOLDER'] + '/' + str(review.id) + '/',
            filename)
        flash('Your review is now live!')
        return redirect(
            url_for('main.tasting', tasting_id=form.tasting_id.data))
    return render_template(
        'add_review.html',
        title='Add Review',
        form=form,
    )
コード例 #2
0
def rate(bookid):
    review_form = ReviewForm()
    property_owner_user_id = Book.query.filter_by(book_id=bookid).join(Post, Post.post_id == Book.post_id) \
        .with_entities(Post.user_id)
    user = User.query.get(current_user.get_id())
    book = Book.query.filter_by(book_id=bookid).first()
    if review_form.validate_on_submit():
        review = Review(content=review_form.content.data,
                        stars=review_form.number.data,
                        renter_user_id=user.user_id,
                        property_owner_user_id=property_owner_user_id)
        book.status = 'booking complete'
        db.session.add(review)
        db.session.commit()
        flash('you have successfully posted a review!', 'success')
        return redirect(url_for('main.home_page'))
    return render_template('rate.html', form=review_form)
コード例 #3
0
ファイル: views.py プロジェクト: ABERT-NOLA/Pitch--Detect
def new_review(id):
    form = ReviewForm()
    pitch = Pitch.query.get(id)
    if form.validate_on_submit():
        review = form.review.data

        # Updated review instance
        user_review = Review(
            pitch_id=pitch.id,
            pitch_review=review,
            user_id=current_user.id
        )

        # save review method
        user_review.save_review()
        return redirect(url_for('.single_pitch', id=pitch.id))

    title = f'{pitch.name} review'
    return render_template('pitch/new_review.html', title=title, review_form=form, pitch=pitch)
コード例 #4
0
def test_disableForm(app, dbSession):
    from app.main.forms import ReviewForm
    with app.app_context():
        form = ReviewForm()
        disableForm(form)
        checkValue = "disabled"
        for field in form:
            if field.type != "RadioField":
                assert checkValue in field.render_kw
            elif field.type == "RadioField":
                assert field.option_widget.__class__ == RadioInputDisabled
コード例 #5
0
def review():
    if request.method == 'GET':
        if len(request.args) != 0:
            form = ReviewForm(request.args)
        else:
            flash("Invalid request. Please search for provider first and then"
                  " add review.")
            return redirect(url_for('main.index'))
    elif request.method == 'POST':
        form = ReviewForm()
    provider = Provider.query.get(form.id.data)
    form.category.choices = [(c.id, c.name) for c in provider.categories]
    if form.validate_on_submit():
        pictures = Picture.savePictures(form)
        Review.create(user_id=current_user.id,
                      provider_id=form.id.data,
                      category_id=form.category.data,
                      rating=form.rating.data,
                      cost=form.cost.data,
                      price_paid=form.price_paid.data,
                      description=form.description.data,
                      service_date=form.service_date.data,
                      comments=form.comments.data,
                      pictures=pictures)
        flash("review added")
        return redirect(url_for('main.index'))
    elif request.method == "POST" and not form.validate():
        return render_template("review.html", title="Review", form=form), 422
    if not current_user.email_verified:
        disableForm(form)
        flash("Form disabled. Please verify email to unlock.")
    return render_template("review.html", title="Review", form=form)
コード例 #6
0
ファイル: views.py プロジェクト: ABERT-NOLA/Pitch--Detect
def single_pitch(id):
    pitch = Pitch.query.get(id)
    if pitch is None:
        abort(404)
    reviews = Review.get_reviews(pitch.id)
    vote_count = Vote.get_vote_count(pitch.id)
    vote_dict = {}
    for type, count in vote_count:
        vote_dict[type] = count
    return render_template(
        'pitch/pitch.html',
        pitch=pitch,
        vote_count=vote_dict,
        reviews=reviews,
        reviewform=ReviewForm(),
        voteform=VoteForm()
    )
コード例 #7
0
def edit_review(review_id):
    review = Review.query.filter_by(id=review_id).first()
    form = ReviewForm(obj=review)
    if review.brand is not None:
        form.brand_name.data = review.brand.name
    if form.validate_on_submit:
        if request.method == 'POST':
            if form.age.data == "":
                age = 0
            else:
                age = int(form.age.data)
            if form.brand_id.data is '0':
                brand = Brand(name=form.brand_name.data)
                db.session.add(brand)
                db.session.flush()
                review.brand_id = brand.id
            else:
                review.brand_id = form.brand_id.data
            review.order = form.order.data
            review.notes = form.notes.data
            review.tasting_note = form.tasting_note.data
            review.name = form.name.data
            review.age = age
            review.max_rating = form.max_rating.data
            review.avg_rating = form.avg_rating.data
            review.min_rating = form.min_rating.data
            review.author = current_user
            if form.image.data is not None:
                filename = secure_filename(form.image.data.filename)
                pathlib.Path(current_app.config['UPLOAD_FOLDER'] + '/' +
                             str(review.id)).mkdir(parents=True, exist_ok=True)
                form.image.data.save(current_app.config['UPLOAD_FOLDER'] +
                                     '/' + str(review.id) + '/' + filename)
                review.img_name = filename
                rotateImage(
                    current_app.config['UPLOAD_FOLDER'] + '/' +
                    str(review.id) + '/', filename)

            db.session.commit()
            flash('Your changes have been saved.')
            return redirect(
                url_for('main.tasting', tasting_id=review.tasting.id))
    return render_template('add_review.html',
                           title='Edit Review',
                           action="Edit",
                           form=form)
コード例 #8
0
def index():
    sentence_aspects = None
    if request.method == 'GET':
        form = ReviewForm()
        if form.validate_on_submit():
            return redirect(url_for('main.index'))
        return render_template('index.html', form=form, sentence_aspects=sentence_aspects)
    else:
        form = ReviewForm(review=request.form.get('review'))

        if form.validate():
            aspects = aspect_extractor.predict(
                form.review.data.split("."))
            sentence_aspects = sentiment_extractor.predict(aspects)
            return render_template('index.html', form=form, sentence_aspects=sentence_aspects)
        return redirect(url_for('main.index'))
コード例 #9
0
def index(sort='name'):
    '''View function for the main index page.'''

    add_repo_form = AddRepoForm()
    review_form = ReviewForm()
    del_review_form = DeleteReviewForm()
    del_topic_form = DeleteTopicForm()
    rename_topic_form = RenameTopicForm()
    del_repo_form = DeleteRepoForm()

    repos = current_user.repos.all()
    topics = None
    recommend = None
    base_url = None
    file_url = None
    add_repo_messages = None
    selected_repo = Repo.query.filter(
        Repo.repository == request.args.get('selected_repo'),
        Repo.user_id == current_user.id).first()

    # if there are repos but none has been selected, default to the first:
    if repos and not selected_repo:
        selected_repo = Repo.query.filter_by(user_id=current_user.id).first()

    if selected_repo:
        # build the base url to link to files:
        base_url = current_app.config['URL_START']
        url_end = current_app.config['URL_END']
        file_url = base_url + selected_repo.repository + url_end

        # get the topics for display:
        if sort == 'skill':
            topics = Topic.query.filter_by(repo_id=selected_repo.id) \
                                .order_by(Topic.current_skill).all()
        elif sort == 'date':
            topics = Topic.query.filter_by(repo_id=selected_repo.id) \
                                .order_by(Topic.last_study_date).all()
        else:
            topics = Topic.query.filter_by(repo_id=selected_repo.id) \
                                .order_by(Topic.filename).all()

        # build select menus for forms:
        form_topics = Topic.query.filter_by(repo_id=selected_repo.id) \
                                 .order_by(Topic.filename).all()
        topic_choices = [(t.filename, t.filename) for t in form_topics]
        repo_choices = [(r.repository, r.repository) for r in repos]
        topic_choices.insert(0, ('', ''))
        repo_choices.insert(0, ('', ''))

        review_form.filename.choices = topic_choices
        del_topic_form.filename.choices = topic_choices
        rename_topic_form.old_filename.choices = topic_choices
        del_repo_form.repository.choices = repo_choices

        # recommend a topic:
        recommend = Topic.recommend_study_topic(selected_repo)

    # process forms
    if add_repo_form.add_repo_submit.data and add_repo_form.validate_on_submit(
    ):
        # check that the repo exists on github and hasn't already beed added:
        reponame = add_repo_form.repository.data
        ping = Repo.ping_repo(reponame)
        repo = Repo.query.filter(Repo.repository == reponame,
                                 Repo.user_id == current_user.id).first()

        if not ping:
            flash("I couldn't find that repository on Github",
                  category='main-fail')
            add_repo_messages = True
        elif repo:
            flash("You've added that one already", category='main-fail')
            add_repo_messages = True
        else:
            repo = Repo(repository=reponame, user_id=current_user.id)
            db.session.add(repo)
            db.session.commit()
            flash('New repository sucessfully added!', category='main-success')
            # direct to add update
            return redirect(url_for('main.update', new_repo=reponame))

    if review_form.review_submit.data and review_form.validate_on_submit():
        topic = Topic.query.filter(
            Topic.repo_id == selected_repo.id,
            Topic.filename == review_form.filename.data).first()
        review = Review(count=current_user.review_count,
                        time_spent=review_form.time_spent.data,
                        skill_before=review_form.skill_before.data,
                        skill_after=review_form.skill_after.data,
                        topic_id=topic.id)
        topic.current_skill = review_form.skill_after.data
        topic.last_study_date = datetime.utcnow()
        if topic.current_skill == 5:
            topic.mastery += 1
        current_user.review_count += 1
        db.session.add(review)
        db.session.commit()
        flash('Review logged!', category='main-success')
        return redirect(
            url_for('main.index',
                    sort='name',
                    selected_repo=selected_repo.repository))

    if del_topic_form.del_topic_submit.data and del_topic_form.validate_on_submit(
    ):
        topic = Topic.query.filter(
            Topic.repo_id == selected_repo.id,
            Topic.filename == del_topic_form.filename.data).first()
        topic.reviews.delete()  # for query delete
        db.session.delete(topic)  # for single query result
        db.session.commit()
        flash('Topic deleted.', category='main-success')
        return redirect(
            url_for('main.index',
                    sort='name',
                    selected_repo=selected_repo.repository))

    if rename_topic_form.rename_submit.data and rename_topic_form.validate_on_submit(
    ):
        topic = Topic.query.filter(
            Topic.repo_id == selected_repo.id,
            Topic.filename == rename_topic_form.old_filename.data).first()
        topic.filename = rename_topic_form.new_filename.data
        db.session.commit()
        flash('Topic renamed!', category='main-success')
        return redirect(
            url_for('main.index',
                    sort='name',
                    selected_repo=selected_repo.repository))

    if del_repo_form.del_repo_submit.data and del_repo_form.validate_on_submit(
    ):
        repo = Repo.query.filter(
            Repo.user_id == current_user.id,
            Repo.repository == del_repo_form.repository.data).first()
        for t in repo.topics.all():
            t.reviews.delete()
        repo.topics.delete()
        db.session.delete(repo)
        db.session.commit()
        flash('Repo deleted', category='main-success')
        return redirect(
            url_for('main.index',
                    sort='name',
                    selected_repo=selected_repo.repository))

    if del_review_form.del_review_submit.data and del_review_form.validate_on_submit(
    ):
        review = Review.query.join(Topic).join(Repo).join(User) \
                             .add_columns(Review.id, Review.skill_after, Review.topic_id) \
                             .filter(Review.count == del_review_form.review_number.data,
                                     User.id == current_user.id).first()
        if not review:
            flash("You don't have a review No. {}".format(
                del_review_form.review_number.data),
                  category='main-fail')
        else:
            Review.query.filter_by(id=review.id).delete()
            topic = Topic.query.filter_by(id=review.topic_id).first()
            prev_review = Review.query.filter_by(topic_id=topic.id) \
                                      .order_by(Review.review_date.desc()).first()
            if prev_review:
                topic.current_skill = prev_review.skill_after
                topic.last_study_date = prev_review.review_date
            else:
                topic.current_skill = topic.start_skill
                topic.last_study_date = topic.created_date
            if review.skill_after == int(5):
                topic.mastery -= 1

            db.session.commit()
            flash('Review session deleted.', category='main-success')
            return redirect(
                url_for('main.index',
                        sort='name',
                        selected_repo=selected_repo.repository))

    return render_template('index.html',
                           sort=sort,
                           repos=repos,
                           topics=topics,
                           selected_repo=selected_repo,
                           recommend=recommend,
                           base_url=base_url,
                           file_url=file_url,
                           add_repo_messages=add_repo_messages,
                           add_repo_form=add_repo_form,
                           review_form=review_form,
                           del_review_form=del_review_form,
                           del_topic_form=del_topic_form,
                           rename_topic_form=rename_topic_form,
                           del_repo_form=del_repo_form)
コード例 #10
0
def review_form():
    form = ReviewForm()
    form.project_id.data = request.form['project_id']
    return render_template('_comment.html', form=form)