<commit_before>from django.http import Http404
from django.utils.decorators import method_decorator
from django.views.decorators.clickjacking import xframe_options_exempt
from django.views.generic.base import TemplateView

from treeherder.model.derived import JobsModel


class ResultsetStatusView(TemplateView):

    template_name = "embed/resultset_status.html"

    def get_context_data(self, **kwargs):
        assert "repository" in kwargs and "revision" in kwargs
        context = super(ResultsetStatusView, self).get_context_data(**kwargs)
        with JobsModel(kwargs['repository']) as jm:
            resultset_list = jm.get_resultset_all_revision_lookup(
                [kwargs['revision']])
            if not resultset_list:
                raise Http404("No resultset found for revision {0}".format(
                    kwargs['revision']))
            result_set_id = resultset_list[kwargs['revision']]['id']
            resultset_status_dict = jm.get_push_status(result_set_id)
            update_needed = (('pending' in resultset_status_dict) or
                             ('running' in resultset_status_dict) or
                             not resultset_status_dict)
            context['update_needed'] = update_needed
            context['resultset_status_dict'] = resultset_status_dict
            return context

    # TODO: Replace with the class-based method_decorator once using Django 1.9.
    @method_decorator(xframe_options_exempt)
    def dispatch(self, *args, **kwargs):
        return super(ResultsetStatusView, self).dispatch(*args, **kwargs)<commit_msg>Bug 1311185 - Fix embed widget (#1978)<commit_after>from django.http import Http404
from django.utils.decorators import method_decorator
from django.views.decorators.clickjacking import xframe_options_exempt
from django.views.generic.base import TemplateView

from treeherder.model.derived import JobsModel
from treeherder.model.models import Push


class ResultsetStatusView(TemplateView):

    template_name = "embed/resultset_status.html"

    def get_context_data(self, **kwargs):
        assert "repository" in kwargs and "revision" in kwargs
        (repository_name, revision) = (kwargs['repository'], kwargs['revision'])
        context = super(ResultsetStatusView, self).get_context_data(**kwargs)
        pushes = Push.objects.filter(
            repository__name=repository_name,
            commits__revision__startswith=revision).values_list(
                'id', flat=True)
        if not len(pushes):
            raise Http404("No resultset found for revision {0}".format(
                revision))
        push_id = pushes[0]
        with JobsModel(repository_name) as jm:
            resultset_status_dict = jm.get_push_status(push_id)
            update_needed = (('pending' in resultset_status_dict) or
                             ('running' in resultset_status_dict) or
                             not resultset_status_dict)
            context['update_needed'] = update_needed
            context['resultset_status_dict'] = resultset_status_dict
        return context

    # TODO: Replace with the class-based method_decorator once using Django 1.9.
    @method_decorator(xframe_options_exempt)
    def dispatch(self, *args, **kwargs):
        return super(ResultsetStatusView, self).dispatch(*args, **kwargs)
{'fraction_non_alphanumeric': 0.08415990381725277, 'fraction_numerical': 0.009017132551848512, 'mean_word_length': 3.108641975308642, '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': '4480472', 'n_tokens_mistral': 944, 'n_tokens_neox': 893, 'n_words': 207}