Пример #1
0
def create_feedback(username):
    form = FeedbackForm()

    if 'user' not in session:
        flash('Please sign in or register first')
        return redirect('/')
    else:
        if form.validate_on_submit():
            flash("Feedback added")
            user = User.query.get(username)

            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/{user.username}')
        else:
            user = User.query.get(username)
            return render_template('feedback.html', form=form, user=user)
Пример #2
0
def update_feedback(f_id):
    if session.get('user', default=None) is None:
        flash('Please login or register')
        return redirect('/')
    else:
        feedback = Feedback.query.get(f_id)
        user = User.query.get(feedback.username)
        form = FeedbackForm(obj=feedback)

        if user.username != feedback.username:
            flash('You can not edit this post')
            return redirect(f'/users/{user.username}')
        else:
            if form.validate_on_submit():
                flash("Feedback updated")

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

                db.session.commit()

                return redirect(f'/users/{user.username}')
            else:
                return render_template('update_feed.html',
                                       form=form,
                                       user=user,
                                       feedback=feedback)
Пример #3
0
def main(user_exit=False):
    form_ex = NewExForm()
    form_train = NewTrainForm()
    form_feedback = FeedbackForm()
    if user_exit:
        crud.AddTokenToBlacklist()
        return redirect(url_for('index'))
    if form_ex.name.data and form_ex.is_submitted():
        crud.AddExerciseToDataBase()
        return redirect(url_for('main'))
    if form_feedback.text.data and form_feedback.is_submitted():
        crud.AddFeedbackToDataBase()
        return redirect(url_for('main'))
    if form_train.date.data and form_train.is_submitted():
        crud.AddTrainingToDataBase()
        return redirect(url_for('main'))
    ex_list = crud.GetExerciseList()
    csrf_token = (get_raw_jwt() or {}).get("csrf")
    response = make_response(
        render_template('home.html',
                        form_feedback=form_feedback,
                        form_ex=form_ex,
                        form_train=form_train,
                        ex_list=ex_list,
                        csrf_token=csrf_token))
    response.set_cookie(key='current_page', value='main')
    return response
Пример #4
0
def add_feed(username):
    form = FeedbackForm()
    if 'username' not in session:
        flash('Please login to access this page', 'danger')
        return redirect('/login')
    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/{username}')
    return render_template('feed_form.html', form=form)
Пример #5
0
def feedback(request):
    if request.method == 'POST':
        form = FeedbackForm(request.POST)
        if form.is_valid():
            try:
                Feedback(user=request.user,
                         title=request.POST['title'],
                         message_text=request.POST['message_text']).save()
                messages.success(request, 'Thanks for your feedback!')
            except KeyError:
                messages.warning(request, 'Error, please try again.')
        else:
            messages.error(request, 'Please all the fields are required!')
    return HttpResponseRedirect(reverse('dashboard:dashboard'))
Пример #6
0
def edit_feed(id):
    
    if 'username' not in session:
        flash('Please login first', 'danger')
        return redirect('/login')
    feed = Feedback.query.get_or_404(id)
    form = FeedbackForm(obj=feed)
    if feed.username == session['username']:
        
        if form.validate_on_submit():
            feed.title = form.title.data
            feed.content = form.content.data
            db.session.commit()
            return redirect(f'/users/{feed.username}')
        else:
            return render_template('edit_feed.html', form=form)
    
    flash("Sorry you do not have permissions", 'danger')
    return redirect(f'/users/{session["username"]}')
Пример #7
0
	def index():
		"""
			Render the view of index page.
		"""
		form = FeedbackForm()
		return render_template('index.html', title='Tri Sinergi Mitra', current_page='TSM', form=form)