<commit_before>from django.shortcuts import render
from django.http import JsonResponse, HttpResponse

# Create your views here.

def location(request):
    response_data = {}
    response_data['test'] = 'test_str'
    return JsonResponse(response_data)

def index(request):
    return HttpResponse()


def get_all_locations(request):
    return None<commit_msg>Better location handling, ID handling<commit_after>from django.shortcuts import render, get_object_or_404
from django.http import JsonResponse, HttpResponse, HttpResponseBadRequest
from .models import Location, Category, DetectedLocation
from django.core import serializers
from django.forms.models import model_to_dict
import json
from django.contrib.gis.geos import Point
from django.views.decorators.csrf import csrf_exempt
# Create your views here.

@csrf_exempt
def location(request, **kwargs):
    if request.method != 'GET':
	return HttpResponseBadRequest("Only get Request allowed")
    if kwargs['id']:
	#get only a single location
	objects = [get_object_or_404(Location, pk=kwargs['id'])]
    else:
	query_params = ['latitude','longitude','distance','count']
	if any([param in request.GET for param in query_params]):
	    print 'found param'
	    objects = []
	else:
	    objects = Location.objects.all()
    #data = serializers.serialize('geojson', all_objects)['features']
    data = []
    for obj in objects:
	tmp_dict = obj.__dict__
	tmp_dict['latitude'] = tmp_dict['loc'].coords[0]
	tmp_dict['longitude'] = tmp_dict['loc'].coords[1]
	del tmp_dict['loc']
	del tmp_dict['_state']
	tmp_dict['category'] = Category.objects.get(pk=tmp_dict['category_id']).name
	del tmp_dict['category_id']
	data.append(tmp_dict)
    data = json.dumps(data)
    return HttpResponse(data, content_type = 'application/json')

def index(request):
    return HttpResponse()


def get_all_locations(request):
    return None
{'fraction_non_alphanumeric': 0.11247334754797442, 'fraction_numerical': 0.0042643923240938165, 'mean_word_length': 5.36271186440678, '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': '5174350', 'n_tokens_mistral': 583, 'n_tokens_neox': 569, 'n_words': 147}