<commit_before>from agcal.models import User


def show_user(username):
    usernames = User.objects.filter(username=username)

    if not usernames.count():
        response = '{"message": "No such user"}'
        status = 404
    else:
        user = usernames.first()
        response = '{"username": "%s", "name": "%s", "email": "%s"}' % (
            user.username, user.name, user.email)
        status = 200

    return (response, status)


def check_username_email(username, email):
    response = '{"message": "ok"}'
    status = 200

    if User.objects.filter(username=username).count():
        response = '{"message": "Username Exists"}'
        status = 409

    if User.objects.filter(email=email).count():
        response = '{"message": "Email Exists"}'

    return (response, status)


def add_user(username, password, name, email):
    user = User(username, password, name, email)

    user_status = UserManager.check_username_email(username, email)
    if user_status[1] == 409:
        return user_status

    user.save()
    response = '{"message": "ok"}'
    status = 200

    return (response, status)


def remove_user(username):
    try:
        user = User.objects.get(username=username)
    except Exception:
        response = '{"message": "No such user"}'
        status = 404
    else:
        user.delete()
        response = '{"message": "ok"}'
        status = 200

    return (response, status)


def update_user(username, password, name, email):
    try:
        user = User.objects.get(username=username)<commit_msg>Rahul | Refactored User manager<commit_after>from agcal.models import User


def show_user(username):
    try:
        user = User.objects.get(username=username)
    except Exception:
        response = '{"message": "No such user"}'
        status = 404
    else:
        response = '{"username": "%s", "name": "%s", "email": "%s"}' % (user.username, user.name, user.email)
        status = 200

    return (response, status)


def check_username_email(username, email):
    response = '{"message": "ok"}'
    status = 200

    if User.objects.filter(username=username).exists():
        response = '{"message": "Username Exists"}'
        status = 409

    if User.objects.filter(email=email).exists():
        response = '{"message": "Email Exists"}'

    return (response, status)


def add_user(username, password, name, email):
    user = User(username, password, name, email)

    user_status = check_username_email(username, email)
    if user_status[1] == 409:
        return user_status

    user.save()
    response = '{"message": "ok"}'
    status = 200

    return (response, status)


def remove_user(username):
    try:
        user = User.objects.get(username=username)
    except Exception:
        response = '{"message": "No such user"}'
        status = 404
    else:
        user.delete()
        response = '{"message": "ok"}'
        status = 200

    return (response, status)


def update_user(username, password, name, email):
    try:
        user = User.objects.get(username=username)
{'fraction_non_alphanumeric': 0.1409921671018277, 'fraction_numerical': 0.016318537859007835, 'mean_word_length': 2.8360450563204007, 'pattern_counts': {'":': 20, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4710957', 'n_tokens_mistral': 969, 'n_tokens_neox': 895, 'n_words': 240}