[Cubicweb] Ticket / IProgressAdapter

Sylvain Thénault sylvain.thenault at logilab.fr
Fri Sep 10 08:46:26 CEST 2010


On 09 septembre 21:42, Carlos Balderas wrote:
> Hello, list
 
Hi Carlos,
 
> 1.- What do you think about making an IProgressAdapter for Ticket entity in
> Tracker cube?
>      (We find this handy to display progress bar for tickets.)

sounds like a good idea.
 
> 2.- Would it be so simple like adding these lines in
> tracker/entities/ticket.py file?
> 
> 2.1.- Create the IProgressAdapter
> 
> from cubicweb.entities.adapters import IProgressAdapter
> from cubicweb.selectors import is_instance
> 
> class TicketIProgressAdapter(IProgressAdapter):
> 
>     """IProgressAdapter for Tickets """
> 
>     __select__ = is_instance('Ticket')
> 
>     def progress_info(self):
> 
>         """returns a dictionary describing load and progress of the
> ticket"""
> 
>         return {'notestimated': 0,
>                 'estimated': 0,
>                 'done': 0,
>                 'todo': 0 }
> 
> 2.2.- Add methods to Ticket Entity
> 
> class Ticket(AnyEntity):
>     __regid__ = 'Ticket'
> 
> --------------------- add these 3 methods ---------------------
> 
>     def done(self):
> 
>         """returns work done in this ticket """
> 
>         return self.load - self.load_left
> 
>     def todo(self):
> 
>         """returns remaining work in this ticket """
> 
>         return self.load_left
> 
>     def revised_cost(self):
> 
>         """return total work estimated to this ticket """
> 
>         return self.load
> 
> Making the changes above, the progress bar view works for tickets too, but I
> am not sure this is the best way to do it.

I don't think that it display valuable information then. The methods you added
on the  ticket entity should be properties of the adapter. Though the base
adapter provides default implementation for them, based on information returned
by progress info. And you've to implement the in_progress method which is
also abstract on the base adapter. So something like:

class TicketIProgressAdapter(IProgressAdapter):
    """IProgressAdapter for Tickets """
    __select__ = is_instance('Ticket')

    def progress_info(self):
        """returns a dictionary describing load and progress of the ticket"""
        return {'notestimated': 0,
                'estimated': 1,
                'done': self.entity.load,
                'todo': self.entity.load - self.entity.load_left}

    def in_progress(self):
        """returns True if status is not finished"""
        return self.entity.load_left != 0

should be enough.

-- 
Sylvain Thénault                               LOGILAB, Paris (France)
Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations
Développement logiciel sur mesure:       http://www.logilab.fr/services
CubicWeb, the semantic web framework:    http://www.cubicweb.org




More information about the Cubicweb mailing list