Exemplo n.º 1
0
def set_due_date(lab, row: ui.layers.Row):
    """Set a cutoff date for a lab

    When grading the submission before the cutoff date will be shown, but the
    in-grader submission picker allows to pick submissions after the cutoff date
    if needed
    """
    window = ui.get_window()

    labs = data.get_labs()

    old_date = lab.options.get("due", None)
    date_spinner = ui.layers.DatetimeSpinner("Due Date")
    date_spinner.set_optional(True)
    if old_date:
        date_spinner.set_initial_time(old_date)
    window.run_layer(date_spinner)
    if date_spinner.canceled:
        return

    due_date = date_spinner.get_time()

    # Clearing the due date
    if due_date == ui.components.DatetimeSpinner.NO_DATE:
        if "due" in lab.options:
            del lab.options["due"]
    else:
        # Remove time zone information
        lab.options["due"] = due_date.astimezone(tz=None)

    data.write_labs(labs)
    set_date_text(lab, row)
Exemplo n.º 2
0
def toggle_lab_option(lab, option):
    """Toggle a boolean lab option (T/F value)"""
    if option in lab.options:
        del lab.options[option]
    else:
        lab.options[option] = ""

    labs = data.get_labs()
    data.write_labs(labs)
Exemplo n.º 3
0
def rename_lab(lab_list: ui.layers.ListLayer, lab):
    """Rename a lab"""
    window = ui.get_window()
    labs = data.get_labs()

    text_input = ui.layers.TextInputLayer("Rename Lab")
    text_input.set_prompt(["Enter Lab's new name"])
    text_input.set_text(lab.name)
    window.run_layer(text_input)
    if not text_input.canceled:
        lab.name = text_input.get_text()
        data.write_labs(labs)
        fill_lab_list(lab_list, labs)
Exemplo n.º 4
0
def move_lab(lab_list: ui.layers.ListLayer, lab, step):
    """Move a lab up or down the list of labs"""
    labs = data.get_labs()
    index = labs.index(lab)

    # Prevent moving out of bounds
    if index + step > len(labs) - 1 or index + step < 0:
        return

    labs[index] = labs[index + step]
    labs[index + step] = lab

    data.write_labs(labs)
    lab_list.component._selected_index += step
    fill_lab_list(lab_list, labs)
Exemplo n.º 5
0
def remove_fn(lab_list, window, lab) -> bool:
    """Remove a lab from the list"""
    msg = [f"Are you sure you want to remove {lab.name}?"]
    popup = ui.layers.BoolPopup("Confirm", msg)
    window.run_layer(popup)
    remove = popup.get_result()

    if remove:
        labs = data.get_labs()
        labs.remove(lab)
        data.write_labs(labs)

    labs = data.get_labs()
    fill_lab_list(lab_list, labs)
    events = ui.get_events()
    events.push_layer_close_event()
    return remove
Exemplo n.º 6
0
def add_lab():
    """Add a lab to the current class"""
    window = ui.get_window()
    zy_api = Zybooks()

    text_input = ui.layers.TextInputLayer("Lab Name")
    text_input.set_prompt(["Enter the Lab Name"])
    window.run_layer(text_input)
    if text_input.canceled:
        return

    lab_name = text_input.get_text()

    # Get lab part(s)
    parts = []

    section_selector = ZybookSectionSelector(allow_optional_and_hidden=True)
    section_numbers = section_selector.select_zybook_sections(
        return_just_numbers=True)

    for chapter, section in section_numbers:
        part = {}
        response = zy_api.get_zybook_section(chapter, section)
        if not response.success:
            popup = ui.layers.Popup("Error", ["Invalid URL"])
            window.run_layer(popup)
        part["name"] = response.name
        part["id"] = response.id
        parts.append(part)

    new_lab = data.model.Lab(lab_name, parts, {})

    edit_lab_options(new_lab)

    all_labs = data.get_labs()
    all_labs.append(new_lab)

    data.write_labs(all_labs)