<commit_before>from django.shortcuts import render, get_object_or_404
from django.core.exceptions import ObjectDoesNotExist
from django.db.models import Q
from django.http import JsonResponse
from stocks.models import *
from stocksApi.models import SessionId

def getDNEError():
    return JsonResponse({"error": "That object could not be found"})

def getAuthError():
    return JsonResponse({"error": "Your session id is old or never existed. You should get a new one"})

def getPermError():
    return JsonResponse({"error": "You don't have permission to see that"})

def getParamError():
    return JsonResponse({"error": "You gave the wrong parameters"})

def getUser(request):
    sessionId = request.GET.get("sessionId", None)
    if not sessionId:
        return None
    try:
        user = SessionId.objects.get(id_string=sessionId).associated_user
    except ObjectDoesNotExist:
        return None


def getObject(klass, pk):
    if pk == None:
        if klass == User:
            return [userJSON(u) for u in klass.objects.all()]<commit_msg>Improve error functions<commit_after>from django.shortcuts import render, get_object_or_404
from django.core.exceptions import ObjectDoesNotExist
from django.db.models import Q
from django.http import JsonResponse
from stocks.models import *
from stocksApi.models import SessionId

def getError(message):
    return JsonResponse({"error": message})


def getDNEError():
    return getError("That object could not be found")

def getAuthError():
    return getError("Your session id is old or never existed. You should get a new one")

def getPermError():
    return getError("You don't have permission to see that")

def getParamError(lacking = None):
    retval = getError("You gave the wrong parameters." + 
                      ("{} is/are missing".format(lacking)) if lacking else "")
    return JsonResponse({"error": "You gave the wrong parameters", "wrongParams": lacking})


def getUser(request):
    sessionId = request.GET.get("sessionId", None)
    if not sessionId:
        return None
    try:
        user = SessionId.objects.get(id_string=sessionId).associated_user
    except ObjectDoesNotExist:
        return None


def getObject(klass, pk):
    if pk == None:
        if klass == User:
            return [userJSON(u) for u in klass.objects.all()]
{'fraction_non_alphanumeric': 0.09599655617735686, 'fraction_numerical': 0.002582866982350409, 'mean_word_length': 3.8115942028985508, 'pattern_counts': {'":': 7, '<': 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': '2624982', 'n_tokens_mistral': 664, 'n_tokens_neox': 648, 'n_words': 225}