<commit_before>import logging

from pylons import request, response, tmpl_context as c
from pylons.controllers.util import redirect
from pylons.i18n import _

from openspending import model
from openspending.model import Source, Run, LogRecord, meta as db
from openspending.ui.lib import helpers as h
from openspending.ui.lib.page import Page
from openspending.ui.lib.base import BaseController, render
from openspending.ui.lib.base import abort, require

log = logging.getLogger(__name__)

class RunController(BaseController):

    def _get_run(self, dataset, source, id):
        self._get_dataset(dataset)
        require.dataset.update(c.dataset)
        c.source = Source.by_id(source)
        if c.source is None or c.source.dataset != c.dataset:
            abort(404, _("There is no source '%s'") % source)
        c.run = Run.by_id(id)
        if c.run is None or c.run.source != c.source:
            abort(404, _("There is no run '%s'") % id)

    def view(self, dataset, source, id, format='html'):
        self._get_run(dataset, source, id)
        system = c.run.records.filter_by(category=LogRecord.CATEGORY_SYSTEM)
        c.num_system = system.count()
        c.system_page = Page(system.order_by(LogRecord.timestamp.asc()), 
                page=self._get_page('system_page'),
                items_per_page=10)
        data = c.run.records.filter_by(category=LogRecord.CATEGORY_DATA)
        c.num_data = data.count()
        c.data_page = Page(data.order_by(LogRecord.timestamp.asc()), 
                page=self._get_page('data_page'),
                items_per_page=20)
        return render('run/view.html')


<commit_msg>Bugfix: re-introduce parts of the pager class to support error listings in source runs. <commit_after>import logging

from pylons import tmpl_context as c
from pylons.i18n import _

from openspending.model import Source, Run, LogRecord
from webhelpers import paginate
from openspending.ui.lib.base import BaseController, render
from openspending.ui.lib.base import abort, require

log = logging.getLogger(__name__)


class Page(paginate.Page):
    # Curry the pager method of the webhelpers.paginate.Page class, so we have
    # our custom layout set as default.
    def pager(self, *args, **kwargs):
        kwargs.update(
            format="<div class='pager'>$link_previous ~2~ $link_next</div>",
            symbol_previous=u'\xab Prev', symbol_next=u'Next \xbb'
        )
        return super(Page, self).pager(*args, **kwargs)


class RunController(BaseController):

    def _get_run(self, dataset, source, id):
        self._get_dataset(dataset)
        require.dataset.update(c.dataset)
        c.source = Source.by_id(source)
        if c.source is None or c.source.dataset != c.dataset:
            abort(404, _("There is no source '%s'") % source)
        c.run = Run.by_id(id)
        if c.run is None or c.run.source != c.source:
            abort(404, _("There is no run '%s'") % id)

    def view(self, dataset, source, id, format='html'):
        self._get_run(dataset, source, id)
        system = c.run.records.filter_by(category=LogRecord.CATEGORY_SYSTEM)
        c.num_system = system.count()
        c.system_page = Page(system.order_by(LogRecord.timestamp.asc()),
                page=self._get_page('system_page'),
                items_per_page=10)
        data = c.run.records.filter_by(category=LogRecord.CATEGORY_DATA)
        c.num_data = data.count()
        c.data_page = Page(data.order_by(LogRecord.timestamp.asc()),
                page=self._get_page('data_page'),
                items_per_page=20)
        return render('run/view.html')

{'fraction_non_alphanumeric': 0.11246200607902736, 'fraction_numerical': 0.006907985631389887, 'mean_word_length': 2.9519650655021836, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2536388', 'n_tokens_mistral': 1150, 'n_tokens_neox': 1115, 'n_words': 271}