<commit_before>import os
import json
from django.shortcuts import render
from django.conf import settings
from grapher_admin.models import Chart, Variable, License, DataValue, Entity
from django.http import HttpResponse, HttpResponseNotFound
from django.contrib.auth.decorators import login_required


@login_required
def chart(request, chartid):

    manifest = json.loads(open(os.path.join(settings.BASE_DIR, "public/build/manifest.json")).read())
    jspath = "/build/%s" % (manifest['charts.js'])
    csspath = "/build/%s" % (manifest['charts.css'])

    # for now, only looking up the chart by its id, not slug
    chartmeta = {}

    configpath = "%s/config/%s.js" % (settings.BASE_URL, chartid)

    return render(request, 'grapher/base_chart_template.html', context={'slug': chartid,
                                                                        'meta': chartmeta, 'configpath': configpath,
                                                                        'jspath': jspath, 'csspath': csspath})


@login_required
def configfile(request, configid):

    if '.js' not in configid:
        return HttpResponseNotFound
    else:
        chartid = int(configid[:configid.find('.js')])
        chartobj = Chart.objects.get(pk=chartid)

        configdict = json.loads(chartobj.config)
        configdict['title'] = chartobj.name
        configdict['chart-type'] = chartobj.type
        configdict['internalNotes'] = chartobj.notes
        configdict['slug'] = chartobj.slug
        configdict['data-entry-url'] = chartobj.origin_url
        configdict['published'] = chartobj.published

        config = 'App.loadChart(' + json.dumps(configdict) + ')'

        return HttpResponse(config, content_type="text/plain")


@login_required
def variables(request, ids):
    varids = []
    meta = {}
    entitykey = {}
    meta['variables'] = {}
    meta['license'] = License.objects.values().first()
    meta['license']['created_at'] = str(meta['license']['created_at'])
    meta['license']['updated_at'] = str(meta['license']['updated_at'])
    large_string = ''
    for each in ids.split('+'):
        varids.append(int(each))

    varids = sorted(varids)

    for each in varids:
        varobj = Variable.objects.select_related('sourceid__datasetid__fk_dst_cat_id').get(pk=each)
        source = {}
        source['name'] = varobj.sourceid.name
        source['description'] = varobj.sourceid.description

        var = {}
        var['id'] = varobj.pk<commit_msg>Fixed content type for config file<commit_after>import os
import json
from django.shortcuts import render
from django.conf import settings
from grapher_admin.models import Chart, Variable, License, DataValue, Entity
from django.http import HttpResponse, HttpResponseNotFound
from django.contrib.auth.decorators import login_required


@login_required
def chart(request, chartid):

    manifest = json.loads(open(os.path.join(settings.BASE_DIR, "public/build/manifest.json")).read())
    jspath = "/build/%s" % (manifest['charts.js'])
    csspath = "/build/%s" % (manifest['charts.css'])

    # for now, only looking up the chart by its id, not slug
    chartmeta = {}

    configpath = "%s/config/%s.js" % (settings.BASE_URL, chartid)

    return render(request, 'grapher/base_chart_template.html', context={'slug': chartid,
                                                                        'meta': chartmeta, 'configpath': configpath,
                                                                        'jspath': jspath, 'csspath': csspath})


@login_required
def configfile(request, configid):

    if '.js' not in configid:
        return HttpResponseNotFound
    else:
        chartid = int(configid[:configid.find('.js')])
        chartobj = Chart.objects.get(pk=chartid)

        configdict = json.loads(chartobj.config)
        configdict['title'] = chartobj.name
        configdict['chart-type'] = chartobj.type
        configdict['internalNotes'] = chartobj.notes
        configdict['slug'] = chartobj.slug
        configdict['data-entry-url'] = chartobj.origin_url
        configdict['published'] = chartobj.published

        config = 'App.loadChart(' + json.dumps(configdict) + ')'

        return HttpResponse(config, content_type="application/javascript")


@login_required
def variables(request, ids):
    varids = []
    meta = {}
    entitykey = {}
    meta['variables'] = {}
    meta['license'] = License.objects.values().first()
    meta['license']['created_at'] = str(meta['license']['created_at'])
    meta['license']['updated_at'] = str(meta['license']['updated_at'])
    large_string = ''
    for each in ids.split('+'):
        varids.append(int(each))

    varids = sorted(varids)

    for each in varids:
        varobj = Variable.objects.select_related('sourceid__datasetid__fk_dst_cat_id').get(pk=each)
        source = {}
        source['name'] = varobj.sourceid.name
        source['description'] = varobj.sourceid.description

        var = {}
        var['id'] = varobj.pk
{'fraction_non_alphanumeric': 0.13453453453453454, 'fraction_numerical': 0.0, 'mean_word_length': 2.8849144634525663, '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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6053016', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1403, 'n_words': 292}