<commit_before>import datetime
import json

from django.http import JsonResponse
from django.contrib.auth import hashers
from django import db

from stuff import models
from django.http import HttpResponse
from django.shortcuts import get_object_or_404


#Tested
def create_user(request):
    if request.method != 'POST':
        #return HttpResponse("must make POST", status=400)
        return _error_response(request, "must make POST request")
    if 'usertype' not in request.POST:
        return _error_response(request, "Usertype is not found")

    if 'password' not in request.POST or 'username' not in request.POST:
        return _error_response(request, "missing fields for Basic User")
    if request.POST['usertype'] == 'buyer' and 'resume_url' not in request.POST:
        return _error_response(request, "missing fields for Buyer")
    if request.POST['usertype'] == 'seller' and 'company_name' not in request.POST:
        return _error_response(request, "missing fields for Seller")

    ##create_user
    u = models.User(username=request.POST['username'],
                    password=<PASSWORD>(request.POST['password']),
                    usertype=request.POST['usertype'])
    try:
        u.save()
    except db.Error:
        return _error_response(request, "can't store User. db error")



    ##create seller
    if(request.POST['usertype'] == 'seller'):
        s = models.Seller(company=models.Company.objects.get(name=request.POST['company_name']), user_account=u)
        try:
             s.save()
        except db.Error:
            return _error_response(request, "can't store Seller. db error")
            #return HttpResponse("can't write into DB",status=500)
        return _success_response(request, {'seller_id': s.pk})




    ##create buyer
    if(request.POST['usertype'] == 'buyer'):
        b = models.Buyer(resume_url=request.POST['resume_url'], user_account=u)
        try:
            b.save()
        except db.Error:
            return _error_response(request, "can't store Seller. db error")
        return _success_response(request, {'buyer_id': b.pk})






def lookup_user(request, user_id):
    if  request.method !='GET':
        return _error_response(request, "must make GET request")
    try:
        u = models.User.objects.get(pk=user_id)
    except models.User.DoesNotExist:
        return _error_response(request, "user not found")
    if(u.usertype=='seller'):
        #s = models.Seller.objects.get(user_account=u)
        s = get_object_or_404(Seller, user_account=u)
        return _success_response(request, {'username': u.username,
                                            'usertype': u.usertype,<commit_msg>fixing APIs<commit_after>import datetime
import json

from django.http import JsonResponse
from django.contrib.auth import hashers
from django import db

from stuff import models
from django.http import HttpResponse
from django.shortcuts import get_object_or_404


#Tested
def create_user(request):
    if request.method != 'POST':
        #return HttpResponse("must make POST", status=400)
        return _error_response(request, "must make POST request")
    if 'usertype' not in request.POST:
        return _error_response(request, "Usertype is not found")

    if 'password' not in request.POST or 'username' not in request.POST:
        return _error_response(request, "missing fields for Basic User")
    if request.POST['usertype'] == 'buyer' and 'resume_url' not in request.POST:
        return _error_response(request, "missing fields for Buyer")
    if request.POST['usertype'] == 'seller' and 'company_name' not in request.POST:
        return _error_response(request, "missing fields for Seller")

    ##create_user
    u = models.User(username=request.POST['username'],
                    password=<PASSWORD>.make_password(request.POST['password']),
                    usertype=request.POST['usertype'])
    try:
        u.save()
    except db.Error:
        return _error_response(request, "can't store User. db error")



    ##create seller
    if(request.POST['usertype'] == 'seller'):
        s = models.Seller(company=models.Company.objects.get(name=request.POST['company_name']), user_account=u)
        try:
             s.save()
        except db.Error:
            return _error_response(request, "can't store Seller. db error")
            #return HttpResponse("can't write into DB",status=500)
        return _success_response(request, {'seller_id': s.pk})




    ##create buyer
    if(request.POST['usertype'] == 'buyer'):
        b = models.Buyer(resume_url=request.POST['resume_url'], user_account=u)
        try:
            b.save()
        except db.Error:
            return _error_response(request, "can't store Seller. db error")
        return _success_response(request, {'buyer_id': b.pk})






def lookup_user(request, user_id):
    if  request.method !='GET':
        return _error_response(request, "must make GET request")
    try:
        u = models.User.objects.get(pk=user_id)
    except models.User.DoesNotExist:
        return _error_response(request, "user not found")
    if(u.usertype=='seller'):
        #s = models.Seller.objects.get(user_account=u)
        s = get_object_or_404(models.Seller, user_account=u)
        return _success_response(request, {'username': u.username,
                                            'usertype': u.usertype,
{'fraction_non_alphanumeric': 0.11373350678312581, 'fraction_numerical': 0.004460137520906894, 'mean_word_length': 3.0164179104477613, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2827018', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1546, 'n_words': 400}