<commit_before>from moksha.lib.base import Controller
from moksha.lib.helpers import Category, MokshaApp, Not, not_anonymous, MokshaWidget
from moksha.api.widgets.containers import DashboardContainer
from moksha.api.widgets import ContextAwareWidget

from tg import expose, tmpl_context, require, request

class BugsDashboard(DashboardContainer, ContextAwareWidget):
    template = 'mako:fedoracommunity.mokshaapps.packages.templates.single_col_dashboard'
    layout = [Category('content-col-apps',[])]

bugs_dashboard = BugsDashboard

class BugsController(Controller):
    @expose('mako:moksha.templates.widget')
    def index(self, package):
        tmpl_context.widget = bugs_dashboard
        return {'package': package}<commit_msg>Add BugStats and BugsGrid widgets<commit_after>from tw.api import Widget as TWWidget
from pylons import cache
from moksha.lib.base import Controller
from moksha.lib.helpers import Category, MokshaApp, Not, not_anonymous, MokshaWidget
from moksha.lib.helpers import Widget
from moksha.api.widgets.containers import DashboardContainer
from moksha.api.widgets import ContextAwareWidget, Grid
from moksha.api.connectors import get_connector

from tg import expose, tmpl_context, require, request

class BugStatsWidget(TWWidget):
    template='mako:fedoracommunity.mokshaapps.packages.templates.bugs_stats_widget'
    params = ['id', 'product', 'component', 'version', 'num_closed', 'num_open', 'num_new']
    product = 'Fedora'
    version = 'rawhide'
    component = None

    num_closed = num_open = num_new = '-'


bug_stats_widget = BugStatsWidget('bug_stats')


class BugsGrid(Grid):
    template='mako:fedoracommunity.mokshaapps.packages.templates.bugs_table_widget'

    def update_params(self, d):
        d['resource'] = 'bugzilla'
        d['resource_path'] = 'query_bugs'
        super(BugsGrid, self).update_params(d)

bugs_grid = BugsGrid('bugs_grid')


class BugsDashboard(DashboardContainer, ContextAwareWidget):
    template = 'mako:fedoracommunity.mokshaapps.packages.templates.single_col_dashboard'
    layout = [Category('content-col-apps',[
                         Widget('Dashboard', bug_stats_widget,
                                params={'filters':{'package': ''}}),
                         Widget('Recently Filed Bugs',
                                bugs_grid,
                                params={'filters':{'package': ''}}),
                         ])]

    def update_params(self, d):
        package = d.get('package')
        conn = get_connector('pkgdb')
        info = conn.get_basic_package_info(package)
        d['pkg_summary'] = info['summary']
        super(BugsDashboard, self).update_params(d)


bugs_dashboard = BugsDashboard('bugs_dashboard')

class BugsController(Controller):

    @expose('mako:moksha.templates.widget')
    def index(self, package):
        tmpl_context.widget = bugs_dashboard
        return {'options': {'package': package}}
{'fraction_non_alphanumeric': 0.10689890710382513, 'fraction_numerical': 0.0, 'mean_word_length': 3.801639344262295, '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': '6342018', 'n_tokens_mistral': 891, 'n_tokens_neox': 884, 'n_words': 174}