def index(): objective = Objective.select().where(Objective.user_id == current_user.id) compliments_received_msg = Compliment.select().where( Compliment.recipient_id == current_user.id).limit(5) compliments_given_msg = Compliment.select().where( Compliment.sender_id == current_user.id).limit(5) departments = User.select().where( User.department == current_user.department) all_users = User.select() compliments_received = Compliment.select().where( Compliment.recipient_id == current_user.id).count() compliments_given = Compliment.select().where( Compliment.sender_id == current_user.id).count() user = User.get_or_none(User.id == current_user.id) rep = Feedback.select().where(Feedback.requester_id == current_user.id) feedback_exist = Feedback.select().where( (Feedback.receiver_id == current_user.id) & (Feedback.answered == False)) star = Medal.select().where(Medal.medal_caption == "Star").get() gold = Medal.select().where(Medal.medal_caption == "Gold").get() silver = Medal.select().where(Medal.medal_caption == "Silver").get() bronze = Medal.select().where(Medal.medal_caption == "Bronze").get() completed_objectives = Objective.select().where( (Objective.user_id == user.id) & (Objective.done == True)) incomplete_objectives = Objective.select().where( (Objective.user_id == user.id) & (Objective.done == False)) try: progress = ( completed_objectives.count() / (completed_objectives.count() + incomplete_objectives.count())) except ZeroDivisionError: progress = 0 progress_percentage = "{:.0%}".format(progress) return render_template('dashboard/new.html', objectives=objective, compliments_received_msg=compliments_received_msg, compliments_given_msg=compliments_given_msg, departments=departments, all_users=all_users, user=user, progress_percentage=progress_percentage, progress=progress, compliments_received=compliments_received, compliments_given=compliments_given, gold=gold, silver=silver, bronze=bronze, star=star, feedback_exist=feedback_exist, rep=rep)
def reply(id): reply_message = request.form.get('formReply') Feedback.update(answered=True).where(Feedback.id == id).execute() Replies(reply_message=reply_message, feedback_replied_id=id).save() any_feedback_left = False feedback_exist = Feedback.select().where( (Feedback.receiver_id == current_user.id) & (Feedback.answered == False)) if feedback_exist: any_feedback_left = True resp = {'success': True, 'any_feedback_left': any_feedback_left} return jsonify(resp)