# HG changeset patch # User Sylvain Thénault # Date 1276187292 -7200 # Node ID 61d6a4caa9637ad10f617b056a1b00d82d5fb121 # Parent f0e521487903db6d4bfdad94636d2f1e11852a38 [iprogress] move adapter to entities.adapters 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 diff -r f0e521487903 -r 61d6a4caa963 web/application.py --- a/web/application.py Thu Jun 10 16:57:02 2010 +0200 +++ b/web/application.py Thu Jun 10 18:28:12 2010 +0200 @@ -15,9 +15,8 @@ # # You should have received a copy of the GNU Lesser General Public License along # with CubicWeb. If not, see . -"""CubicWeb web client application object +"""CubicWeb web client application object""" -""" from __future__ import with_statement __docformat__ = "restructuredtext en" diff -r f0e521487903 -r 61d6a4caa963 web/views/ibreadcrumbs.py --- a/web/views/ibreadcrumbs.py Thu Jun 10 16:57:02 2010 +0200 +++ b/web/views/ibreadcrumbs.py Thu Jun 10 18:28:12 2010 +0200 @@ -15,9 +15,8 @@ # # You should have received a copy of the GNU Lesser General Public License along # with CubicWeb. If not, see . -"""navigation components definition for CubicWeb web client +"""breadcrumbs components definition for CubicWeb web client""" -""" __docformat__ = "restructuredtext en" _ = unicode diff -r f0e521487903 -r 61d6a4caa963 web/views/iprogress.py --- a/web/views/iprogress.py Thu Jun 10 16:57:02 2010 +0200 +++ b/web/views/iprogress.py Thu Jun 10 18:28:12 2010 +0200 @@ -25,120 +25,12 @@ from logilab.mtconverter import xml_escape from cubicweb.utils import make_uid -from cubicweb.selectors import implements, adaptable -from cubicweb.interfaces import IProgress, IMileStone +from cubicweb.selectors import adaptable from cubicweb.schema import display_name -from cubicweb.view import EntityView, EntityAdapter, implements_adapter_compat +from cubicweb.view import EntityView from cubicweb.web.views.tableview import EntityAttributesTableView -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 - - class ProgressTableView(EntityAttributesTableView): """The progress table view is able to display progress information of any object implement IMileStone.