<commit_before># -*- coding: utf-8 -*-
from django.conf import settings
from django.core.context_processors import csrf
from django.shortcuts import render_to_response
from geography.utils import JsonResponse, StaticFiles
from django.db.models.loading import get_model
from django.core import serializers
from django.http import HttpResponse
from geography.models import Place
import json
import os
from django.core.servers.basehttp import FileWrapper


def home(request):
    JS_FILES = (
        "static/lib/js/fallbacks.js",
        "static/lib/js/jquery-1.11.0.min.js",
        "static/lib/js/bootstrap.js",
        "static/lib/angular-1.2.9/angular.min.js",
        "static/lib/angular-1.2.9/angular-route.min.js",
        "static/lib/angular-1.2.9/angular-cookies.min.js",
        "static/lib/js/raphael.js",
        "static/lib/raphael-pan-zoom/raphael.pan-zoom.min.js",
        "static/lib/js/kartograph.js",
        "static/lib/js/chroma.min.js",
        "static/lib/js/jquery.qtip.min.js",
        "static/lib/js/angulartics.min.js",
        "static/lib/js/angulartics-google-analytics.min.js",
        "static/js/map.js",
        "static/js/app.js",
        "static/js/controllers.js",
        "static/js/services.js",
        "static/js/filters.js",
        "static/js/directives.js"
    )
    TOP_CSS_FILES = (
        "static/lib/css/bootstrap.css",
        "static/css/app.css",
    )
    BOTTOM_CSS_FILES = (
        "static/lib/css/flags.css",
        "static/lib/css/tips.css",
        "static/css/map.css"
    )
    request.META["CSRF_COOKIE_USED"] = True
    title = 'Loc - ' if not settings.ON_OPENSHIFT else ''
    c = {
        'title': title,
        'isProduction': settings.ON_OPENSHIFT,
        'top_css_files': StaticFiles.add_hash(TOP_CSS_FILES),
        'bottom_css_files': StaticFiles.add_hash(BOTTOM_CSS_FILES),
        'js_files': StaticFiles.add_hash(JS_FILES),
        'continents': Place.objects.get_continents(),
        'states': Place.objects.get_states_with_map(),
        'hashes': json.dumps(settings.HASHES),
    }
    c.update(csrf(request))
    return render_to_response('home/home.html', c)


def csv_view(request, model):
    if not request.user.is_staff:
        response = {
            "error": "Permission denied: you need to be staff member. If you think you should be able to access logs, contact admins."}
        return JsonResponse(response)
    allowed_models = [
        'place',
        'placerelation',
        'answer',
        'answer_options']
    if model not in allowed_models:
        response = {"error": "the requested model '" + model + "' is not valid"}
        return JsonResponse(response)
    csv_file = "geography." + model + ".zip"
    logpath = os.path.join(settings.MEDIA_ROOT, csv_file)
    response = HttpResponse(FileWrapper(open(logpath)), content_type='application/zip')
    response['Content-Disposition'] = 'attachment; filename=' + csv_file
    return response
<commit_msg>code cosmetics<commit_after># -*- coding: utf-8 -*-
from django.conf import settings
from django.core.context_processors import csrf
from django.shortcuts import render_to_response
from geography.utils import JsonResponse, StaticFiles
from django.http import HttpResponse
from geography.models import Place
import json
import os
from django.core.servers.basehttp import FileWrapper


def home(request):
    JS_FILES = (
        "static/lib/js/fallbacks.js",
        "static/lib/js/jquery-1.11.0.min.js",
        "static/lib/js/bootstrap.js",
        "static/lib/angular-1.2.9/angular.min.js",
        "static/lib/angular-1.2.9/angular-route.min.js",
        "static/lib/angular-1.2.9/angular-cookies.min.js",
        "static/lib/js/raphael.js",
        "static/lib/raphael-pan-zoom/raphael.pan-zoom.min.js",
        "static/lib/js/kartograph.js",
        "static/lib/js/chroma.min.js",
        "static/lib/js/jquery.qtip.min.js",
        "static/lib/js/angulartics.min.js",
        "static/lib/js/angulartics-google-analytics.min.js",
        "static/js/map.js",
        "static/js/app.js",
        "static/js/controllers.js",
        "static/js/services.js",
        "static/js/filters.js",
        "static/js/directives.js"
    )
    TOP_CSS_FILES = (
        "static/lib/css/bootstrap.css",
        "static/css/app.css",
    )
    BOTTOM_CSS_FILES = (
        "static/lib/css/flags.css",
        "static/lib/css/tips.css",
        "static/css/map.css"
    )
    request.META["CSRF_COOKIE_USED"] = True
    title = 'Loc - ' if not settings.ON_OPENSHIFT else ''
    c = {
        'title': title,
        'isProduction': settings.ON_OPENSHIFT,
        'top_css_files': StaticFiles.add_hash(TOP_CSS_FILES),
        'bottom_css_files': StaticFiles.add_hash(BOTTOM_CSS_FILES),
        'js_files': StaticFiles.add_hash(JS_FILES),
        'continents': Place.objects.get_continents(),
        'states': Place.objects.get_states_with_map(),
        'hashes': json.dumps(settings.HASHES),
    }
    c.update(csrf(request))
    return render_to_response('home/home.html', c)


def csv_view(request, model):
    if not request.user.is_staff:
        response = {
            "error": "Permission denied: you need to be staff member. If you think you should be able to access logs, contact admins."}
        return JsonResponse(response)
    allowed_models = [
        'place',
        'placerelation',
        'answer',
        'answer_options']
    if model not in allowed_models:
        response = {"error": "the requested model '" + model + "' is not valid"}
        return JsonResponse(response)
    csv_file = "geography." + model + ".zip"
    logpath = os.path.join(settings.MEDIA_ROOT, csv_file)
    response = HttpResponse(FileWrapper(open(logpath)), content_type='application/zip')
    response['Content-Disposition'] = 'attachment; filename=' + csv_file
    return response
{'fraction_non_alphanumeric': 0.13646494085376307, 'fraction_numerical': 0.00480027430138865, 'mean_word_length': 2.7469492614001285, 'pattern_counts': {'":': 4, '<': 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': '5986904', 'n_tokens_mistral': 1948, 'n_tokens_neox': 1902, 'n_words': 331}