Пример #1
0
def expense_recording_submit(user_id, calendar_week=get_current_week_number()):
    user = get_user_by_id(user_id)

    working_hours = dict(
        map(lambda v: (v.project_id, v),
            get_working_hour_for_user(user.id, calendar_week) or []))

    for key in request.form.keys():
        # Cleanup irrelevant form data
        if key.startswith("start") or key.startswith("end") or key.startswith(
                "i_"):
            pass
        else:
            # project_id_weekday --> 1_ProjectAlpha
            (project_id, weekday) = key.split("_")
            project_id = int(project_id)

            # get hours worked
            time = request.form.get(key)

            # if project has no work hours, create an entry
            if project_id not in working_hours.keys():
                working_hours[project_id] = WorkingHour(
                    user.id, project_id, calendar_week, "")

            # patch working hour directly into WorkHour's dict
            working_hours[project_id].__dict__[weekday] = time

    for working_hour in working_hours.values():
        put_working_hour(working_hour)

    return redirect(
        url_for("performance_recording.performance_recording",
                user_id=user.id,
                calendar_week=calendar_week))
Пример #2
0
 def delete(self, user_id):
     """Updates a user."""
     response_object = {}
     user = get_user_by_id(user_id)
     if not user:
         users_namespace.abort(404, f"User {user_id} does not exist")
     delete_user(user)
     response_object["message"] = f"{user.email} was removed!"
     return response_object, 200
Пример #3
0
    def get_user_liked_levels(self, user_id):
        """
        This method will return a list of levels this user has liked
        @param user_id: int id of the user we are looking for list of levels liked

        sample curl:
            curl -X GET http://localhost:8080/user/2/like
        """
        user = user_service.get_user_by_id(int(user_id))
        self.send_response({"liked_levels": user.likes})
Пример #4
0
def reports(user_id):
    user = get_user_by_id(user_id)
    calendar_weeks = get_available_calendar_weeks(user_id)
    return render_template("reports.html",
                           company=config.company_name,
                           application=config.app_name,
                           user=current_user,
                           projects=get_projects_for_user(user.id),
                           calendar_weeks=calendar_weeks,
                           calendar_week=get_current_week_number())
Пример #5
0
def like_level(level_id, user_id):
    """
    This method will add a like to a level by a user
    @param level_id: integer id of the level we are adding the like
    @param user_id: integer id of the user who liked the level
    """
    level = get_level_by_id(level_id)
    user = user_service.get_user_by_id()
    user.likes.append(level_id)
    level.likes.append(user_id)
    level.put()
    user._put()
Пример #6
0
    def get_user_comments(self, user_id):
        """
        This method will return a list of comments on the levels this user has made
        @param user_id: int id of the user we want to get list of comments for

        sample curl:
            curl -X GET http://localhost:8080/user/2/comment
        """
        user = user_service.get_user_by_id(int(user_id))
        comments = [{'text': comment.text, 'level_id': comment.level_id, 'date': comment.date}
                    for comment in user.comments]
        self.send_response({"comments": comments})
Пример #7
0
    def put(self, user_id):
        """Updates a user."""
        post_data = request.get_json()
        username = post_data.get("username")
        email = post_data.get("email")
        response_object = {}

        user = get_user_by_id(user_id)
        if not user:
            users_namespace.abort(404, f"User {user_id} does not exist")
        update_user(user, username, email)
        response_object["message"] = f"{user.id} was updated!"
        return response_object, 200
Пример #8
0
def comment_on_level(level_id, user_id, comment_text):
    """
    This method will add a comment to a level and also list of users comments
    @param level_id: integer id of the level we are adding this comment
    @param user_id: ineteger id of the user who is adding this comment
    @param comment_text: the text of the comment
    """
    level = get_level_by_id(level_id)
    user = user_service.get_user_by_id(user_id)
    comment = CommentModel(user_id=user_id, level_id=level_id, text=comment_text)
    level.comments.append(comment)
    user.comments.append(comment)
    level.put()
    user.put()
Пример #9
0
def performance_recording(user_id, calendar_week=get_current_week_number()):
    user = get_user_by_id(user_id)

    working_hours = get_working_hour_for_user(user.id, calendar_week) or []
    projects = get_projects_for_user(user.id) or []

    projects_with_hours = list(map(lambda wh: wh.project_id, working_hours))

    for project in projects:
        if project.id not in projects_with_hours:
            working_hours.append(
                WorkingHour(user.id, project.id, calendar_week, project.name))

    return render_template("performance_recording.html",
                           company=config.company_name,
                           application=config.app_name,
                           user=user,
                           projects=projects,
                           working_hours=working_hours,
                           calendar_week=calendar_week,
                           weekdays=generate_array_of_weekdays_for_week())
Пример #10
0
def performance_record(user_id):
    user = get_user_by_id(user_id)
    calendar_week = request.values.get("calendar_week")

    work_per_days = []

    for day in [("monday", "Montag"), ("tuesday", "Dienstag"),
                ("wednesday", "Mittwoch"), ("thursday", "Donnerstag"),
                ("friday", "Freitag")]:

        for w in get_project_hours_per_day(user_id, calendar_week, day[0]):
            work_per_days.append({
                "day": day[1],
                "project": w["name"],
                "work": w[day[0]]
            })

    sum_work = 0
    for w in work_per_days:
        try:
            sum_work += int(w["work"])
        except ValueError:
            # for invalid time strings
            pass

    rendered_html = render_template("reports.performance_report.html",
                                    company=config.company_name,
                                    user_name=user.name,
                                    calendar_week=calendar_week,
                                    sum_work=sum_work,
                                    work=work_per_days)

    if request.values.get("as_pdf"):
        report_filename = save_report(rendered_html)
        return redirect(
            url_for("reports.report_file",
                    user_id=current_user.id,
                    file=report_filename))
    else:
        return rendered_html
Пример #11
0
    def __init__(self, request: Request):
        super().__init__(request)

        self.user = user_service.get_user_by_id(self.user_id)
Пример #12
0
 def get(self, user_id):
     """Returns a single user."""
     user = get_user_by_id(user_id)
     if not user:
         users_namespace.abort(404, f"User {user_id} does not exist")
     return user, 200
Пример #13
0
def load_user(user_id):
    return get_user_by_id(user_id)