コード例 #1
0
def destroy(id):
    obj = Objective.get_by_id(id)

    Objective.delete().where(Objective.id == id).execute()

    trueprogress = len([
        obj
        for obj in Objective.select().where((Objective.user_id == obj.user_id)
                                            & (Objective.done == True))
    ])

    falseprogress = len([
        obj
        for obj in Objective.select().where((Objective.user_id == obj.user_id)
                                            & (Objective.done == False))
    ])

    try:
        progress = trueprogress / (trueprogress + falseprogress)
    except ZeroDivisionError:
        progress = 0

    progress_percentage = "{:.0%}".format(progress)
    response = {"success": True, "progress": progress_percentage}

    return jsonify(response)
コード例 #2
0
ファイル: objective.py プロジェクト: azecoder/ASSE
def set_objective():
    form = ObjectiveForm()

    if form.validate_on_submit():
        existing_objective = None
        objective_distance = km2m(form.data['distance'])

        #existing_objective = db.session.query(Objectives).filter(Objectives.user == user).first()
        obj_json = requests.get(DATASERVICE + '/users/' +
                                str(current_user.id) + '/objectives').json()

        if obj_json:
            existing_objective = Objective(obj_json[0])

        if existing_objective is None:
            #_setObjective(user, objective_distance)
            requests.post(DATASERVICE + '/users/' + str(current_user.id) +
                          '/objectives',
                          json={'distance': objective_distance})

        else:
            #existing_objective.set_distance(objective_distance)
            existing_objective.distance = objective_distance
            r = requests.put(DATASERVICE + '/users/' + str(current_user.id) +
                             '/objectives/' + str(existing_objective.id),
                             json=existing_objective.toJson())

        #db.session.commit()
        return redirect("/")

    return render_template('set_objective.html', form=form)
コード例 #3
0
def create(username):
    user = User.get_or_none(User.name == username)
    obj = request.form.get("objective")
    Objective.create(objective=obj, user=user.id)
    if user.id != current_user.id:
        Notification.create(notification_type=1,
                            sender=current_user.id,
                            recipient=user.id)
    flash("Objective succesfully added")
    return redirect(url_for('users.show', username=username))
コード例 #4
0
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)
コード例 #5
0
ファイル: views.py プロジェクト: shawnlah/worqlyfe
def show(username):
    user = User.get_or_none(User.name == username)
    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)

    if user:
        return render_template("users/profile.html", user=user, star=star, gold=gold, silver=silver, bronze=bronze, completed_objectives=completed_objectives, incomplete_objectives=incomplete_objectives, progress=progress, progress_percentage=progress_percentage)
コード例 #6
0
 def incomplete_objective(self):
     from models.objective import Objective
     return [
         obs for obs in Objective.select().where(
             (Objective.user_id == self.id)
             & (Objective.done == False)).order_by(Objective.id.asc())
     ]
コード例 #7
0
    def progress(self):
        from models.objective import Objective
        trueprogress = len([
            obj
            for obj in Objective.select().where((Objective.user_id == self.id)
                                                & (Objective.done == True))
        ])

        falseprogress = len([
            obj
            for obj in Objective.select().where((Objective.user_id == self.id)
                                                & (Objective.done == False))
        ])
        try:
            ppprogress = trueprogress / (trueprogress + falseprogress)
        except ZeroDivisionError:
            ppprogress = 0

        return ppprogress
コード例 #8
0
ファイル: views.py プロジェクト: shawnlah/worqlyfe
def show_review(id):
    user = User.get_or_none(User.id == id)
    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()
    manager = User.get_or_none(User.id == user.manager_id)
    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)
    executive_notes = Review.select().where((Review.executive_id == user.id)
                                            & (Review.executive_notes.is_null(False)))
    manager_notes = Review.select().where((Review.executive_id == user.id)
                                          & (Review.manager_notes.is_null(False)))
    return render_template('users/review.html', user=user, manager=manager, star=star, gold=gold, silver=silver, bronze=bronze, executive_notes=executive_notes, manager_notes=manager_notes, completed_objectives=completed_objectives, incomplete_objectives=incomplete_objectives, progress_percentage=progress_percentage)
コード例 #9
0
ファイル: test_of_all_module.py プロジェクト: azecoder/ASSE
def test_module_objective():
    objective = Objective(None)
    assert objective.toJson() == {}

    objective = Objective({
        "objective_id": 1,
        "distance": 30,
        "user_id": 2,
    })
    assert objective.toJson() == {"objective_id": 1, "distance": 30, "user_id": 2}
コード例 #10
0
def update(id):

    obj = Objective.get_by_id(id)

    if obj.done:
        Objective.update(done=False).where(Objective.id == obj.id).execute()
        progress = len(Objective.select().where(
            (Objective.user_id == obj.user_id) & (Objective.done == True)
        )) / (len(Objective.select().where((Objective.user_id == obj.user_id) &
                                           (Objective.done == True))) +
              len(Objective.select().where((Objective.user_id == obj.user_id) &
                                           (Objective.done == False))))
        progress_percentage = "{:.0%}".format(progress)

        response = {
            "success": True,
            "done": False,
            "progress": progress_percentage
        }

    else:
        Objective.update(done=True).where(Objective.id == obj.id).execute()
        progress = len(Objective.select().where(
            (Objective.user_id == obj.user_id) & (Objective.done == True)
        )) / (len(Objective.select().where((Objective.user_id == obj.user_id) &
                                           (Objective.done == True))) +
              len(Objective.select().where((Objective.user_id == obj.user_id) &
                                           (Objective.done == False))))
        progress_percentage = "{:.0%}".format(progress)
        response = {
            "success": True,
            "done": True,
            "progress": progress_percentage
        }
    return jsonify(response)