GTG

Merge lp:~jml/gtg/docstrings-for-requester into lp:~gtg/gtg/old-trunk

Proposed by Jonathan Lange
Status: Merged
Merged at revision: not available
Proposed branch: lp:~jml/gtg/docstrings-for-requester
Merge into: lp:~gtg/gtg/old-trunk
Diff against target: None lines
To merge this branch: bzr merge lp:~jml/gtg/docstrings-for-requester
Reviewer Review Type Date Requested Status
Gtg developers Pending
Review via email: mp+8666@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Jonathan Lange (jml) wrote :

This changes all of the comments in the requester module into docstrings. It also removes any trailing whitespace, removes any unnecessary backslashes, deletes spaces before colons (PEP 8 violation), adds spaces after commas (PEP 8 violation), puts spaces after the '#' symbol on comments, fixes spelling on comments and tries to expand the docstrings where appropriate.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'GTG/core/requester.py'
--- GTG/core/requester.py 2009-03-29 19:32:59 +0000
+++ GTG/core/requester.py 2009-07-13 03:50:25 +0000
@@ -19,182 +19,238 @@
1919
2020
21from GTG.tools.listes import *21from GTG.tools.listes import *
22#Requester is a pure View object. It will not do anything but it will22
23#be used by any Interface to handle the requests to the datastore23
24
25#There could be multiple requester. It means that a requester should never
26#Hold any data except a reference to its datastore.
27class Requester :24class Requester :
28 def __init__(self,datastore) :25 """A view on a GTG datastore.
26
27 `Requester` is a stateless object that simply provides a nice API for user
28 interfaces to use for datastore operations.
29
30 Multiple `Requester`s can exist on the same datastore, so they should
31 never have state of their own.
32 """
33
34 def __init__(self, datastore):
35 """Construct a `Requester`."""
29 self.ds = datastore36 self.ds = datastore
30 37
31 def connect(self,signal,func) :38 def connect(self, signal, func):
32 self.ds.connect(signal,func)39 self.ds.connect(signal, func)
33 40
34 ############## Tasks ##########################41 ############## Tasks ##########################
35 ###############################################42 ###############################################
3643
3744 def has_task(self, tid):
38 #Return True if the task exists45 """Does the task 'tid' exist?"""
39 def has_task(self,tid) :
40 return self.ds.has_task(tid)46 return self.ds.has_task(tid)
41 47
42 #Get the task with the given pid48 def get_task(self, tid):
43 #If the task doesn't exist, we create it and force the pid49 """Get the task with the given 'tid'.
44 def get_task(self,tid) :50
51 If no such task exists, create it and force the tid to be 'tid'.
52
53 :param tid: The task id.
54 :return: A task.
55 """
45 task = self.ds.get_task(tid)56 task = self.ds.get_task(tid)
46 return task57 return task
47 58
48 #Pid is the project in which the new task will be created59 def new_task(self, pid=None, tags=None, newtask=True):
49 #MODIFICATION class (the data will be modified)60 """Create a new task.
50 def new_task(self,pid=None,tags=None,newtask=True) :61
51 task = self.ds.new_task(pid=pid,newtask=newtask)62 Note: this modifies the datastore.
52 if tags :63
53 for t in tags :64 :param pid: The project where the new task will be created.
65 :param tags: The tags for the new task. If not provided, then the
66 task will have no tags.
67 :param newtask: 'True' if this is creating a task, 'False' if
68 importing an existing task.
69 """
70 # XXX: The docs don't make it clear why you'd ever need to pass in
71 # newtask or how newtask is used.
72 task = self.ds.new_task(pid=pid, newtask=newtask)
73 if tags:
74 for t in tags:
54 task.add_tag(t.get_name())75 task.add_tag(t.get_name())
55 return task76 return task
56 77
57 78 def delete_task(self, tid):
58 #MODIFICATION class (the data will be modified)79 """Delete the task 'tid'.
59 def delete_task(self,tid) :80
81 Note: this modifies the datastore.
82
83 :param tid: The id of the task to be deleted.
84 """
60 self.ds.delete_task(tid)85 self.ds.delete_task(tid)
61 86
62 #Return a list of active tasks tid87 def get_tasks_list(self, tags=None, status=["Active"], notag_only=False,
63 #88 started_only=True, is_root=False):
64 # tags = []. All tasks will have at least one of those tags.89 """Return a list of tids of tasks.
65 # If None, all tasks are eligible90
66 #91 By default, returns a list of all the tids of all active tasks.
67 # Status = [] : a list of status to choose from92
68 # available status are : Active - Done - Dismiss - Deleted93 :param tags: A list of tags. If provided, restricts the list of
69 # If none, all tasks are eligible94 returned tasks to those that have one or more of these tags.
70 #95 :param status: A list of statuses. If provided, restricts the list of
71 # notag_only : if True, only tasks without tags are selected96 returned tasks to those that are in one of these states.
72 #97 :param notag_only: If True, only include tasks without tags. Defaults
73 # started_only : if True, only tasks with an already passed started date are selected98 to False.
74 # (task with no startdate are considered as started)99 :param started_only: If True, only include tasks that have been
75 #100 started. That is, tasks that have an already-passed start date or
76 # is_root : if True, only tasks that have no parent in the current selection101 tasks with no startdate. Defaults to 'True'.
77 # are eligible. If False, all tasks are eligible102 :param is_root: If True, only include tasks that have no parent in the
78 def get_tasks_list(self,tags=None, status=["Active"],notag_only=False,\103 current selection. Defaults to False.
79 started_only=True,is_root=False) :104
105 :return: A list of task ids (tids).
106 """
80 l_tasks = []107 l_tasks = []
81 for tid in self.ds.all_tasks() :108 for tid in self.ds.all_tasks():
82 task = self.get_task(tid)109 task = self.get_task(tid)
83 if task and not task.is_loaded() :110 if task and not task.is_loaded():
84 task = None111 task = None
85 #This is status filtering112 # This is status filtering.
86 if task and not task.get_status() in status :113 if task and not task.get_status() in status:
87 task = None114 task = None
88 #This is tag filtering115 # This is tag filtering.
89 #If we still have a task and we need to filter tags116 # If we still have a task and we need to filter tags
90 #(if tags is None, this test is skipped)117 # (if tags is None, this test is skipped)
91 if task and tags :118 if task and tags:
92 if not task.has_tags(tags) :119 if not task.has_tags(tags):
93 task = None120 task = None
94 #Checking here the is_root because it has sense only with tags121 # Checking here the is_root because it has sense only with
95 elif is_root and task.has_parents(tag=tags) :122 # tags.
96 task = None123 elif is_root and task.has_parents(tag=tags):
97 #If tags = [], we still check the is_root124 task = None
98 elif task and is_root :125 #If tags = [], we still check the is_root.
99 if task.has_parents() :126 elif task and is_root:
100 #We accept children of a note127 if task.has_parents():
101 for p in task.get_parents() :128 # We accept children of a note.
129 for p in task.get_parents():
102 pp = self.get_task(p)130 pp = self.get_task(p)
103 if pp.get_status() != "Note" :131 if pp.get_status() != "Note":
104 task = None132 task = None
105 #Now checking if it has no tag133 # Now checking if it has no tag.
106 if task and notag_only :134 if task and notag_only:
107 if not task.has_tags(notag_only=notag_only) :135 if not task.has_tags(notag_only=notag_only):
108 task = None136 task = None
109 #This is started filtering137 # This is started filtering.
110 if task and started_only :138 if task and started_only:
111 if not task.is_started() :139 if not task.is_started():
112 task = None140 task = None
113 141
114 #If we still have a task, we return it142 # If we still have a task, we return it.
115 if task :143 if task:
116 l_tasks.append(tid)144 l_tasks.append(tid)
117 return l_tasks145 return l_tasks
118 146
119 #Workable means that the task have no pending subtasks and can be done directly147 def get_active_tasks_list(self, tags=None, notag_only=False,
120 #It also means that all tags are to be "workview" tags (which is the default for tags)148 started_only=True, is_root=False,
121 #Except if the tag is explicitely selected149 workable=False):
122 def get_active_tasks_list(self,tags=None,notag_only=False,\150 """Return a list of task ids for all active tasks.
123 started_only=True,is_root=False,workable=False) :151
152 See `get_tasks_list` for more information about the parameters.
153
154 :param workable: If True, then only include tasks with no pending
155 subtasks and that can be done directly and exclude any tasks that
156 have a 'nonworkview' tag which is not explicitly provided in the
157 'tags' parameter. Defaults to False.
158 """
124 l_tasks = []159 l_tasks = []
125 if workable :160 if workable:
126 nonwork_tag = self.ds.get_tagstore().get_all_tags(\161 nonwork_tag = self.ds.get_tagstore().get_all_tags(
127 attname="nonworkview",\162 attname="nonworkview", attvalue="True")
128 attvalue="True")163 # We build the list of tags we will skip.
129 #nonwork_tag = []164 for nwtag in nonwork_tag:
130 #We build the list of tags we will skip165 # If the tag is explicitly selected, it doesn't go in the
131 for nwtag in nonwork_tag :166 # nonwork_tag.
132 #If the tag is explicitely selected, it doesn't go in the167 if tags and nwtag in tags:
133 #nonwork_tag
134 if tags and nwtag in tags :
135 nonwork_tag.remove(nwtag)168 nonwork_tag.remove(nwtag)
136 #We build the task list169 # We build the task list.
137 temp_tasks = self.get_active_tasks_list(tags=tags, notag_only=notag_only,\170 temp_tasks = self.get_active_tasks_list(
138 started_only=True,is_root=False,workable=False)171 tags=tags, notag_only=notag_only, started_only=True,
139 #Now we verify that the tasks are workable and doesn't have172 is_root=False, workable=False)
140 #a nonwork_tag.173 # Now we verify that the tasks are workable and don't have a
141 for tid in temp_tasks :174 # nonwork_tag.
175 for tid in temp_tasks:
142 t = self.get_task(tid)176 t = self.get_task(tid)
143 if t and t.is_workable() :177 if t and t.is_workable():
144 if len(nonwork_tag) == 0 :178 if len(nonwork_tag) == 0:
145 l_tasks.append(tid)179 l_tasks.append(tid)
146 elif not t.has_tags(nonwork_tag) :180 elif not t.has_tags(nonwork_tag):
147 l_tasks.append(tid)181 l_tasks.append(tid)
148 return l_tasks182 return l_tasks
149 else :183 else:
150 active = ["Active"]184 active = ["Active"]
151 temp_tasks = self.get_tasks_list(tags=tags,status=active,\185 temp_tasks = self.get_tasks_list(
152 notag_only=notag_only,started_only=started_only,is_root=is_root)186 tags=tags, status=active, notag_only=notag_only,
153 for t in temp_tasks :187 started_only=started_only, is_root=is_root)
188 for t in temp_tasks:
154 l_tasks.append(t)189 l_tasks.append(t)
155 return l_tasks190 return l_tasks
156 191
157 def get_closed_tasks_list(self,tags=None,notag_only=False,\192 def get_closed_tasks_list(self, tags=None, notag_only=False,
158 started_only=False,is_root=False) :193 started_only=False, is_root=False):
159 closed = ["Done","Dismiss","Deleted"]194 """Return a list of task ids for closed tasks.
160 return self.get_tasks_list(tags=tags,status=closed,\195
161 notag_only=notag_only,started_only=started_only,is_root=is_root)196 "Closed" means either "done", "dismissed" or "deleted".
162 197
163 def get_notes_list(self,tags=None,notag_only=False) :198 See `get_tasks_list` for more information about the parameters.
199 """
200 closed = ["Done", "Dismiss", "Deleted"]
201 return self.get_tasks_list(
202 tags=tags, status=closed, notag_only=notag_only,
203 started_only=started_only, is_root=is_root)
204
205 def get_notes_list(self, tags=None, notag_only=False):
206 """Return a list of task ids for notes.
207
208 See `get_tasks_list` for more information about the parameters.
209 """
164 note = ["Note"]210 note = ["Note"]
165 return self.get_tasks_list(tags=tags,status=note,\211 return self.get_tasks_list(
166 notag_only=notag_only,started_only=False,is_root=False)212 tags=tags, status=note, notag_only=notag_only, started_only=False,
167 213 is_root=False)
168 214
169 215
170 ############### Tags ##########################216 ############### Tags ##########################
171 ############################################### 217 ###############################################
172 218
173 #MODIFICATION219 def new_tag(self, tagname):
174 def new_tag(self,tagname) :220 """Create a new tag called 'tagname'.
221
222 Note: this modifies the datastore.
223
224 :param tagname: The name of the new tag.
225 :return: The newly-created tag.
226 """
175 return self.ds.get_tagstore().new_tag(tagname)227 return self.ds.get_tagstore().new_tag(tagname)
176 228
177 def get_tag(self,tagname) :229 def get_tag(self, tagname):
178 return self.ds.get_tagstore().get_tag(tagname)230 return self.ds.get_tagstore().get_tag(tagname)
179 231
180 #Not used currently because it returns every tag that was ever used
181 def get_all_tags(self):232 def get_all_tags(self):
233 """Return a list of every tag that was ever used."""
234 # XXX: Not actually used.
182 return returnlist(self.ds.get_tagstore().get_all_tags())235 return returnlist(self.ds.get_tagstore().get_all_tags())
183 236
184 def get_notag_tag(self) :237 def get_notag_tag(self):
185 return self.ds.get_tagstore().get_notag_tag()238 return self.ds.get_tagstore().get_notag_tag()
186 def get_alltag_tag(self) :239
240 def get_alltag_tag(self):
187 return self.ds.get_tagstore().get_alltag_tag()241 return self.ds.get_tagstore().get_alltag_tag()
188 242
189 243 def get_used_tags(self):
190 #return only tags that are currently used in a task244 """Return tags currently used by a task.
191 #FIXME it should be only active and visible tasks245
192 def get_used_tags(self) :246 :return: A list of tags used by a task.
247 """
248 # FIXME: it should be only active and visible tasks.
193 l = []249 l = []
194 for tid in self.ds.all_tasks():250 for tid in self.ds.all_tasks():
195 t = self.get_task(tid)251 t = self.get_task(tid)
196 if t :252 if t:
197 for tag in t.get_tags() :253 for tag in t.get_tags():
198 if tag not in l: l.append(tag)254 if tag not in l:
255 l.append(tag)
199 return l256 return l
200

Subscribers

People subscribed via source and target branches

to status/vote changes: