<commit_before>
import json

from tagging.models import TaggedItem
from tagging.utils import get_tag

from django.shortcuts import get_object_or_404, render, redirect
from django.core.urlresolvers import reverse
from django.http import HttpResponse, HttpResponseForbidden
from django.contrib.auth.decorators import login_required, permission_required
from django.views.generic import DetailView
from django import forms

from extensions.models import Extension, ExtensionVersion, Screenshot

class ExtensionLatestVersionView(DetailView):
    model = Extension
    context_object_name = "version"
    template_name = "browse/detail.html"

    def get(self, request, **kwargs):
        # Redirect if we don't match the slug.
        slug = self.kwargs.get('slug')
        self.object = self.get_object()
        if slug == self.object.extension.slug:
            context = self.get_context_data(object=self.object)
            return self.render_to_response(context)

        kwargs = dict(self.kwargs)
        kwargs.update(dict(slug=self.object.extension.slug))
        return redirect('browse-detail', **kwargs)

    def get_object(self):
        extension = super(ExtensionLatestVersionView, self).get_object()
        return extension.get_latest_version()

class ExtensionVersionView(DetailView):
    model = ExtensionVersion
    context_object_name = "version"
    template_name = "browse/detail.html"

class UploadScreenshotForm(forms.ModelForm):
    class Meta:
        model = Screenshot
        exclude = 'extension',

@login_required
def upload_screenshot(request, pk):
    extension = get_object_or_404(Extension, pk=pk)
    if request.user.has_perm('extensions.can-modify-data') or extension.creator == request.user:
        pass
    else:
        return HttpResponseForbidden()

    if request.method == 'POST':
        form = UploadScreenshotForm(request.POST, request.FILES)
        if form.is_valid():
            screenshot = form.save(commit=False)
            screenshot.extension = extension
            screenshot.save()

        return redirect('detail', kwargs=dict(pk=extension.pk))
    else:
        form = UploadScreenshotForm(initial=dict(extension="FOO"))

    return render(request, 'browse/upload-screenshot.html', dict(form=form))

@permission_required('extensions.can-modify-tags')
def modify_tag(request, tag):
    uuid = request.GET.get('uuid')
    action = request.GET.get('action')
    extension = get_object_or_404(Extension, is_published=True, uuid=uuid)<commit_msg>Forgot to fix a redirect from cleanup.<commit_after>
import json

from tagging.models import TaggedItem
from tagging.utils import get_tag

from django.shortcuts import get_object_or_404, render, redirect
from django.core.urlresolvers import reverse
from django.http import HttpResponse, HttpResponseForbidden
from django.contrib.auth.decorators import login_required, permission_required
from django.views.generic import DetailView
from django import forms

from extensions.models import Extension, ExtensionVersion, Screenshot

class ExtensionLatestVersionView(DetailView):
    model = Extension
    context_object_name = "version"
    template_name = "browse/detail.html"

    def get(self, request, **kwargs):
        # Redirect if we don't match the slug.
        slug = self.kwargs.get('slug')
        self.object = self.get_object()
        if slug == self.object.extension.slug:
            context = self.get_context_data(object=self.object)
            return self.render_to_response(context)

        kwargs = dict(self.kwargs)
        kwargs.update(dict(slug=self.object.extension.slug))
        return redirect('browse-detail', **kwargs)

    def get_object(self):
        extension = super(ExtensionLatestVersionView, self).get_object()
        return extension.get_latest_version()

class ExtensionVersionView(DetailView):
    model = ExtensionVersion
    context_object_name = "version"
    template_name = "browse/detail.html"

class UploadScreenshotForm(forms.ModelForm):
    class Meta:
        model = Screenshot
        exclude = 'extension',

@login_required
def upload_screenshot(request, pk):
    extension = get_object_or_404(Extension, pk=pk)
    if request.user.has_perm('extensions.can-modify-data') or extension.creator == request.user:
        pass
    else:
        return HttpResponseForbidden()

    if request.method == 'POST':
        form = UploadScreenshotForm(request.POST, request.FILES)
        if form.is_valid():
            screenshot = form.save(commit=False)
            screenshot.extension = extension
            screenshot.save()

        return redirect('browse-detail', pk=extension.pk)
    else:
        form = UploadScreenshotForm(initial=dict(extension="FOO"))

    return render(request, 'browse/upload-screenshot.html', dict(form=form))

@permission_required('extensions.can-modify-tags')
def modify_tag(request, tag):
    uuid = request.GET.get('uuid')
    action = request.GET.get('action')
    extension = get_object_or_404(Extension, is_published=True, uuid=uuid)
{'fraction_non_alphanumeric': 0.09691542288557214, 'fraction_numerical': 0.003582089552238806, 'mean_word_length': 3.7730294396961064, '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': '3714087', 'n_tokens_mistral': 1466, 'n_tokens_neox': 1431, 'n_words': 315}