Cleaning up some further todos
[doneit] / src / rtm_view.py
index b986b3c..5f454a9 100644 (file)
@@ -9,7 +9,7 @@ import gtk
 import toolbox
 import gtk_toolbox
 import rtm_backend
-import rtmapi
+import rtm_api
 
 
 def abbreviate(text, expectedLen):
@@ -44,7 +44,7 @@ def abbreviate_url(url, domainLength, pathLength):
 
 def get_token(username, apiKey, secret):
        token = None
-       rtm = rtmapi.RTMapi(username, apiKey, secret, token)
+       rtm = rtm_api.RTMapi(username, apiKey, secret, token)
 
        authURL = rtm.getAuthURL()
        webbrowser.open(authURL)
@@ -87,7 +87,6 @@ class GtkRtMilk(object):
                self._projectsCombo = widgetTree.get_widget("projectsCombo")
                self._onListActivateId = 0
 
-               # @todo Need to figure out how to make the list sortable, especially with weird priority sorting
                self._itemList = gtk.ListStore(
                        gobject.TYPE_STRING, # id
                        gobject.TYPE_BOOLEAN, # is complete
@@ -183,7 +182,7 @@ class GtkRtMilk(object):
                                self._manager = rtm_backend.RtMilkManager(*credentials)
                                self._credentials = credentials
                                return # Login succeeded
-                       except rtmapi.AuthStateMachine.NoData:
+                       except rtm_api.AuthStateMachine.NoData:
                                # Login failed, grab new credentials
                                credentials = get_credentials(self._credentialsDialog)
 
@@ -283,19 +282,22 @@ class GtkRtMilk(object):
                # @todo Look into using a button for notes and links, and labels for all else
                currentProject = self._get_project()
                projId = self._manager.lookup_project(currentProject)["id"]
-               for taskDetails in self._manager.get_tasks_with_details(projId):
+               sortedTasks = list(self._manager.get_tasks_with_details(projId))
+               sortedTasks.sort(key = lambda taskDetails: (taskDetails["priority"].get_nothrow(1000), taskDetails["dueDate"].get_nothrow(datetime.datetime.max)))
+               for taskDetails in sortedTasks:
                        show = self._showCompleted if taskDetails["isCompleted"] else self._showIncomplete
                        if not show:
                                continue
                        id = taskDetails["id"]
                        isCompleted = taskDetails["isCompleted"]
                        name = abbreviate(taskDetails["name"], 100)
-                       priority = taskDetails["priority"]
-                       dueDescription = taskDetails["dueDate"]
-                       if dueDescription:
-                               dueDate = datetime.datetime.strptime(dueDescription, "%Y-%m-%dT%H:%M:%SZ")
+                       priority = str(taskDetails["priority"].get_nothrow(""))
+                       if taskDetails["dueDate"].is_good():
+                               dueDate = taskDetails["dueDate"].get()
+                               dueDescription = dueDate.strftime("%Y-%m-%d %H:%M:%S")
                                fuzzyDue = toolbox.to_fuzzy_date(dueDate)
                        else:
+                               dueDescription = ""
                                fuzzyDue = ""
 
                        linkDisplay = taskDetails["url"]
@@ -312,8 +314,7 @@ class GtkRtMilk(object):
                self._reset_task_list()
 
        def _on_item_select(self, treeView, path, viewColumn):
-               # @todo See if there is a way to get a right click / tap'n'hold for more task goodness
-               #       https://garage.maemo.org/plugins/wiki/index.php?TapAndHold&id=40&type=g
+               # @todo See if there is a way to use the new gtk_toolbox.ContextHandler
                taskId = self._itemList[path[0]][self.ID_IDX]
 
                if viewColumn is self._priorityColumn: