1 from action import Action
4 from datetime import date
6 from observable import *
7 from filtered_list import FilteredList,StatusFilteredList
9 from log.logging import logger
12 class ProjectStatus(Status):
15 # def __eq__(self,other):
17 class Inactive(ProjectStatus):
19 super(Inactive,self).__init__(u'review',4,'!')
21 def update(self,project):
22 # if project.has_active_actions():
29 class Active(ProjectStatus):
32 super(Active,self).__init__(u'active',1)
34 def update(self,project):
35 if not project.has_active_actions():
41 class Tickled(ProjectStatus):
42 def __init__(self,date=date.tomorrow()):
43 super(Tickled,self).__init__(u'tickled',3,'/')
46 def update(self,project):
47 if self.date <= date.now():
53 return super(Tickled,self).__str__()+" for %s"%self.date
58 unprocessed = ProjectStatus(u'unprocessed',0)
60 done = ProjectStatus(u'done',2,'+')
63 someday = ProjectStatus(u'someday',5,'~')
64 info = ProjectStatus(u'info',0)
68 class Project(ObservableItem,ItemWithStatus):
70 def __init__(self,name,status = inactive):
71 assert type(name) == unicode
72 logger.log(u'Creating project %s (%s)'%(name,status))
73 ItemWithStatus.__init__(self,status)
75 self.actions=StatusFilteredList([])
76 self.infos=FilteredList([])
77 self.update_methods = {'status':self.action_changed_status,
78 'description':self.action_changed_content,
79 'info':self.action_changed_content,
80 'context':self.action_changed_content,
81 'text':self.info_changed}
82 super(Project,self).__init__()
83 for o in Project.observers:
84 o.notify(self.__class__,'new_project',self,None)
85 logger.log(u'Now, its project %s (%s)'%(name,status))
88 def add_action(self,a):
90 a.observers.append(self)
91 self.actions.append(a)
92 self.notify_observers('add_action',a)
93 if a.status == action.unprocessed:
94 a.status = action.active
96 def remove_action(self,a):
97 a.status = action.done
98 a.observers.remove(self)
99 self.actions.remove(a)
100 self.notify_observers('remove_action',a)
102 def add_info(self,info,position=None):
103 info.observers.append(self)
104 self.infos.append(info)
105 self.notify_observers('add_info', info)
107 def remove_info(self,info):
108 info.observers.remove(self)
109 self.infos.remove(info)
110 self.notify_observers('remove_info', info)
114 for a in self.actions_with_status(action.inactive):
115 a.status = action.active
117 def deactivate(self):
118 self.status = inactive
119 for a in self.actions_with_status(action.active):
120 a.status = action.inactive
122 def actions_with_status(self,status):
123 return self.actions.with_property(lambda a:a.status == status)
125 def active_actions(self):
126 return self.actions_with_status(action.active)
128 def has_active_actions(self):
129 return len(self.active_actions()) > 0
131 def notify(self,action,attribute,new=None,old=None):
132 self.update_methods[attribute](action,new)
134 def info_changed(self,info,text):
135 self.notify_observers('changed_info', info)
137 def action_changed_content(self,action,content):
138 self.notify_observers('changed_action',action)
140 def action_changed_status(self,a,status):
141 self.notify_observers('changed_action', new=a, old=None)
143 def last_modification_date(self):
144 return datetime.date.now()
146 def __eq__(self, other):
147 return self.name == other.name and self.status == other.status
149 def __ne__(self,project):
150 return not self.__eq__(project)
155 def status_symbol_and_name(self):
156 return self.status_symbol()+self.name
158 return u'Project %s (@%s, %s actions, %s infos)'%("Moeject",self.status.name.capitalize(),len(self.actions),len(self.infos))