<commit_before>from django.http import HttpResponse
import json

from students.models import Student

STATUS_OK = {
  'success' : 'API is running'
}

# status view
def status(request):  

  return HttpResponse(
    json.dumps(STATUS_OK),
    content_type = 'application/json'
  )

# students api implementing GET, POST, PUT & DELETE for Student model
def students(request):

  if request.method == 'GET':

    response = []
    students = Student.objects.all()
    for student in students:
      print student
      obj = {}
      obj.update({ 'id': student.id })
      obj.update({ 'name': student.name })
      response.append(obj)

    return HttpResponse(
      json.dumps(response),
      content_type = 'application/json'
    )<commit_msg>added POST and DELETE operations<commit_after>from django.http import HttpResponse
import json

from students.models import Student

STATUS_OK = {
  'success' : 'API is running'
}

# status view
def status(request):  

  return HttpResponse(
    json.dumps(STATUS_OK),
    content_type = 'application/json'
  )

# students api implementing GET, POST, PUT & DELETE for Student model
def students(request,id=0):

  if request.method == 'GET':

    response = []
    students = Student.objects.all()
    for student in students:
      print student
      obj = {}
      obj.update({ 'id': student.id })
      obj.update({ 'name': student.name })
      response.append(obj)

    return HttpResponse(
    json.dumps(response),
    content_type = 'application/json')

  elif request.method == 'POST':
    studentName = request.POST['name']
    newStudent = Student(name = studentName)
    newStudent.save()
    addedStudent = {'id' : newStudent.id , 'name' : newStudent.name}

    
    return HttpResponse(
      json.dumps(addedStudent),
      content_type='application/json')

  elif request.method == 'DELETE':
    Student.objects.get(id=id).delete()
    message={ 'success' : 'True' }
    return HttpResponse(
      json.dumps(message),
      content_type='application/json')

    
{'fraction_non_alphanumeric': 0.1190711462450593, 'fraction_numerical': 0.0004940711462450593, 'mean_word_length': 3.1752577319587627, 'pattern_counts': {'":': 0, '<': 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': '216468', 'n_tokens_mistral': 610, 'n_tokens_neox': 597, 'n_words': 155}