<commit_before>from django.shortcuts import render_to_response
from django.template import RequestContext
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.views.decorators.csrf import csrf_protect

from localtv.admin import forms
from localtv.decorators import require_site_admin
from localtv.models import SiteSettings, WidgetSettings


@require_site_admin
@csrf_protect
def edit_settings(request, form_class=forms.EditSettingsForm):
    site_settings = SiteSettings.objects.get_current()
    form = form_class(instance=site_settings)

    if request.method == 'POST':
        form = form_class(request.POST, request.FILES,
                                      instance=site_settings)
        if form.is_valid():
            site_settings = form.save()
            if request.POST.get('delete_background'):
                if site_settings.background:
                    site_settings.background.delete()
            return HttpResponseRedirect(
                reverse('localtv_admin_settings'))

    return render_to_response(
        "localtv/admin/edit_settings.html",
        {'form': form},
        context_instance=RequestContext(request))


@require_site_admin
@csrf_protect
def widget_settings(request):
    if request.method == 'POST':
        form = forms.WidgetSettingsForm(
            request.POST,
            request.FILES,
            instance=WidgetSettings.objects.get_current())
        if form.is_valid():
            widgetsettings = form.save()
            if request.POST.get('delete_icon'):
                if widgetsettings.icon:
                    widgetsettings.icon.delete()
            if request.POST.get('delete_css'):
                if widgetsettings.css:
                    widgetsettings.css.delete()
            return HttpResponseRedirect(
                reverse('localtv_admin_widget_settings'))
    else:
        form = forms.WidgetSettingsForm(
            instance=WidgetSettings.objects.get_current(),
            initial={
                'title':
                WidgetSettings.objects.get().get_title_or_reasonable_default()})

    return render_to_response(
        'localtv/admin/widget_settings.html',
        {'form': form},
        context_instance=RequestContext(request))
<commit_msg>Removed an assumption of a single WidgetSettings instance.<commit_after>from django.shortcuts import render_to_response
from django.template import RequestContext
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.views.decorators.csrf import csrf_protect

from localtv.admin import forms
from localtv.decorators import require_site_admin
from localtv.models import SiteSettings, WidgetSettings


@require_site_admin
@csrf_protect
def edit_settings(request, form_class=forms.EditSettingsForm):
    site_settings = SiteSettings.objects.get_current()
    form = form_class(instance=site_settings)

    if request.method == 'POST':
        form = form_class(request.POST, request.FILES,
                                      instance=site_settings)
        if form.is_valid():
            site_settings = form.save()
            if request.POST.get('delete_background'):
                if site_settings.background:
                    site_settings.background.delete()
            return HttpResponseRedirect(
                reverse('localtv_admin_settings'))

    return render_to_response(
        "localtv/admin/edit_settings.html",
        {'form': form},
        context_instance=RequestContext(request))


@require_site_admin
@csrf_protect
def widget_settings(request):
    if request.method == 'POST':
        form = forms.WidgetSettingsForm(
            request.POST,
            request.FILES,
            instance=WidgetSettings.objects.get_current())
        if form.is_valid():
            widgetsettings = form.save()
            if request.POST.get('delete_icon'):
                if widgetsettings.icon:
                    widgetsettings.icon.delete()
            if request.POST.get('delete_css'):
                if widgetsettings.css:
                    widgetsettings.css.delete()
            return HttpResponseRedirect(
                reverse('localtv_admin_widget_settings'))
    else:
        widgetsettings = WidgetSettings.objects.get_current()
        form = forms.WidgetSettingsForm(
            instance=widgetsettings,
            initial={
                'title': widgetsettings.get_title_or_reasonable_default()})

    return render_to_response(
        'localtv/admin/widget_settings.html',
        {'form': form},
        context_instance=RequestContext(request))
{'fraction_non_alphanumeric': 0.08351269909599655, 'fraction_numerical': 0.0, 'mean_word_length': 2.571867794004612, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2242181', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1158, 'n_words': 227}