Esempio n. 1
0
def group_tasks():
    """
    Method(s): POST

    Take a form with values being task ids.

    Group the selected tasks.
    """
    username = CASClient().authenticate()
    task_ids = []
    group_title = ""

    for value in request.form.values():
        try:
            task_id = int(value)
            task_ids.append(task_id)
        except ValueError:
            group_title = value

    try:
        create_new_group(task_ids, group_title, username)
    except:
        return json.dumps({"success": False}), 500
    else:
        return json.dumps({"success": True}), 200
Esempio n. 2
0
def uncomplete():
    """
    Method(s): POST

    Take request args of the following fields:
        task_id: int
        iteration: int

    Uncomplete a task iteration.
    """
    username = CASClient().authenticate()
    task_id = request.args["task_id"]
    iteration = request.args["iteration"]
    time = None

    try:
        uncomplete_task(int(task_id), int(iteration), username)

        update_completion_time(task_id, iteration, username, time)
        if int(iteration) > 1:
            update_timely_pred(task_id, iteration, username)
    except:
        return json.dumps({"success": False}), 500
    else:
        return json.dumps({"success": True}), 200
Esempio n. 3
0
def edit_class_details():
    """
    Method(s): POST

    Take a form of the following fields:
        title: str
        class_id: int
        dept: str
        num: int
        color: str

    Update the details of an existing task and/or task iteration.
    """
    username = CASClient().authenticate()
    class_details = {
        "title": None,
        "class_id": None,
        "dept": None,
        "num": None,
        "color": None,
        "active_status": None,
        "username": username
    }

    class_details["class_id"] = request.args["class_id"]
    for key, item in request.form.items():
        class_details[key] = item

    try:
        update_class_details(class_details)
    except:
        return json.dumps({"success": False}), 500
    else:
        return json.dumps({"success": True}), 200
Esempio n. 4
0
def create_class_form():
    """
    Method(s): POST

    Take a form of the following fields:
        title: str
        dept: str
        num: int
        color: str

    Create a new class.
    """
    username = CASClient().authenticate()

    class_details = {
        'title': None,
        'dept': None,
        'num': None,
        'color': None,
        'username': username
    }

    for key, item in request.form.items():
        class_details[key] = item

    try:
        class_handler(class_details)
    except NameError:  # An error such that the user reached the max limit of classes
        return json.dumps({"success": False}), 409  # Conflict
    except:
        return json.dumps({"success": False}), 500
    else:
        return json.dumps({"success": True}), 200
Esempio n. 5
0
def completion_form():
    """
    Method(s): POST

    Take request args of the following fields:
        task_id: int
        iteration: int

    Take a form of the following fields:
        time: float

    Complete a task iteration.
    """
    username = CASClient().authenticate()
    task_id = request.args["task_id"]
    iteration = request.args["iteration"]
    time = request.form["time"]

    try:
        mark_task_complete(int(task_id), int(iteration), username)
        update_completion_time(task_id, iteration, username, time)
        update_timely_pred(task_id, iteration, username)
    except:
        return json.dumps({"success": False}), 500
    else:
        return json.dumps({"success": True}), 200
def about():
    """Display about page."""
    try:
        CASClient().authenticate()
    except:
        return render_template("views/about.html", public=True)
    else:
        return render_template("views/about.html", public=False)
def feedback():
    """Display the feedback page."""
    try:
        CASClient().authenticate()
    except:
        return render_template("views/feedback.html", public=True)
    else:
        return render_template("views/feedback.html", public=False)
def landing():
    """Return the landing page."""
    # Redirects to list if user is logged in
    try:
        CASClient().authenticate()
    except:
        return render_template("views/landing.html")
    else:
        return redirect("/list")
def calendar():
    """Return the calendar page."""
    username = CASClient().authenticate()
    classes = fetch_class_list(username)
    tasks = fetch_task_calendar_view(username)
    week_dates = fetch_curr_week()
    return render_template("views/calendar.html",
                           class_list=classes,
                           task_list=tasks,
                           week_dates=week_dates)
Esempio n. 10
0
def get_classes():
    """
    Method(s): GET

    Return JSON of the current user's classes.
    """
    try:
        classes = fetch_class_list(CASClient().authenticate())
    except:
        return json.dumps({"success": False}), 500
    return json.dumps(classes, default=str)
Esempio n. 11
0
def next_week():
    """Return the next week of the calendar page."""
    username = CASClient().authenticate()
    classes = fetch_class_list(username)
    tasks = fetch_task_calendar_view(username)
    week_dates = request.args["week-dates"]
    next_week_dates = fetch_week(week_dates, False)
    return render_template("views/calendar.html",
                           class_list=classes,
                           task_list=tasks,
                           week_dates=next_week_dates)
Esempio n. 12
0
def prev_week():
    """Return the previous week of the calendar page."""
    username = CASClient().authenticate()
    classes = fetch_class_list(username)
    tasks = fetch_task_calendar_view(username)
    week_dates = request.args["week-dates"]
    # week_dates = eval(week_dates)
    prev_week_dates = fetch_week(week_dates, True)
    return render_template("views/calendar.html",
                           class_list=classes,
                           task_list=tasks,
                           week_dates=prev_week_dates)
Esempio n. 13
0
def edit_task_details():
    """
    Method(s): POST

    Take a form of the following fields:
        task_id: int
        class_id: int
        iteration: int
        iteration_title: str
        priority: int
        link: str
        due_date: Date
        est_time: float
        notes: str
        repeat_freq: str
        repeat_end: Date

    Update the details of an existing task and/or task iteration.
    """
    username = CASClient().authenticate()
    # TODO: Potentially change class_id to class
    task_details = {
        "task_id": None,
        "class_id": None,
        "iteration": None,
        "priority": None,
        "link": None,
        "due_date": None,
        "notes": None,
        "est_time": None,
        "repeat_freq": None,
        "repeat_end": None,
        "username": username,
        "iteration_title": None
    }

    for key, item in request.form.items():
        task_details[key] = item

    if task_details["repeat_end"] == "":
        task_details["repeat_end"] = None

    task_details["task_id"] = int(request.args["task_id"])
    task_details["iteration"] = int(request.args["iteration"])

    print(task_details)

    try:
        update_task_details(task_details)
    except:
        return json.dumps({"success": False}), 500
    else:
        return json.dumps({"success": True}), 200
Esempio n. 14
0
def get_canvas_tasks():
    """
    Method(s): GET

    Return JSON of the current user's canvas tasks.
    """
    try:
        tasks = fetch_canvas_tasks(fetch_current_semester(),
                                   CASClient().authenticate())
    except:
        return json.dumps({"success": False}), 500
    return json.dumps(tasks, default=str)
Esempio n. 15
0
def canvas_class():
    """
    Method(s): POST

    Import classes from Canvas.
    """
    username = CASClient().authenticate()
    try:
        fetch_canvas_courses(fetch_current_semester(), username)
    except:
        return json.dumps({"success": False}), 500
    else:
        return json.dumps({"success": True}), 200
Esempio n. 16
0
def list_view():
    """Return the index page."""
    username = CASClient().authenticate()
    if "sort" in request.args:
        sort = request.args['sort']
    else:
        sort = "due_date"

    classes = fetch_class_list(username)
    tasks = fetch_task_list_view(username, sort)
    user = fetch_user(username)
    colors = fetch_available_colors(username)
    return render_template("views/list.html",
                           class_list=classes,
                           task_list=tasks,
                           user_info=user,
                           colors=colors)
Esempio n. 17
0
def class_details_json():
    """
    Method(s): GET

    Take request args of the following fields:
        class_id: int

    Return JSON of the given class's details.
    """
    username = CASClient().authenticate()
    class_details = fetch_class_details(request.args["class_id"], username)

    # If task_details is None (which will occur if user manually inputs task_id they do not have
    # access to) then raise a 403 error
    if class_details is None:
        return json.dumps({"success": False}), 403

    return json.dumps(class_details, default=str)
Esempio n. 18
0
def create_task_form():
    """
    Method(s): POST

    Take a form of the following fields:
        iteration_title: str
        class_id: int
        priority: int
        est_time: float
        link: str
        notes: str
        due_date: Date
        repeat_freq: str
        repeat_end: Date

    Create a new task.
    """
    username = CASClient().authenticate()
    details = {
        'iteration_title': None,
        'class_id': None,
        'priority': None,
        'est_time': None,
        'link': None,
        'notes': None,
        'due_date': None,
        'repeat_freq': None,
        'repeat_end': None,
        'username': username
    }

    for key, item in request.form.items():
        details[key] = item

    details['group_title'] = details['iteration_title']

    try:
        task_handler(details)
    except:
        return json.dumps({"success": False}), 500
    else:
        return json.dumps({"success": True}), 200
Esempio n. 19
0
def get_graph_data():
    """
    Method(s): GET

    Take request args of the following fields:
        task_id: int
        iteration: int

    Return JSON of the given iteration's graph data.
    """
    username = CASClient().authenticate()
    task_id = request.args["task_id"]
    iteration = request.args["iteration"]
    # Contains labels, actual_times, and predicted_times
    try:
        times = fetch_graph_times(task_id, iteration, username)
    except:
        return json.dumps({"success": False}), 500

    return json.dumps(times, default=dict)  # dumps is for str formatting dict
Esempio n. 20
0
def canvas_task():
    """
    Method(s): POST

    Take a JSON list of tasks.

    Imports the given Canvas tasks.
    """
    username = CASClient().authenticate()
    task_list = []
    for value in request.form.values():
        # json.loads returns dictionary, first key is status (new or updated), second is task itself
        task_list.append(json.loads(value))

    try:
        insert_canvas_tasks(task_list, username)
    except:
        return json.dumps({"success": False}), 500
    else:
        return json.dumps({"success": True}), 200
Esempio n. 21
0
def canvas_key():
    """
    Method(s): POST

    Take a form of the following fields:
        api_key: str

    Set the Canvas key for the current user.
    """
    username = CASClient().authenticate()
    api_key = request.form["api_key"]

    if validate_api_key(api_key) is False:
        return json.dumps({"success": False}), 400

    try:
        insert_canvas_key(username, api_key)
    except:
        return json.dumps({"success": False}), 500
    else:
        return json.dumps({"success": True}), 200
Esempio n. 22
0
def task_details_endpoint():
    """
    Method(s): GET

    Take request args of the following fields:
        task_id: int
        iteration: int

    Return JSON of the given iteration's details.
    """
    username = CASClient().authenticate()
    task_id = request.args["task_id"]
    iteration = request.args["iteration"]
    task_details = fetch_task_details(task_id, iteration, username)

    # If task_details is None (which will occur if user manually inputs task_id they do not have
    # access to) then raise a 403 error
    if task_details is None:
        return json.dumps({"success": False}), 403

    return json.dumps(task_details, default=str)
Esempio n. 23
0
def get_tasks():
    """
    Method(s): GET

    Fetch all tasks associated with a given class and returns information in JSON format.
    If class is left as none, return all tasks for all classes.
    """
    username = CASClient().authenticate()
    class_id = request.args["class_id"]
    try:
        tasks = fetch_tasks_from_class(class_id, username)
    except:
        return json.dumps({"success": False}), 500

    # Set null due_dates to 'Group' to avoid showing null due dates on modal
    for task in tasks:
        if task["due_date"] is None:
            task["due_date"] = "Group"
        if task["title"] is None or task["title"] == "":
            task["title"] = task["iteration_title"]

    return json.dumps(tasks, default=str)
Esempio n. 24
0
def logout():
    """Log the user out of the application."""
    cas_client = CASClient()
    cas_client.authenticate()
    cas_client.logout()