diff -r f0e521487903 -r 61d6a4caa963 entities/adapters.py --- a/entities/adapters.py Thu Jun 10 16:57:02 2010 +0200 +++ b/entities/adapters.py Thu Jun 10 18:28:12 2010 +0200 @@ -29,7 +29,7 @@ from cubicweb.view import EntityAdapter, implements_adapter_compat from cubicweb.selectors import implements, relation_possible -from cubicweb.interfaces import IDownloadable, ITree +from cubicweb.interfaces import IDownloadable, ITree, IProgress, IMileStone class IEmailableAdapter(EntityAdapter): @@ -327,3 +327,109 @@ path.reverse() return path + +class IProgressAdapter(EntityAdapter): + """something that has a cost, a state and a progression. + + You should at least override progress_info an in_progress methods on concret + implementations. + """ + __regid__ = 'IProgress' + __select__ = implements(IProgress) # XXX for bw compat, should be abstract + + @property + @implements_adapter_compat('IProgress') + def cost(self): + """the total cost""" + return self.progress_info()['estimated'] + + @property + @implements_adapter_compat('IProgress') + def revised_cost(self): + return self.progress_info().get('estimatedcorrected', self.cost) + + @property + @implements_adapter_compat('IProgress') + def done(self): + """what is already done""" + return self.progress_info()['done'] + + @property + @implements_adapter_compat('IProgress') + def todo(self): + """what remains to be done""" + return self.progress_info()['todo'] + + @implements_adapter_compat('IProgress') + def progress_info(self): + """returns a dictionary describing progress/estimated cost of the + version. + + - mandatory keys are (''estimated', 'done', 'todo') + + - optional keys are ('notestimated', 'notestimatedcorrected', + 'estimatedcorrected') + + 'noestimated' and 'notestimatedcorrected' should default to 0 + 'estimatedcorrected' should default to 'estimated' + """ + raise NotImplementedError + + @implements_adapter_compat('IProgress') + def finished(self): + """returns True if status is finished""" + return not self.in_progress() + + @implements_adapter_compat('IProgress') + def in_progress(self): + """returns True if status is not finished""" + raise NotImplementedError + + @implements_adapter_compat('IProgress') + def progress(self): + """returns the % progress of the task item""" + try: + return 100. * self.done / self.revised_cost + except ZeroDivisionError: + # total cost is 0 : if everything was estimated, task is completed + if self.progress_info().get('notestimated'): + return 0. + return 100 + + @implements_adapter_compat('IProgress') + def progress_class(self): + return '' + + +class IMileStoneAdapter(IProgressAdapter): + __regid__ = 'IMileStone' + __select__ = implements(IMileStone) # XXX for bw compat, should be abstract + + parent_type = None # specify main task's type + + @implements_adapter_compat('IMileStone') + def get_main_task(self): + """returns the main ITask entity""" + raise NotImplementedError + + @implements_adapter_compat('IMileStone') + def initial_prevision_date(self): + """returns the initial expected end of the milestone""" + raise NotImplementedError + + @implements_adapter_compat('IMileStone') + def eta_date(self): + """returns expected date of completion based on what remains + to be done + """ + raise NotImplementedError + + @implements_adapter_compat('IMileStone') + def completion_date(self): + """returns date on which the subtask has been completed""" + raise NotImplementedError + + @implements_adapter_compat('IMileStone') + def contractors(self): + """returns the list of persons supposed to work on this task""" + raise NotImplementedError