<commit_before>import json

from django.http import HttpResponse
from django.views.generic import TemplateView, View

from map.models import CityBorder
from map.utils import generateGeoJson


class MapView(TemplateView):
    template_name = 'map.html'


class FetchGridView(View):

    def get(self, request, *args, **kwargs):
        pk = self.request.GET.get('pk')
        size = int(self.request.GET.get('size'))
        city = CityBorder.objects.get(pk=pk)
        grid = city.generateGrid(size)
        geojson = generateGeoJson(grid)
        return HttpResponse(json.dumps(geojson))<commit_msg>updated view to fetch grid from db<commit_after>import json

from django.http import HttpResponse
from django.views.generic import TemplateView, View

from map.models import CityBorder
from map.utils import generateGeoJson


class MapView(TemplateView):
    template_name = 'map.html'


class FetchGridView(View):

    def get(self, request, *args, **kwargs):
        pk = self.request.GET.get('pk')
        size = int(self.request.GET.get('size'))
        city = CityBorder.objects.get(pk=pk)
        grid = city.grids.filter(size=size).values_list('geom', flat=True)
        geojson = generateGeoJson(list(grid))
        return HttpResponse(json.dumps(geojson))
{'fraction_non_alphanumeric': 0.110055423594616, 'fraction_numerical': 0.0, 'mean_word_length': 3.8244274809160306, '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': '1618802', 'n_tokens_mistral': 388, 'n_tokens_neox': 375, 'n_words': 90}