Merge lp:~jml/gtg/docstrings-for-requester into lp:~gtg/gtg/old-trunk
- docstrings-for-requester
- Merge into 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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Gtg developers | Pending | ||
Review via email:
|
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Jonathan Lange (jml) wrote : | # |
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'GTG/core/requester.py' | |||
2 | --- GTG/core/requester.py 2009-03-29 19:32:59 +0000 | |||
3 | +++ GTG/core/requester.py 2009-07-13 03:50:25 +0000 | |||
4 | @@ -19,182 +19,238 @@ | |||
5 | 19 | 19 | ||
6 | 20 | 20 | ||
7 | 21 | from GTG.tools.listes import * | 21 | from GTG.tools.listes import * |
13 | 22 | #Requester is a pure View object. It will not do anything but it will | 22 | |
14 | 23 | #be used by any Interface to handle the requests to the datastore | 23 | |
10 | 24 | |||
11 | 25 | #There could be multiple requester. It means that a requester should never | ||
12 | 26 | #Hold any data except a reference to its datastore. | ||
15 | 27 | class Requester : | 24 | class Requester : |
17 | 28 | def __init__(self,datastore) : | 25 | """A view on a GTG datastore. |
18 | 26 | |||
19 | 27 | `Requester` is a stateless object that simply provides a nice API for user | ||
20 | 28 | interfaces to use for datastore operations. | ||
21 | 29 | |||
22 | 30 | Multiple `Requester`s can exist on the same datastore, so they should | ||
23 | 31 | never have state of their own. | ||
24 | 32 | """ | ||
25 | 33 | |||
26 | 34 | def __init__(self, datastore): | ||
27 | 35 | """Construct a `Requester`.""" | ||
28 | 29 | self.ds = datastore | 36 | self.ds = datastore |
33 | 30 | 37 | ||
34 | 31 | def connect(self,signal,func) : | 38 | def connect(self, signal, func): |
35 | 32 | self.ds.connect(signal,func) | 39 | self.ds.connect(signal, func) |
36 | 33 | 40 | ||
37 | 34 | ############## Tasks ########################## | 41 | ############## Tasks ########################## |
38 | 35 | ############################################### | 42 | ############################################### |
39 | 36 | 43 | ||
43 | 37 | 44 | def has_task(self, tid): | |
44 | 38 | #Return True if the task exists | 45 | """Does the task 'tid' exist?""" |
42 | 39 | def has_task(self,tid) : | ||
45 | 40 | return self.ds.has_task(tid) | 46 | return self.ds.has_task(tid) |
50 | 41 | 47 | ||
51 | 42 | #Get the task with the given pid | 48 | def get_task(self, tid): |
52 | 43 | #If the task doesn't exist, we create it and force the pid | 49 | """Get the task with the given 'tid'. |
53 | 44 | def get_task(self,tid) : | 50 | |
54 | 51 | If no such task exists, create it and force the tid to be 'tid'. | ||
55 | 52 | |||
56 | 53 | :param tid: The task id. | ||
57 | 54 | :return: A task. | ||
58 | 55 | """ | ||
59 | 45 | task = self.ds.get_task(tid) | 56 | task = self.ds.get_task(tid) |
60 | 46 | return task | 57 | return task |
68 | 47 | 58 | ||
69 | 48 | #Pid is the project in which the new task will be created | 59 | def new_task(self, pid=None, tags=None, newtask=True): |
70 | 49 | #MODIFICATION class (the data will be modified) | 60 | """Create a new task. |
71 | 50 | def new_task(self,pid=None,tags=None,newtask=True) : | 61 | |
72 | 51 | task = self.ds.new_task(pid=pid,newtask=newtask) | 62 | Note: this modifies the datastore. |
73 | 52 | if tags : | 63 | |
74 | 53 | for t in tags : | 64 | :param pid: The project where the new task will be created. |
75 | 65 | :param tags: The tags for the new task. If not provided, then the | ||
76 | 66 | task will have no tags. | ||
77 | 67 | :param newtask: 'True' if this is creating a task, 'False' if | ||
78 | 68 | importing an existing task. | ||
79 | 69 | """ | ||
80 | 70 | # XXX: The docs don't make it clear why you'd ever need to pass in | ||
81 | 71 | # newtask or how newtask is used. | ||
82 | 72 | task = self.ds.new_task(pid=pid, newtask=newtask) | ||
83 | 73 | if tags: | ||
84 | 74 | for t in tags: | ||
85 | 54 | task.add_tag(t.get_name()) | 75 | task.add_tag(t.get_name()) |
86 | 55 | return task | 76 | return task |
91 | 56 | 77 | ||
92 | 57 | 78 | def delete_task(self, tid): | |
93 | 58 | #MODIFICATION class (the data will be modified) | 79 | """Delete the task 'tid'. |
94 | 59 | def delete_task(self,tid) : | 80 | |
95 | 81 | Note: this modifies the datastore. | ||
96 | 82 | |||
97 | 83 | :param tid: The id of the task to be deleted. | ||
98 | 84 | """ | ||
99 | 60 | self.ds.delete_task(tid) | 85 | self.ds.delete_task(tid) |
119 | 61 | 86 | ||
120 | 62 | #Return a list of active tasks tid | 87 | def get_tasks_list(self, tags=None, status=["Active"], notag_only=False, |
121 | 63 | # | 88 | started_only=True, is_root=False): |
122 | 64 | # tags = []. All tasks will have at least one of those tags. | 89 | """Return a list of tids of tasks. |
123 | 65 | # If None, all tasks are eligible | 90 | |
124 | 66 | # | 91 | By default, returns a list of all the tids of all active tasks. |
125 | 67 | # Status = [] : a list of status to choose from | 92 | |
126 | 68 | # available status are : Active - Done - Dismiss - Deleted | 93 | :param tags: A list of tags. If provided, restricts the list of |
127 | 69 | # If none, all tasks are eligible | 94 | returned tasks to those that have one or more of these tags. |
128 | 70 | # | 95 | :param status: A list of statuses. If provided, restricts the list of |
129 | 71 | # notag_only : if True, only tasks without tags are selected | 96 | returned tasks to those that are in one of these states. |
130 | 72 | # | 97 | :param notag_only: If True, only include tasks without tags. Defaults |
131 | 73 | # started_only : if True, only tasks with an already passed started date are selected | 98 | to False. |
132 | 74 | # (task with no startdate are considered as started) | 99 | :param started_only: If True, only include tasks that have been |
133 | 75 | # | 100 | started. That is, tasks that have an already-passed start date or |
134 | 76 | # is_root : if True, only tasks that have no parent in the current selection | 101 | tasks with no startdate. Defaults to 'True'. |
135 | 77 | # are eligible. If False, all tasks are eligible | 102 | :param is_root: If True, only include tasks that have no parent in the |
136 | 78 | def get_tasks_list(self,tags=None, status=["Active"],notag_only=False,\ | 103 | current selection. Defaults to False. |
137 | 79 | started_only=True,is_root=False) : | 104 | |
138 | 105 | :return: A list of task ids (tids). | ||
139 | 106 | """ | ||
140 | 80 | l_tasks = [] | 107 | l_tasks = [] |
142 | 81 | for tid in self.ds.all_tasks() : | 108 | for tid in self.ds.all_tasks(): |
143 | 82 | task = self.get_task(tid) | 109 | task = self.get_task(tid) |
163 | 83 | if task and not task.is_loaded() : | 110 | if task and not task.is_loaded(): |
164 | 84 | task = None | 111 | task = None |
165 | 85 | #This is status filtering | 112 | # This is status filtering. |
166 | 86 | if task and not task.get_status() in status : | 113 | if task and not task.get_status() in status: |
167 | 87 | task = None | 114 | task = None |
168 | 88 | #This is tag filtering | 115 | # This is tag filtering. |
169 | 89 | #If we still have a task and we need to filter tags | 116 | # If we still have a task and we need to filter tags |
170 | 90 | #(if tags is None, this test is skipped) | 117 | # (if tags is None, this test is skipped) |
171 | 91 | if task and tags : | 118 | if task and tags: |
172 | 92 | if not task.has_tags(tags) : | 119 | if not task.has_tags(tags): |
173 | 93 | task = None | 120 | task = None |
174 | 94 | #Checking here the is_root because it has sense only with tags | 121 | # Checking here the is_root because it has sense only with |
175 | 95 | elif is_root and task.has_parents(tag=tags) : | 122 | # tags. |
176 | 96 | task = None | 123 | elif is_root and task.has_parents(tag=tags): |
177 | 97 | #If tags = [], we still check the is_root | 124 | task = None |
178 | 98 | elif task and is_root : | 125 | #If tags = [], we still check the is_root. |
179 | 99 | if task.has_parents() : | 126 | elif task and is_root: |
180 | 100 | #We accept children of a note | 127 | if task.has_parents(): |
181 | 101 | for p in task.get_parents() : | 128 | # We accept children of a note. |
182 | 129 | for p in task.get_parents(): | ||
183 | 102 | pp = self.get_task(p) | 130 | pp = self.get_task(p) |
185 | 103 | if pp.get_status() != "Note" : | 131 | if pp.get_status() != "Note": |
186 | 104 | task = None | 132 | task = None |
198 | 105 | #Now checking if it has no tag | 133 | # Now checking if it has no tag. |
199 | 106 | if task and notag_only : | 134 | if task and notag_only: |
200 | 107 | if not task.has_tags(notag_only=notag_only) : | 135 | if not task.has_tags(notag_only=notag_only): |
201 | 108 | task = None | 136 | task = None |
202 | 109 | #This is started filtering | 137 | # This is started filtering. |
203 | 110 | if task and started_only : | 138 | if task and started_only: |
204 | 111 | if not task.is_started() : | 139 | if not task.is_started(): |
205 | 112 | task = None | 140 | task = None |
206 | 113 | 141 | ||
207 | 114 | #If we still have a task, we return it | 142 | # If we still have a task, we return it. |
208 | 115 | if task : | 143 | if task: |
209 | 116 | l_tasks.append(tid) | 144 | l_tasks.append(tid) |
210 | 117 | return l_tasks | 145 | return l_tasks |
217 | 118 | 146 | ||
218 | 119 | #Workable means that the task have no pending subtasks and can be done directly | 147 | def get_active_tasks_list(self, tags=None, notag_only=False, |
219 | 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, |
220 | 121 | #Except if the tag is explicitely selected | 149 | workable=False): |
221 | 122 | def get_active_tasks_list(self,tags=None,notag_only=False,\ | 150 | """Return a list of task ids for all active tasks. |
222 | 123 | started_only=True,is_root=False,workable=False) : | 151 | |
223 | 152 | See `get_tasks_list` for more information about the parameters. | ||
224 | 153 | |||
225 | 154 | :param workable: If True, then only include tasks with no pending | ||
226 | 155 | subtasks and that can be done directly and exclude any tasks that | ||
227 | 156 | have a 'nonworkview' tag which is not explicitly provided in the | ||
228 | 157 | 'tags' parameter. Defaults to False. | ||
229 | 158 | """ | ||
230 | 124 | l_tasks = [] | 159 | l_tasks = [] |
241 | 125 | if workable : | 160 | if workable: |
242 | 126 | nonwork_tag = self.ds.get_tagstore().get_all_tags(\ | 161 | nonwork_tag = self.ds.get_tagstore().get_all_tags( |
243 | 127 | attname="nonworkview",\ | 162 | attname="nonworkview", attvalue="True") |
244 | 128 | attvalue="True") | 163 | # We build the list of tags we will skip. |
245 | 129 | #nonwork_tag = [] | 164 | for nwtag in nonwork_tag: |
246 | 130 | #We build the list of tags we will skip | 165 | # If the tag is explicitly selected, it doesn't go in the |
247 | 131 | for nwtag in nonwork_tag : | 166 | # nonwork_tag. |
248 | 132 | #If the tag is explicitely selected, it doesn't go in the | 167 | if tags and nwtag in tags: |
239 | 133 | #nonwork_tag | ||
240 | 134 | if tags and nwtag in tags : | ||
249 | 135 | nonwork_tag.remove(nwtag) | 168 | nonwork_tag.remove(nwtag) |
256 | 136 | #We build the task list | 169 | # We build the task list. |
257 | 137 | temp_tasks = self.get_active_tasks_list(tags=tags, notag_only=notag_only,\ | 170 | temp_tasks = self.get_active_tasks_list( |
258 | 138 | started_only=True,is_root=False,workable=False) | 171 | tags=tags, notag_only=notag_only, started_only=True, |
259 | 139 | #Now we verify that the tasks are workable and doesn't have | 172 | is_root=False, workable=False) |
260 | 140 | #a nonwork_tag. | 173 | # Now we verify that the tasks are workable and don't have a |
261 | 141 | for tid in temp_tasks : | 174 | # nonwork_tag. |
262 | 175 | for tid in temp_tasks: | ||
263 | 142 | t = self.get_task(tid) | 176 | t = self.get_task(tid) |
266 | 143 | if t and t.is_workable() : | 177 | if t and t.is_workable(): |
267 | 144 | if len(nonwork_tag) == 0 : | 178 | if len(nonwork_tag) == 0: |
268 | 145 | l_tasks.append(tid) | 179 | l_tasks.append(tid) |
270 | 146 | elif not t.has_tags(nonwork_tag) : | 180 | elif not t.has_tags(nonwork_tag): |
271 | 147 | l_tasks.append(tid) | 181 | l_tasks.append(tid) |
272 | 148 | return l_tasks | 182 | return l_tasks |
274 | 149 | else : | 183 | else: |
275 | 150 | active = ["Active"] | 184 | active = ["Active"] |
279 | 151 | temp_tasks = self.get_tasks_list(tags=tags,status=active,\ | 185 | temp_tasks = self.get_tasks_list( |
280 | 152 | notag_only=notag_only,started_only=started_only,is_root=is_root) | 186 | tags=tags, status=active, notag_only=notag_only, |
281 | 153 | for t in temp_tasks : | 187 | started_only=started_only, is_root=is_root) |
282 | 188 | for t in temp_tasks: | ||
283 | 154 | l_tasks.append(t) | 189 | l_tasks.append(t) |
284 | 155 | return l_tasks | 190 | return l_tasks |
293 | 156 | 191 | ||
294 | 157 | def get_closed_tasks_list(self,tags=None,notag_only=False,\ | 192 | def get_closed_tasks_list(self, tags=None, notag_only=False, |
295 | 158 | started_only=False,is_root=False) : | 193 | started_only=False, is_root=False): |
296 | 159 | closed = ["Done","Dismiss","Deleted"] | 194 | """Return a list of task ids for closed tasks. |
297 | 160 | return self.get_tasks_list(tags=tags,status=closed,\ | 195 | |
298 | 161 | notag_only=notag_only,started_only=started_only,is_root=is_root) | 196 | "Closed" means either "done", "dismissed" or "deleted". |
299 | 162 | 197 | ||
300 | 163 | def get_notes_list(self,tags=None,notag_only=False) : | 198 | See `get_tasks_list` for more information about the parameters. |
301 | 199 | """ | ||
302 | 200 | closed = ["Done", "Dismiss", "Deleted"] | ||
303 | 201 | return self.get_tasks_list( | ||
304 | 202 | tags=tags, status=closed, notag_only=notag_only, | ||
305 | 203 | started_only=started_only, is_root=is_root) | ||
306 | 204 | |||
307 | 205 | def get_notes_list(self, tags=None, notag_only=False): | ||
308 | 206 | """Return a list of task ids for notes. | ||
309 | 207 | |||
310 | 208 | See `get_tasks_list` for more information about the parameters. | ||
311 | 209 | """ | ||
312 | 164 | note = ["Note"] | 210 | note = ["Note"] |
318 | 165 | return self.get_tasks_list(tags=tags,status=note,\ | 211 | return self.get_tasks_list( |
319 | 166 | notag_only=notag_only,started_only=False,is_root=False) | 212 | tags=tags, status=note, notag_only=notag_only, started_only=False, |
320 | 167 | 213 | is_root=False) | |
321 | 168 | 214 | ||
322 | 169 | 215 | ||
323 | 170 | ############### Tags ########################## | 216 | ############### Tags ########################## |
328 | 171 | ############################################### | 217 | ############################################### |
329 | 172 | 218 | ||
330 | 173 | #MODIFICATION | 219 | def new_tag(self, tagname): |
331 | 174 | def new_tag(self,tagname) : | 220 | """Create a new tag called 'tagname'. |
332 | 221 | |||
333 | 222 | Note: this modifies the datastore. | ||
334 | 223 | |||
335 | 224 | :param tagname: The name of the new tag. | ||
336 | 225 | :return: The newly-created tag. | ||
337 | 226 | """ | ||
338 | 175 | return self.ds.get_tagstore().new_tag(tagname) | 227 | return self.ds.get_tagstore().new_tag(tagname) |
341 | 176 | 228 | ||
342 | 177 | def get_tag(self,tagname) : | 229 | def get_tag(self, tagname): |
343 | 178 | return self.ds.get_tagstore().get_tag(tagname) | 230 | return self.ds.get_tagstore().get_tag(tagname) |
346 | 179 | 231 | ||
345 | 180 | #Not used currently because it returns every tag that was ever used | ||
347 | 181 | def get_all_tags(self): | 232 | def get_all_tags(self): |
348 | 233 | """Return a list of every tag that was ever used.""" | ||
349 | 234 | # XXX: Not actually used. | ||
350 | 182 | return returnlist(self.ds.get_tagstore().get_all_tags()) | 235 | return returnlist(self.ds.get_tagstore().get_all_tags()) |
353 | 183 | 236 | ||
354 | 184 | def get_notag_tag(self) : | 237 | def get_notag_tag(self): |
355 | 185 | return self.ds.get_tagstore().get_notag_tag() | 238 | return self.ds.get_tagstore().get_notag_tag() |
357 | 186 | def get_alltag_tag(self) : | 239 | |
358 | 240 | def get_alltag_tag(self): | ||
359 | 187 | return self.ds.get_tagstore().get_alltag_tag() | 241 | return self.ds.get_tagstore().get_alltag_tag() |
365 | 188 | 242 | ||
366 | 189 | 243 | def get_used_tags(self): | |
367 | 190 | #return only tags that are currently used in a task | 244 | """Return tags currently used by a task. |
368 | 191 | #FIXME it should be only active and visible tasks | 245 | |
369 | 192 | def get_used_tags(self) : | 246 | :return: A list of tags used by a task. |
370 | 247 | """ | ||
371 | 248 | # FIXME: it should be only active and visible tasks. | ||
372 | 193 | l = [] | 249 | l = [] |
373 | 194 | for tid in self.ds.all_tasks(): | 250 | for tid in self.ds.all_tasks(): |
374 | 195 | t = self.get_task(tid) | 251 | t = self.get_task(tid) |
378 | 196 | if t : | 252 | if t: |
379 | 197 | for tag in t.get_tags() : | 253 | for tag in t.get_tags(): |
380 | 198 | if tag not in l: l.append(tag) | 254 | if tag not in l: |
381 | 255 | l.append(tag) | ||
382 | 199 | return l | 256 | return l |
383 | 200 |
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.