Пример #1
0
def handle_new_tag_creation(new_tag_str: str):
    """
    Handles the user clicking Ok to submit a new tag.

    Return value of this sets the text on the Ok button.
    """
    log.debug("User %s creating new tag: %s", current_user_email(),
              new_tag_str)

    if not new_tag_str:
        # If the user didn't enter anything, do nothing.
        return "Ok"

    if new_tag_str in [tag.name for tag in list_all_tags()]:
        return "Tag Exists"

    if Tag.normalise_tag(new_tag_str) == new_tag_str:
        # Tag is acceptable, enter it into the database.
        new_tag = Tag(new_tag_str)
        new_tag.add()
        return "Ok"

    # If it's unacceptable, then the other callback will have changed the input
    # field to be an acceptable value.
    return "Normalised to {0!r}, click again to accept.".format(
        Tag.normalise_tag(new_tag_str))
Пример #2
0
def set_mentor_tags(tags: List[str]):
    """
    Callback that gets called when a tag is added or deleted

    :param tags: List of tags, comma separated.
    """
    log.info("User %s set mentor tags: %s", current_user_email(), tags)
    get_current_user().set_tags(tags)
Пример #3
0
def submit_mentee_information(categories: List[str], details: str):
    print("mentee request", categories, details)

    if session.is_logged_in():
        database.models.create_request(session.current_user_email(),
                                       categories, details)
    else:
        session.store_signup_information("",
                                         request_categories=categories,
                                         request_details=details)
        session.set_post_login_redirect(href(__name__, submit_request))
Пример #4
0
def handle_save_and_delete(
    request_id: str, tags: List[str], details: str, n_save_clicked, n_delete_clicked
):
    """Handles the user clicking save or delete on the request editing page."""
    log.debug(
        "Handling request update or deletion: %s, %s", n_save_clicked, n_delete_clicked
    )
    current_request = get_request_by_id(request_id)
    if current_request is None:
        raise RuntimeError(
            "Unrecognised request ID passed to editing page: %s" % request_id
        )
    if n_save_clicked:
        current_request.tags = tags
        current_request.comment = details
        current_request.commit()
        log.info("User %s updated request: %s", current_user_email(), current_request)
    elif n_delete_clicked:
        log.info("User %s deleted request: %s", current_user_email(), current_request)
        current_request.delete()
Пример #5
0
def set_mentor_tags(bio: str):
    """
    Callback that gets called when a tag is added or deleted

    :param bio: Biography of the users.
    """
    log.info("User %s set bio: %s", current_user_email(), bio)
    user = get_current_user()
    user.bio = bio
    user.commit()

    return "Saved!"
Пример #6
0
def children_matches(completed_matches: List[Request]) -> List:
    table_rows = [
        html.Tr(
            [
                html.Td("Partner"),
                html.Td("Request tags"),
                html.Td("Request description"),
            ],
            className="table-active",
        )
    ]

    for match in completed_matches:
        if match.maker == current_user_email():
            # Current user is the mentee
            other_user = get_user(match.mentor)
            name = other_user.name if other_user else "unknown"
            partner_name = "{} (mentor)".format(name)
        else:
            # Current user is the mentor
            other_user = get_user(match.maker)
            name = other_user.name if other_user else "unknown"
            partner_name = "{} (mentee)".format(name)

        table_rows.append(
            html.Tr(
                [
                    html.Td(partner_name),
                    html.Td(", ".join(match.tags)),
                    html.Td(match.comment),
                ],
                className="table-light",
            ))
    return [
        html.H1("{}, here are your completed matches".format(
            get_current_user().name)),
        html.Table([*table_rows], className="table table-condensed"),
    ]
Пример #7
0
def children_no_matches():
    return [
        html.H1("{}, you have no completed matches! :(".format(
            current_user_email()))
    ]