コード例 #1
0
def add_feedback(username):
    if 'user_username' not in session:
        flash("You must login", "warning")
        return redirect("/login")
    sessuser = session["user_username"]
    form = FeedbackForm()
    if form.validate_on_submit():
        title = form.title.data
        content = form.feedback.data
        new_feedback = Feedback(title = title, content = content, username = username)
        db.session.add(new_feedback)
        try:
            db.session.commit()
        except IntegrityError as e:
            err = str(e)
            if "feedback_title_key" in err:
                form.title.errors = ["Title cannot be blank"]
            if "feedback_feedback_key" in err:
                form.feedback.errors = ["Feedback cannot be blank"]
        flash("Successfully created feedback", "success")
        return redirect(f"/users/{username}")
    if username == session["user_username"]:
        return render_template("feedback.html", form = form)
    flash("You dont have permission to do that", "danger")
    return redirect(f"/users/{sessuser}")
コード例 #2
0
def new_feedback(username):
    """Show add-feedback form and process it."""

    if "username" not in session or username != session['username']:
        raise Unauthorized()

    form = FeedbackForm()

    if form.validate_on_submit():
        title = form.title.data
        content = form.content.data

        feedback = Feedback(
            title=title,
            content=content,
            username=username,
        )

        db.session.add(feedback)
        db.session.commit()

        return redirect(f"/users/{feedback.username}")

    else:
        return render_template("feedback.html", form=form)
コード例 #3
0
ファイル: app.py プロジェクト: starmanDX/springboard
def add_feedback(username):
    """Show the page to add feedback for the current user
        or add feedback for the current user"""

    form = FeedbackForm()

    if form.validate_on_submit():
        title = form.title.data
        content = form.content.data
        new_feedback = Feedback(title=title,
                                content=content,
                                username=username)
        db.session.add(new_feedback)
        db.session.commit()

        flash('Successfully added feedback!', 'success')
        return redirect('/')

    try:
        user = User.query.filter_by(username=username).one()

        if "user_id" not in session:
            flash('Please log in first.', 'danger')
            return redirect('/login')

        if user.username == session['username']:
            return render_template('add_feedback.html', form=form)

        else:
            flash("You don't have permission to access that!", 'danger')
            return redirect('/')

    except:
        flash("Page not found. Redirecting!", 'info')
        return redirect('/')
コード例 #4
0
def feedback(username):
    """Show feedback form (GET) or add feedback to db (POST)"""

    if "username" in session:
        form = FeedbackForm()
        user = User.query.get_or_404(username)

        if user.username == session['username']:
            if form.validate_on_submit():
                title = form.title.data
                content = form.content.data
                username = user.username

                # create a feedback instance
                feedback = Feedback(title=title, content=content, username=username)
                db.session.add(feedback)
                db.session.commit()

                return redirect(f"/users/{ username }")

            return render_template("feedback_form.html", form=form)
        else:
            flash("You do not have permission to edit that")
            return redirect(f"/users/{ session['username'] }")
    else:
        flash("Need to be logged in to submit feedback")
        return render_template("login.html", form=form)
コード例 #5
0
def edit_feedback(feedback_id):
    """Allow user who created a feedback to edit it"""

    if "username" in session:
        feedback = Feedback.query.get_or_404(feedback_id)
        user = User.query.get_or_404(feedback.user.username)

        if user.username == session['username']:
            form = FeedbackForm(title=feedback.title, content=feedback.content)
            
            if form.validate_on_submit():
                feedback.title = form.title.data
                feedback.content = form.content.data

                db.session.add(feedback)
                db.session.commit()

                return redirect(f"/users/{ user.username }")

            return render_template("feedback_form.html", form=form)
        else:
            flash("You do not have permission to edit that")
            return redirect("/")
    else:
        flash("Need to be logged in to edit feedback")
        return render_template("login.html", form=form)
コード例 #6
0
def edit_feedback(id):
    """GET: Display a form to edit feedback 
    Only the user who has written that feedback can see this form 
    
    POST: Update a specific piece of feedback and redirect to /users/<username>
    Only the user who has written that feedback can update it"""

    fb = Feedback.query.get_or_404(id)
    if not 'username' in session:
        flash('You must be logged in to view that page.', 'error')
        return redirect('/login')
    elif not session['username'] == fb.user.username:
        flash("You don't have permission to view that page.", 'error')
        return redirect('/login')

    form = FeedbackForm(obj=fb)

    if form.validate_on_submit():
        fb.title = form.title.data
        fb.content = form.content.data

        db.session.commit()
        flash(f"Updated feedback: {fb.title}", "success")
        return redirect(f"/users/{fb.user.username}")

    else:
        return render_template("edit_feedback.html", form=form)
コード例 #7
0
def add_feedback(username):
    """GET: Display a form to add feedback. Only the user who is logged in can see this form
    
    POST: Add a new piece of feedback and redirect to /users/<username> 
    Only the user who is logged in can successfully add feedback"""

    if not 'username' in session:
        flash('You must be logged in to view that page.', 'error')
        return redirect('/login')
    elif not session['username'] == username:
        flash("You don't have permission to view that page.", 'error')
        return redirect('/login')

    form = FeedbackForm()
    if form.validate_on_submit():
        title = form.title.data
        content = form.content.data

        fb = Feedback(title=title, content=content, username=username)
        try:
            db.session.add(fb)
            db.session.commit()

            flash(f"Feedback submitted!", "success")
            return redirect(f'/users/{username}')
        except:
            flash(f"Error submitting feedback.", "error")

    return render_template('add_feedback.html', form=form)
コード例 #8
0
ファイル: app.py プロジェクト: nathanmass1/Flask-Feedback
def update_user_feedback(feedback_id):

    userperson = Feedback.query.get(feedback_id)
    username = userperson.username
    session_user = User.query.get(session["username"])

    print(username)
    form = FeedbackForm(obj=userperson)

    if "username" not in session:
        flash("You better login!")
        return redirect("/")
    if session["username"] != username and not session_user.user.is_admin:
        flash("Must be logged in to see form")
        return redirect("/")

    if form.validate_on_submit():
        feedback = Feedback.query.get(feedback_id)

        title = form.title.data
        content = form.content.data

        feedback.title = title
        feedback.content = content

        db.session.commit()

        return redirect(f"/users/{username}")

    return render_template("add_feedback.html", form=form)
コード例 #9
0
def feedback_form(username):
    """Display a form to add feedback""" 

    authenticated_user = User.query.filter_by(username=username).first()
    
    if not authenticated_user:
        return redirect("/register")
    
    if "username" not in session:
        return redirect("/register")

    form = FeedbackForm()

    if form.validate_on_submit():
        title = form.title.data
        feedback = form.feedback.data

        new_feedback = Feedback(title=title, feedback=feedback)
        new_feedback.username = authenticated_user.username
        db.session.add(new_feedback)
        db.session.commit()

        return redirect(f"/users/{username}")

    else:
        return render_template("feedback-form.html", form=form, 
                               user=authenticated_user)
コード例 #10
0
def edit_feedback(id):
    if 'user_username' not in session:
        flash("You must login", "warning")
        return redirect("/login")
    sessuser = session["user_username"]
    form = FeedbackForm()
    feedback = Feedback.query.get(id)
    if form.validate_on_submit():
        title = form.title.data
        content = form.feedback.data
        feedback.title = title
        feedback.content = content
        db.session.add(feedback)
        try:
            db.session.commit()
        except IntegrityError as e:
            err = str(e)
            if "feedback_title_key" in err:
                form.title.errors = ["Title cannot be blank"]
            if "feedback_feedback_key" in err:
                form.feedback.errors = ["Feedback cannot be blank"]
        flash("Successfully edited feedback", "success")
        return redirect(f"/users/{sessuser}")
    if sessuser == feedback.username:
        form.title.data = feedback.title
        form.feedback.data = feedback.content
        return render_template("editfeedback.html", form = form)
    flash("You dont have permission to do that", "danger")
    return redirect(f"/users/{sessuser}")
コード例 #11
0
def show_update_feedback_form(feedback_id):
    """ Let's logged in users update their previous feedback """
    # TODO jay: come back through and make this a function taking
    # flash message and redirect
    previous = Feedback.query.get_or_404(feedback_id)

    if "user_username" not in session:
        flash("You must be logged in to give feedback! Put your name on it!")
        return redirect("/login")
    elif session['user_username'] != previous.username:
        flash("You can't edit someone else's feedback")
        return redirect('/')
    else:
        # pulls current version of feedback
        # passing obj of previous into FeedbackForm to auto fill values
        form = FeedbackForm(obj=previous)

        if form.validate_on_submit():
            title = form.title.data
            content = form.content.data

            previous.title = title
            previous.content = content

            db.session.commit()
            return redirect(f'/users/{previous.username}')

        else:
            return render_template('edit_feedback.html', form=form)
コード例 #12
0
ファイル: app.py プロジェクト: nathanmass1/Flask-Feedback
def add_user_feedback(username):

    form = FeedbackForm()
    user = User.query.get_or_404(username)
    session_user = User.query.get(session["username"])

    if "username" not in session:
        flash("You better login!")
        return redirect("/")
    if session["username"] != username and not session_user.is_admin:
        flash("Must be logged in to see form")
        return redirect("/")

    if form.validate_on_submit():
        title = form.title.data
        content = form.content.data

        feedback = Feedback(title=title,
                            content=content,
                            username=session["username"])

        db.session.add(feedback)
        db.session.commit()

        return redirect(f"/users/{username}")

    return render_template("add_feedback.html", form=form)
コード例 #13
0
def update_feedback(feedback_id):
    """Show update-feedback form and process it."""

    feedback = Feedback.query.get(feedback_id)

    if "username" not in session or feedback.username != session['username']:
        raise Unauthorized()

    form = FeedbackForm(obj=feedback)

    if form.validate_on_submit():
        feedback.title = form.title.data
        feedback.content = form.content.data

        db.session.commit()

        return redirect(f"/users/{feedback.username}")

    return render_template("/feedback_edit.html", form=form, feedback=feedback)

# @app.route('/tweets/<int:id>', methods=["POST"])
# def delete_tweet(id):
#     """Delete tweet"""
#     if 'user_id' not in session:
#         flash("Please login first!", "danger")
#         return redirect('/login')
#     tweet = Tweet.query.get_or_404(id)
#     if tweet.user_id == session['user_id']:
#         db.session.delete(tweet)
#         db.session.commit()
#         flash("Tweet deleted!", "info")
#         return redirect('/tweets')
#     flash("You don't have permission to do that!", "danger")
#     return redirect('/tweets')
コード例 #14
0
def feedback_user(username):
    """Add feedback for a certain user"""
    if "username" not in session:
        raise Unauthorized()
    if username != session['username']:
        raise Forbidden()
        # flash("Sorry, you don't have permission to add a feedabck. Login first.")
        # return redirect('/login')

    form = FeedbackForm()

    if form.validate_on_submit():
        title = form.title.data
        content = form.content.data

        new_feedback = Feedback(title=title,
                                content=content,
                                username=username)
        db.session.add(new_feedback)
        db.session.commit()

        flash("Feedback was added.", "info")
        return redirect(f'/users/{username}')
    else:
        return render_template('feedback/add.html',
                               form=form,
                               username=username)
コード例 #15
0
def add_feedback(username):
    """Display and handle form to add feedback."""

    

    if "user_name" not in session:
        flash("You must be logged in to view!")
        return redirect(f"/")

    else:
        form = FeedbackForm()

        if form.validate_on_submit():
            title = form.title.data
            content = form.content.data

            feedback = Feedback.add(title=title, content=content, username=username)
            db.session.add(feedback)
            db.session.commit()
            return redirect(f"/users/{username}")

        else:
            flash("Sorry! Something went wrong with your feedback. Please try again.")
            return render_template("feedback.html", form=form)
    
        return render_template("feedback.html", form=form)
コード例 #16
0
def update_feedback(feedback_id):
    """Show update-feedback form and process it."""

    feedback = Feedback.query.get(feedback_id)

    if "user_id" not in session:
        flash("You are not authorized", "danger")
        return redirect('/')
    id = session['user_id']
    main_user = User.query.get_or_404(id)
    if main_user.username != feedback.username:
        flash("You are not authorized", "danger")
        return redirect('/')

    form = FeedbackForm(obj=feedback)

    if form.validate_on_submit():
        feedback.title = form.title.data
        feedback.content = form.content.data

        db.session.commit()

        return redirect(f"/user/{feedback.username}")

    return render_template("/edit_feedback.html",
                           form=form,
                           feedback=feedback,
                           main_user=main_user)
コード例 #17
0
def new_feedback(username):
    """Show add-feedback form and process it."""

    if "user_id" not in session:
        flash("You are not authorized", "danger")
        return redirect('/')
    id = session['user_id']
    main_user = User.query.get_or_404(id)
    form = FeedbackForm()

    if form.validate_on_submit():
        title = form.title.data
        content = form.content.data

        feedback = Feedback(
            title=title,
            content=content,
            username=username,
        )

        db.session.add(feedback)
        db.session.commit()

        return redirect(f"/user/{feedback.username}")

    else:
        return render_template("new_feedback.html",
                               form=form,
                               main_user=main_user)
コード例 #18
0
def new_feedback(username):
    """Show add-feedback form and process it."""

    if "user_name" not in session or username != session['user_name']:
        flash("Please login first!", "danger")
        return redirect("/")

    form = FeedbackForm()

    if form.validate_on_submit():
        title = form.title.data
        content = form.content.data

        feedback = Feedback(
            title=title,
            content=content,
            username=username,
        )

        db.session.add(feedback)
        db.session.commit()
        flash("Sucessfully Added New Feedback", "success")
        return redirect(f"/users/{feedback.username}")

    else:
        return render_template("feedback.html", form=form)
コード例 #19
0
ファイル: app.py プロジェクト: imgeorge220/flask-feedback
def add_feedback(username):
    """ Add feedback """

    form = FeedbackForm()

    user_id = session.get('user_id')
    logged_in_user = User.query.get(user_id)

    try:
        user = User.query.filter(User.username == username).one()
    except Exception:
        abort(404)

    if user_id != user.id and not logged_in_user.is_admin:
        abort(401)

    if form.validate_on_submit():

        feedback = {
            "title": form.title.data,
            "content": form.content.data,
            "username": username
        }

        new_feedback = Feedback(**feedback)
        db.session.add(new_feedback)
        db.session.commit()

        return redirect(f"/users/{username}")

    return render_template('feedback-form.html',
                           user=user,
                           form=form,
                           action=f'/users/{username}/feedback/add')
コード例 #20
0
ファイル: app.py プロジェクト: imgeorge220/flask-feedback
def update_feedback(feedback_id):
    """ Update Feedback """

    form = FeedbackForm()

    user_id = session.get('user_id')
    logged_in_user = User.query.get(user_id)

    feedback = Feedback.query.get_or_404(feedback_id)
    user = feedback.user

    if user_id != user.id and not logged_in_user.is_admin:
        abort(401)

    if form.validate_on_submit():
        feedback.title = form.title.data
        feedback.content = form.content.data

        db.session.commit()

        return redirect(f'/users/{user.username}')

    form.title.data = feedback.title
    form.content.data = feedback.content

    return render_template('feedback-form.html',
                           user=user,
                           form=form,
                           action=f'/feedback/{feedback_id}/update')
コード例 #21
0
def add_feedback(username):
    """Add feedback for a user, or if submitted create a new feedback instance for the user"""

    curr_user = User.query.filter(User.username == username).first()

    if "username" not in session or username != session['username']:
        flash("You must be logged in to add feedback")
        return redirect("/")

    form = FeedbackForm()

    if form.validate_on_submit():

        title = form.title.data
        content = form.content.data
        new_feedback = Feedback(title=title,
                                content=content,
                                username=curr_user.username)
        db.session.add(new_feedback)
        db.session.commit()
        # on successful adding of feedback bring back to users pages
        return redirect(f"/users/{username}")

    else:
        return render_template("add_feedback.html", form=form)
コード例 #22
0
ファイル: app.py プロジェクト: sairina/flask-feedback
def edit_feedback(feedback_id):
    """ Logged-in user: Edit feedback form """

    feedback = Feedback.query.get_or_404(feedback_id)

    if "username" not in session:
        flash("You must be logged in to view!")
        abort(401)

    elif feedback.user.username != session['username']:
        flash("You can only give yourself feedback!")
        abort(401)

    else:
        user = User.query.get_or_404(feedback.user.username)
        form = FeedbackForm(obj=feedback)

        if form.validate_on_submit():
            feedback.title = form.title.data
            feedback.content = form.content.data

            db.session.commit()

            return redirect(f'/users/{session["username"]}')

        return render_template("edit-feedback.html", user=user, feedback=feedback, form=form)
コード例 #23
0
ファイル: app.py プロジェクト: a-packer/flask_feedback
def new_feedback(username):
    """Show add-feedback form and process it."""

    user = User.query.get_or_404(username)

    if "username" not in session or username != session['username']:
        flash('Not Authorized', "danger")
        return redirect(f"/users/{session['username']}")

    form = FeedbackForm()

    if form.validate_on_submit():
        title = form.title.data
        content = form.content.data
        feedback = Feedback(title=title, content=content, username=username)

        db.session.add(feedback)
        db.session.commit()

        all_feedback = Feedback.query.all()
        for feedback in all_feedback:
            print(feedback.title)

        form = DeleteForm()
        return render_template('user_page.html', user=user, form=form)

    else:
        return render_template("add_feedback.html",
                               form=form,
                               username=username)
コード例 #24
0
ファイル: app.py プロジェクト: JakLarsen/SpringBoard
def update_feedback(id):
    """Render form to update feedback and post submission"""

    if "username" not in session:
        flash("Please login first!")
        return redirect('/')

    our_feedback = Feedback.query.get_or_404(id)
    our_user = our_feedback.user.username

    #if the feedback not by person logged in, send error, redirect to /
    if our_user != session['username']:
        flash("Wrong User!")
        return redirect('/')
    
    form = FeedbackForm()
    
    if form.validate_on_submit():
        title = form.title.data
        content = form.content.data
        our_feedback.title = title
        our_feedback.content = content

        db.session.commit()

        return redirect(f'/users/{our_user}')

    return render_template('edit_feedback.html', form=form, feedback = our_feedback)
コード例 #25
0
ファイル: app.py プロジェクト: sairina/flask-feedback
def add_feedback(username):
    """ Logged-in user: Add feedback form """

    if "username" not in session:
        flash("You must be logged in to view!")
        abort(401)

    elif username != session['username']:
        flash("You can only give yourself feedback!")
        abort(401)

    else:
        user = User.query.get_or_404(username)
        form = FeedbackForm()

        if form.validate_on_submit():
            title = form.title.data
            content = form.content.data
            new_feedback = Feedback(title=title,
                                    content=content,
                                    username=username)

            db.session.add(new_feedback)
            db.session.commit()

            return redirect(f'/users/{session["username"]}')

        return render_template("feedback.html", user=user, form=form)
コード例 #26
0
ファイル: views.py プロジェクト: ttiurani/troikalearning
def feedback():
    feedbackerrors = []
    feedbackform = FeedbackForm()
    user = None
    given_feedback = []
    if 'email' in session: 
        user = get_user(session['email'])
        if user.role == 'admin':
            # For admins, the feedback is shown
            given_feedback = get_feedback()
    
    if feedbackform.validate_on_submit():
        feedback = Feedback(created = datetime.now(),
                            description=feedbackform.description.data,
                            user=user)
        save_feedback(feedback)
        flash(_(u"Feedback saved. Thank you!"))
        return redirect(url_for('troikas'))
        
    if feedbackform.errors:
        for key, value in feedbackform.errors.items():
            feedbackerrors.append(key + ': ' + value[0])

    return render_template('feedback.html', feedbackform=feedbackform, 
                           feedbackerrors=feedbackerrors,
                           given_feedback=given_feedback)
コード例 #27
0
def update_feedback(feedback_id):
    feedback = Feedback.query.get_or_404(feedback_id)

    if 'username' in session and session[
            'username'] == feedback.username or User.query.get(
                session['username']).is_admin:
        form = FeedbackForm()

        if form.validate_on_submit():
            feedback.title = form.title.data
            feedback.content = form.content.data

            db.session.commit()

            return redirect(f"/users/{session['username']}")
        form.content.data = feedback.content
        users = User.query.all()
        logged_in_user = User.query.get(session['username'])
        return render_template('update_feedback_form.html',
                               form=form,
                               users=users,
                               logged_in_user=logged_in_user,
                               username=session['username'],
                               feedback=feedback)
    return redirect('/login')
コード例 #28
0
ファイル: app.py プロジェクト: kamalkhadka/springboard
def update_feedback(feedback_id):
    """ View function to update feedback """
    if 'username' not in session:
        flash('You are not authorized')
        return redirect('/')

    feedback = Feedback.query.get(feedback_id)

    if not feedback:
        return render_template('404.html')

    form = FeedbackForm(obj=feedback)

    if session.get('username'
                   ) == feedback.user.username and form.validate_on_submit():
        feedback.title = form.title.data
        feedback.content = form.content.data

        db.session.add(feedback)
        db.session.commit()

        return redirect(f'/users/{feedback.user.username}')
    else:
        return render_template('update-feedback.html',
                               form=form,
                               feedback_id=feedback.id)
コード例 #29
0
def edit_feedback(feedback_id):
    """Update feedback details"""

    feedback = Feedback.query.get_or_404(feedback_id)

    username = feedback.username

    if 'username' not in session:
        flash("You have to be logged in to edit feedback!")
        return redirect("/")
    # elif not feedback:
    #     username = session['username']
    #     flash("That feedback does not exist Lord Vader!")
    #     return redirect(f"/users/{username}")
    elif session['username'] != username:
        flash("You cant edit feedback for others you sith lowlife!")
        return redirect("/")

    form = FeedbackForm(obj=feedback)

    if form.validate_on_submit():
        feedback.title = form.title.data
        feedback.content = form.content.data

        db.session.commit()

        return redirect(f"/users/{username}")

    return render_template('edit_feedback.html', form=form)
コード例 #30
0
ファイル: app.py プロジェクト: lawrencedovin/flask-feedback
def add_feedback(username):
    if 'username' not in session:
        flash('Please login before continuing.', 'info')
        return ('/login')

    if session['username'] == username:
        form = FeedbackForm()
        if form.validate_on_submit():
            title = form.title.data
            content = form.content.data
            user = User.query.get(session['username'])

            feedback = Feedback(title=title,
                                content=content,
                                username=user.username)
            db.session.add(feedback)
            db.session.commit()

            flash(f'{user.username} Successfully Created Feedback', 'success')
            return redirect(f'/users/{user.username}')

        else:
            return render_template('add_feedback.html', form=form)

    flash('Your account cannot access that page.', 'info')
    return redirect('/')
コード例 #31
0
ファイル: app.py プロジェクト: bpruitt63/sql-and-flask
def update_feedback(feedback_id):

    feedback = Feedback.query.get_or_404(feedback_id)
    user = feedback.user
    form = FeedbackForm(obj=feedback)

    if form.validate_on_submit():
        if user.username == session['user']:
            username = feedback.user.username
            feedback.title = request.form['title']
            feedback.content = request.form['content']
            db.session.commit()
            return redirect(f'/users/{username}')
        else:
            flash('Can only edit your own feedback')
            username = session['user']
            return redirect(f'/users/{username}')
    elif 'user' not in session:
        flash('User must be logged in')
        return redirect('/login')
    elif user.username == session['user']:
        return render_template('/update.html', form=form)
    else:
        flash('Can only edit your own feedback')
        username = session['user']
        return redirect(f'/users/{username}')
コード例 #32
0
ファイル: views.py プロジェクト: madhavsuresh/premier
def enter():
#hacky hack
    form = FeedbackForm(csrf_enabled = False)
    if form.validate_on_submit():
        print 'woot!'
        ad = form_to_dict(form)
        handle_form_data(ad)
        return redirect('/')
    return render_template('form.html',form = form)
コード例 #33
0
ファイル: views.py プロジェクト: JrtPec/coopkot
def send_feedback():
    form = FeedbackForm()
    if form.validate_on_submit():
        newFeedback = Feedback(sender=g.user,text=form.text.data, timestamp=datetime.utcnow())
        db.session.add(newFeedback)
        db.session.commit()
        flash('Your feedback has been submitted! Thank you!')
        return redirect(url_for('index'))
    return render_template('send_feedback.html',
        form = form)
コード例 #34
0
ファイル: views.py プロジェクト: ramin32/Hangspot
def feedback():
    if request.method == "GET":
        return render_template("feedback.html", form=FeedbackForm())

    form = FeedbackForm(request.form)
    if form.validate_on_submit():
        feedback = Feedback(form.name.data, form.email.data, form.message.data)
        db.session.add(feedback)
        db.session.commit()
        flash("Thank you for your comment!")
        return redirect(url_for("views.profiles"))

    return render_template("feedback.html", form=form)