<commit_before># Python
import re

# Django
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.contrib import messages
from django.contrib.auth.models import User
from django.core.exceptions import PermissionDenied
from django.core.urlresolvers import reverse_lazy
from django.db.models import Q
from django.http import Http404, HttpResponseRedirect
from django.shortcuts import redirect
from django.utils.translation import ugettext as _
from django.utils.translation import ungettext
from django.views.generic import (
    DeleteView,
    DetailView,
    UpdateView,
)

# Third party
from actstream import action as act
from braces.views import (
    JSONResponseMixin,
    LoginRequiredMixin,
    SuperuserRequiredMixin,
    UserPassesTestMixin,
)
from toggleproperties.models import ToggleProperty

# AstroBin
from astrobin.forms import (
    ImageDemoteForm,
    ImageEditBasicForm,
    ImageFlagThumbsForm,
    ImagePromoteForm,
    ImageRevisionUploadForm,
    PrivateMessageForm,
)
from astrobin.models import (
    Image, ImageRevision,
    DeepSky_Acquisition,
    SolarSystem_Acquisition,
    LANGUAGES,
    LICENSE_CHOICES,
    SOLAR_SYSTEM_SUBJECT_CHOICES,
)
from astrobin.utils import to_user_timezone

# AstroBin apps
from astrobin_apps_notifications.utils import push_notification
from nested_comments.models import NestedComment
from rawdata.forms import (
    PublicDataPool_SelectExistingForm,
    PrivateSharedFolder_SelectExistingForm,
)
from rawdata.models import PrivateSharedFolder


class ImageFlagThumbsView(
        LoginRequiredMixin, SuperuserRequiredMixin, UpdateView):
    form_class = ImageFlagThumbsForm
    model = Image
    pk_url_kwarg = 'id'
    http_method_names = ('post',)

    def get_queryset(self):
        return Image.all_objects.filter(user = self.request.user)

    def get_success_url(self):
        image = self.get_object()
        return reverse_lazy('image_detail', args = (image.pk,))

    def post(self, request, *args, **kwargs):
        image = self.get_object()
        image.thumbnail_invalidate(False)
        for r in image.revisions.all():
            r.thumbnail_invalidate(False)
        messages.success(self.request, _("Thanks for reporting the problem. All thumbnails will be generated again."))
        return super(ImageFlagThumbsView, self).post(self.request, args, kwargs)


class ImageThumbView(JSONResponseMixin, DetailView):
    model = Image
    pk_url_kwarg = 'id'

    def get(self, request, *args, **kwargs):
        image = self.get_object()
        url = image.thumbnail(kwargs.pop('alias'), {
            'revision_label': kwargs.pop('r'),
            'animated': self.request.GET.get('animated', False),
        })

        return self.render_json_response({
            'id': image.pk,
            'url': url
        })


class ImageRawThumbView(DetailView):
    model = Image
    pk_url_kwarg = 'id'

    def get(self, request, *args, **kwargs):
        image = self.get_object()
        alias = kwargs.pop('alias')
        r = kwargs.pop('r')
        url = image.thumbnail(alias, {'revision_label': r})
        return redirect(url)


class ImageDetailView(DetailView):
    model = Image
    pk_url_kwarg = 'id'
    template_name = 'image/detail.html'
    template_name_suffix = ''

    def get_queryset(self):
        return Image.all_objects.all()

    def dispatch(self, request, *args, **kwargs):
        # Redirect to the correct revision
        try:
            image = Image.all_objects.get(pk = kwargs[self.pk_url_kwarg])
        except Image.DoesNotExist:
            raise Http404
<commit_msg>Fix getting thumbs of staged images<commit_after># Python
import re

# Django
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.contrib import messages
from django.contrib.auth.models import User
from django.core.exceptions import PermissionDenied
from django.core.urlresolvers import reverse_lazy
from django.db.models import Q
from django.http import Http404, HttpResponseRedirect
from django.shortcuts import redirect
from django.utils.translation import ugettext as _
from django.utils.translation import ungettext
from django.views.generic import (
    DeleteView,
    DetailView,
    UpdateView,
)

# Third party
from actstream import action as act
from braces.views import (
    JSONResponseMixin,
    LoginRequiredMixin,
    SuperuserRequiredMixin,
    UserPassesTestMixin,
)
from toggleproperties.models import ToggleProperty

# AstroBin
from astrobin.forms import (
    ImageDemoteForm,
    ImageEditBasicForm,
    ImageFlagThumbsForm,
    ImagePromoteForm,
    ImageRevisionUploadForm,
    PrivateMessageForm,
)
from astrobin.models import (
    Image, ImageRevision,
    DeepSky_Acquisition,
    SolarSystem_Acquisition,
    LANGUAGES,
    LICENSE_CHOICES,
    SOLAR_SYSTEM_SUBJECT_CHOICES,
)
from astrobin.utils import to_user_timezone

# AstroBin apps
from astrobin_apps_notifications.utils import push_notification
from nested_comments.models import NestedComment
from rawdata.forms import (
    PublicDataPool_SelectExistingForm,
    PrivateSharedFolder_SelectExistingForm,
)
from rawdata.models import PrivateSharedFolder


class ImageFlagThumbsView(
        LoginRequiredMixin, SuperuserRequiredMixin, UpdateView):
    form_class = ImageFlagThumbsForm
    model = Image
    pk_url_kwarg = 'id'
    http_method_names = ('post',)

    def get_queryset(self):
        return Image.all_objects.filter(user = self.request.user)

    def get_success_url(self):
        image = self.get_object()
        return reverse_lazy('image_detail', args = (image.pk,))

    def post(self, request, *args, **kwargs):
        image = self.get_object()
        image.thumbnail_invalidate(False)
        for r in image.revisions.all():
            r.thumbnail_invalidate(False)
        messages.success(self.request, _("Thanks for reporting the problem. All thumbnails will be generated again."))
        return super(ImageFlagThumbsView, self).post(self.request, args, kwargs)


class ImageThumbView(JSONResponseMixin, DetailView):
    model = Image
    queryset = Image.all_objects.all()
    pk_url_kwarg = 'id'

    def get(self, request, *args, **kwargs):
        image = self.get_object()
        url = image.thumbnail(kwargs.pop('alias'), {
            'revision_label': kwargs.pop('r'),
            'animated': self.request.GET.get('animated', False),
        })

        return self.render_json_response({
            'id': image.pk,
            'url': url
        })


class ImageRawThumbView(DetailView):
    model = Image
    queryset = Image.all_objects.all()
    pk_url_kwarg = 'id'

    def get(self, request, *args, **kwargs):
        image = self.get_object()
        alias = kwargs.pop('alias')
        r = kwargs.pop('r')
        url = image.thumbnail(alias, {'revision_label': r})
        return redirect(url)


class ImageDetailView(DetailView):
    model = Image
    pk_url_kwarg = 'id'
    template_name = 'image/detail.html'
    template_name_suffix = ''

    def get_queryset(self):
        return Image.all_objects.all()

    def dispatch(self, request, *args, **kwargs):
        # Redirect to the correct revision
        try:
            image = Image.all_objects.get(pk = kwargs[self.pk_url_kwarg])
        except Image.DoesNotExist:
            raise Http404

{'fraction_non_alphanumeric': 0.08644986449864499, 'fraction_numerical': 0.0016260162601626016, 'mean_word_length': 3.4517490952955368, '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': '81149', 'n_tokens_mistral': 2226, 'n_tokens_neox': 2161, 'n_words': 521}