<commit_before>from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from django.contrib import admin
from django.contrib.admin.util import unquote
from django.conf.urls.defaults import patterns, url
from django.shortcuts import redirect
from django.utils.functional import update_wrapper

from django_qbe.utils import pickle_encode, get_query_hash
from django_qbe.utils import admin_site

from .models import SavedQuery


class SavedQueryAdmin(admin.ModelAdmin):
    list_display = ('name', 'description', 'date_created', 'run_link')

    def run_link(self, obj):
        info = self.model._meta.app_label, self.model._meta.module_name
        pickled = pickle_encode(obj.query_data)
        query_hash = get_query_hash(pickled)
        return u'<span class="nowrap"><a href="%s">%s</a> | <a href="%s">%s</a></span>' % \
            (reverse("admin:%s_%s_run" % info, args=(obj.pk,)), _("Run"),
             reverse("qbe_form", kwargs={'query_hash': query_hash}), _("Edit"))
    run_link.short_description = _("query")
    run_link.allow_tags = True

    def get_urls(self):
        def wrap(view):
            def wrapper(*args, **kwargs):
                return self.admin_site.admin_view(view)(*args, **kwargs)
            return update_wrapper(wrapper, view)
        info = self.model._meta.app_label, self.model._meta.module_name
        urlpatterns = patterns('',
            url(r'^(.+)/run/$', wrap(self.run_view), name='%s_%s_run' % info),
        )
        return urlpatterns + super(SavedQueryAdmin, self).get_urls()

    def save_model(self, request, obj, form, change):
        query_hash = request.GET.get("hash", "")
        obj.query_hash = query_hash
        obj.query_data = request.session["qbe_query_%s" % query_hash]<commit_msg>Adding query_hash to admin for savedqueries<commit_after>from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from django.contrib import admin
from django.contrib.admin.util import unquote
from django.conf.urls.defaults import patterns, url
from django.shortcuts import redirect
from django.utils.functional import update_wrapper

from django_qbe.utils import pickle_encode, get_query_hash
from django_qbe.utils import admin_site

from .models import SavedQuery


class SavedQueryAdmin(admin.ModelAdmin):
    list_display = ('name', 'description', 'date_created', 'query_hash',
                    'run_link')

    def run_link(self, obj):
        info = self.model._meta.app_label, self.model._meta.module_name
        pickled = pickle_encode(obj.query_data)
        query_hash = get_query_hash(pickled)
        return u'<span class="nowrap"><a href="%s">%s</a> | <a href="%s">%s</a></span>' % \
            (reverse("admin:%s_%s_run" % info, args=(obj.pk,)), _("Run"),
             reverse("qbe_form", kwargs={'query_hash': query_hash}), _("Edit"))
    run_link.short_description = _("query")
    run_link.allow_tags = True

    def get_urls(self):
        def wrap(view):
            def wrapper(*args, **kwargs):
                return self.admin_site.admin_view(view)(*args, **kwargs)
            return update_wrapper(wrapper, view)
        info = self.model._meta.app_label, self.model._meta.module_name
        urlpatterns = patterns('',
            url(r'^(.+)/run/$', wrap(self.run_view), name='%s_%s_run' % info),
        )
        return urlpatterns + super(SavedQueryAdmin, self).get_urls()

    def save_model(self, request, obj, form, change):
        query_hash = request.GET.get("hash", "")
        obj.query_hash = query_hash
        obj.query_data = request.session["qbe_query_%s" % query_hash]
{'fraction_non_alphanumeric': 0.13039912520503008, 'fraction_numerical': 0.0, 'mean_word_length': 3.522867737948084, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '5194365', 'n_tokens_mistral': 1150, 'n_tokens_neox': 1137, 'n_words': 239}