Exemplo n.º 1
0
    def filter_stream(self, req, method, filename, stream, data):
        """
        filter the stream for the roadmap (/roadmap)
        and milestones /milestone/<milestone>
        """

        if filename in ('roadmap.html', 'milestone_view.html'):
            trachours = TracHoursPlugin(self.env)

            hours = {}

            milestones = data.get('milestones')
            this_milestone = None

            if milestones is None:
                # /milestone view : only one milestone
                milestones = [ data['milestone'] ]
                this_milestone = milestones[0].name
                find_xpath = "//div[@class='milestone']//h1"
                xpath = "//div[@class='milestone']//div[@class='info']"
            else:
                # /roadmap view
                find_xpath = "//li[@class='milestone']//h2/a"
                xpath = "//li[@class='milestone']//div[@class='info']"

            for milestone in milestones:
                hours[milestone.name] = dict(totalhours=0., 
                                             estimatedhours=0.,)
            
                db = self.env.get_db_cnx()
                cursor = db.cursor()
                cursor.execute("select id from ticket where milestone=%s", (milestone.name,))
                tickets = [i[0] for i in cursor.fetchall()]

                if tickets:
                    hours[milestone.name]['date'] = Ticket(self.env, tickets[0]).time_created
                for ticket in tickets:
                    ticket = Ticket(self.env, ticket)

                    # estimated hours for the ticket
                    try:
                        estimatedhours = float(ticket['estimatedhours'])
                    except (ValueError, TypeError):
                        estimatedhours = 0.
                    hours[milestone.name]['estimatedhours'] += estimatedhours

                    # total hours for the ticket (seconds -> hours)
                    totalhours = trachours.get_total_hours(ticket.id) / 3600.0
                    hours[milestone.name]['totalhours'] += totalhours
                
                    # update date for oldest ticket
                    if ticket.time_created < hours[milestone.name]['date']:
                        hours[milestone.name]['date'] = ticket.time_created

            b = StreamBuffer()
            stream |= Transformer(find_xpath).copy(b).end().select(xpath).append(self.MilestoneMarkup(b, hours, req.href, this_milestone))

        return stream
Exemplo n.º 2
0
    def filter_stream(self, req, method, filename, stream, data):
        """
        filter the stream for the roadmap (/roadmap)
        and milestones /milestone/<milestone>
        """

        if filename in ('roadmap.html', 'milestone_view.html') and \
                'TICKET_VIEW_HOURS' in req.perm:
            trac_hours = TracHoursPlugin(self.env)

            hours = {}

            milestones = data.get('milestones')
            this_milestone = None

            if milestones is None:
                # /milestone view : only one milestone
                milestones = [data['milestone']]
                this_milestone = milestones[0].name
                find_xpath = "//div[@class='milestone']/h1"
                xpath = "//div[@class='milestone']/div[1]"
            else:
                # /roadmap view
                find_xpath = "//*[@class='milestone']//h2/a"
                xpath = "//*[@class='milestone']/div[1]"

            for milestone in milestones:
                hours[milestone.name] = dict(
                    totalhours=0.,
                    estimatedhours=0.,
                )

                tickets = [
                    tid for tid, in self.env.db_query(
                        """
                    SELECT id FROM ticket WHERE milestone=%s
                    """, (milestone.name, ))
                ]

                if tickets:
                    hours[milestone.name]['date'] = \
                        Ticket(self.env, tickets[0])['time']
                for ticket in tickets:
                    ticket = Ticket(self.env, ticket)

                    # estimated hours for the ticket
                    try:
                        estimated_hours = float(ticket['estimatedhours'])
                    except (ValueError, TypeError):
                        estimated_hours = 0.
                    hours[milestone.name]['estimatedhours'] += estimated_hours

                    # total hours for the ticket (seconds -> hours)
                    total_hours = trac_hours.get_total_hours(
                        ticket.id) / 3600.0
                    hours[milestone.name]['totalhours'] += total_hours

                    # update date for oldest ticket
                    if ticket['time'] < hours[milestone.name]['date']:
                        hours[milestone.name]['date'] = ticket['time']

            b = StreamBuffer()
            stream |= Transformer(find_xpath).copy(b).end().select(xpath). \
                append(
                self.MilestoneMarkup(b, hours, req.href, this_milestone))

        return stream