import json
from django.db.models import Count
from django.shortcuts import render

from cve_parser.models import CVEEntry


def cve_view(request):
    cves_count = list(CVEEntry.objects.all().extra({'date': "date(last_modified_time)"}).values('date').annotate(
        count=Count('id')).order_by('date'))
    cves_count_json = [dict([a, str(x)] for a, x in b.iteritems()) for b in cves_count]
    return render(request, "cve_list.html", {'group_CVEs': cves_count_json, "cves_count": cves_count})
