예제 #1
0
    def filter_stream(self, req, method, filename, stream, formdata):
        '''Add workflows to query/report output'''
        if filename != 'query.html' and filename != 'report_view.html':
            return stream
        if not (req.perm.has_permission('TICKET_ADMIN')
                or req.perm.has_permission('TICKET_GRID_WORKFLOW')):
            return stream

        ts = TicketSystem(self.env)

        add_script(req, 'gridflow/gridflow.js')

        html = stream.render()
        js = ''
        tickets = []

        copy = genshi.XML(html)
        nodes = genshi.path.Path('//td[contains(@class, "ticket")]//a/text()')
        tickets += [int(a[1][1:]) for a in nodes.select(copy)]

        copy = genshi.XML(html)
        nodes = genshi.path.Path('//td[contains(@class, "id")]//a/text()')
        tickets += [int(a[1][1:]) for a in nodes.select(copy)]

        copy = genshi.XML(html)
        tktDict = {}
        for tno in tickets:
            tktDict[tno] = {'labels': [], 'widgets': [], 'actions': []}
            tkt = trac.ticket.Ticket(self.env, tno)
            actions = ts.get_available_actions(req, tkt)
            for action in actions:
                for controller in self._get_action_controllers(
                        req, tkt, action):
                    (label, widget,
                     hint) = controller.render_ticket_action_control(
                         req, tkt, action)
                    tktDict[tno]['actions'].append(action)
                    tktDict[tno]['labels'].append(label)
                    tktDict[tno]['widgets'].append(widget.generate().render())

        js += 'tktDict = ' + repr(tktDict).replace(", u'", ", '").replace(
            "[u'", "['") + ';\n'
        js += 'baseURL = "%s";\n' % req.base_url

        script = genshi.builder.tag.script(js, type="text/javascript")
        xpath = '//head'
        copy |= Transformer(xpath).append(script)
        return copy
예제 #2
0
파일: wdmmg.py 프로젝트: rufuspollock/econ
    def table(self, id=None):
        if id is None:
            abort(404)
        c.table = self.dbmod.PesaTable.query.get(int(id))
        if c.table is None:
            abort(404)
        c.expenditures = self.dbmod.Expenditure.query.\
                filter_by(pesatable=c.table).\
                order_by(self.dbmod.Expenditure.title).\
                order_by(self.dbmod.Expenditure.date).all()
        # from formalchemy import FieldSet, Field, Grid
        # c.grid = Grid(self.dbmod.Expenditure, c.expenditures).render()
        # c.grid = genshi.HTML(c.grid)
        # fs = FieldSet(c.table)
        td = swiss.tabular.TabularData()
        td.header = ['Year', 'Title', 'Amount']
        td.data = [[e.date, e.title, e.amount] for e in c.expenditures]
        tdout = swiss.tabular.pivot(td, 'Year', 'Title', 'Amount')
        # tdouttable = swiss.tabular.pivot(td,'Title','Year','Amount')

        plotctr = econ.www.controllers.plot.PlotController()
        c.html_table = genshi.XML(plotctr.get_html_table(tdout))
        c.chart_code = genshi.HTML(plotctr._get_chart_code(tdout))

        return render('wdmmg/table')
예제 #3
0
 def chart(self, id=None):
     self._get_data(id)
     if c.error:
         return self.help()
     c.html_table = genshi.XML(self.get_html_table(self.tabular))
     c.chart_code = genshi.HTML(self._get_chart_code(self.tabular))
     return render('plot/chart', strip_whitespace=False)
예제 #4
0
파일: wdmmg.py 프로젝트: rufuspollock/econ
    def spend(self):
        a = d.Analyzer()
        entries, years = a.extract_simple()
        expenditure = entries['Public sector current expenditure']
        td = swiss.tabular.TabularData(header=['Year'], data=[years])
        for k, v in entries.items():
            td.header.append(k)
            td.data.append(v)
        td.data = swiss.tabular.transpose(td.data)

        import econ.www.controllers.plot
        plotctr = econ.www.controllers.plot.PlotController()
        c.html_table = genshi.XML(plotctr.get_html_table(td))
        c.chart_code = genshi.HTML(plotctr._get_chart_code(td))
        c.fig_title = u'UK Government Expenditure (Millions)'
        return render('wdmmg/spend')
예제 #5
0
 def view(self, id):
     c.pkg = self._get_package(id)
     c.metadata_keys = [
         k for k in c.pkg.metadata.key_list if getattr(c.pkg, k)
     ]
     # limit to a maximum to avoid problems with huge datasets
     c.data_limit = 1000
     c.plot_data_url = h.url_for(controller='plot',
                                 action='chart',
                                 id=id,
                                 limit='[:%s]' % c.data_limit)
     import econ.www.controllers.plot
     plotctr = econ.www.controllers.plot.PlotController()
     plotctr._get_data(id, limit='[:%s]' % c.data_limit)
     try:
         c.html_table = genshi.XML(plotctr.get_html_table(plotctr.tabular))
         c.chart_code = genshi.HTML(plotctr._get_chart_code(
             plotctr.tabular))
     except Exception, inst:
         c.error = 'Problem displaying graph or table for data'
예제 #6
0
    def view(self, id=None):
        countries = request.params.getall('countries')
        series = request.params.get('series')
        try:
            c.series = self.dbmod.Series.query.get(series)
        except:
            h.redirect_to(controller='mdg', action='index', id=None)
        c.values = self.dbmod.Value.query.filter(
            self.dbmod.Value.country_code.in_(countries)).filter_by(
                series_code=series).all()
        c.countries = [
            self.dbmod.Country.query.get(ctry) for ctry in countries
        ]
        td = self._cvt_values_to_tabular(c.values)

        import econ.www.controllers.plot
        plotctr = econ.www.controllers.plot.PlotController()
        c.html_table = genshi.XML(plotctr.get_html_table(td))
        c.chart_code = genshi.HTML(plotctr._get_chart_code(td))
        # return render('plot/chart', strip_whitespace=False)
        return render('mdg/view')
예제 #7
0
파일: wdmmg.py 프로젝트: rufuspollock/econ
    def myseries(self, id=None):
        # overloading one url to be both add and view ...
        self._handle_series_changes()
        # now do display
        # from pylons import session
        c.programmes = []
        for seriesid in session['datasets']:
            dataset_code, id = seriesid.split('---')
            if dataset_code == 'cra':
                prg = self.dbmodcra.Area.query.get(id)
                c.programmes.append(prg)

        td = swiss.tabular.TabularData()
        td.header = ['Year', 'Title', 'Amount']
        for prg in c.programmes:
            td.data += [[e.year, prg.title + '-' + prg.region, e.amount]
                        for e in prg.expenditures]
        tdout = swiss.tabular.pivot(td, 'Year', 'Title', 'Amount')
        plotctr = econ.www.controllers.plot.PlotController()
        c.html_table = genshi.XML(plotctr.get_html_table(tdout))
        c.chart_code = genshi.HTML(plotctr._get_chart_code(tdout))
        return render('wdmmg/myseries')
예제 #8
0
	def id_link(self):
		return genshi.XML('<a href="/details?id=%s">%s</a>' % (self.id, str(self.date)))
예제 #9
0
 def table(self, id=None):
     self._get_data(id)
     if not c.error:
         c.html_table = genshi.XML(self.get_html_table(self.tabular))
     self._set_format()
     return render('plot/table', strip_whitespace=False)