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

from django.db import DatabaseError

from django.forms.models import model_to_dict

# Use Regular Expression
import re

# Used when http-POST
from django.views.decorators.csrf import csrf_exempt

# Models
from .models import Person
from .models import Activity

# Create your views here.


def show_api(request):
	"""
	Show api list
	:param request: httpRequest
	:return: app/api.html
	"""
	return render(request, 'app/api.html')


def get_person_list(request):
	"""
	Get person list in MySQL databases
	:param request: httpRequest
	:return: person list(json) 
	"""
	if request.method == 'GET':

		# if has filter
		if 'filter' in request.GET:
			data = Person.objects.all().extra(
				where = parse_multi_filters(request.GET['filter'])
			)
			content = serializers.serialize("json", data)
			return HttpResponse(content, content_type = 'application/json')

		# if requires all
		else:
			data = Person.objects.all()
			content = serializers.serialize("json", data)
			return HttpResponse(content, content_type = 'application/json')


@csrf_exempt
def add_person(request):
	"""<commit_msg>alter details of api - get_person_list<commit_after>from django.shortcuts import render
from django.http import HttpResponse
from django.http import JsonResponse
from django.core import serializers

from django.db import DatabaseError

from django.forms.models import model_to_dict

# Use Regular Expression
import re

# Used when http-POST
from django.views.decorators.csrf import csrf_exempt

# Models
from .models import Person
from .models import Activity

# Create your views here.


def show_api(request):
	"""
	Show api list
	:param request: httpRequest
	:return: app/api.html
	"""
	return render(request, 'app/api.html')


def get_person_list(request):
	"""
	Get person list in MySQL databases
	:param request: httpRequest
	:return: person list(json) 
	"""
	if request.method == 'GET':

		data = Person.objects.all()

		if 'name' in request.GET.keys():
			data = data.filter(name = request.GET['name'])

		if 'gender' in request.GET.keys():
			data = data.filter(gender = request.GET['gender'])

		if 'native_province' in request.GET.keys():
			data = data.filter(native_province = request.GET['native_province'])

		if 'dormitory' in request.GET.keys():
			data = data.filter(dormitory = request.GET['dormitory'])

		if 'birthday' in request.GET.keys():
			data = data.filter(birthday = request.GET['birthday'])

		if 'participation' in request.GET.keys():
			data = data.filter(participation = request.GET['participation'])

		content = serializers.serialize('json', data)
		return HttpResponse(content, content_type = 'application/json')


@csrf_exempt
def add_person(request):
	"""
{'fraction_non_alphanumeric': 0.11247803163444639, 'fraction_numerical': 0.0, 'mean_word_length': 4.646825396825397, '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': '3770022', 'n_tokens_mistral': 935, 'n_tokens_neox': 862, 'n_words': 250}