← Back to team overview

gtg team mailing list archive

[Merge] lp:~bertrand-rousseau/gtg/get_due_date into lp:gtg

 

Bertrand Rousseau has proposed merging lp:~bertrand-rousseau/gtg/get_due_date into lp:gtg.

Requested reviews:
  Gtg developers (gtg)

For more details, see:
https://code.launchpad.net/~bertrand-rousseau/gtg/get_due_date/+merge/109534



    Remove the implicit interpretation of due date through get_due_date:

    With this patch, GTG uses the actual value of the task object's due date
    when accessing it through get_due_date.

    It seems to me that it's saner than the current mechanism that relies
    on an on-the-fly interpretation when accessing the due date. Indeed,
    this can hide mismatches between the stored value and the returned due
    date.

    Typical example: a parent task with due date A and a child task
    with no due date: the child has no due date set, but get_due_date
    will return 'A'.

    Now, you get what you really have stored, but therefore it's up to the
    code to make sure you store a correct value!

    Therefore, from now on all code dealing with tasks due dates and
    tasks relations MUST be written so that the due dates are always set
    correctly (=they respect the date constraints). This is actually not
    a big deal since most of this is actually cared for by set_due_date().

    set_due_date() has thus been slightly modified (pursuing previous
    work by Nimit Shah), so that when you set/update the due date, all
    related tasks dates are modified to respect the constraints.

    However, D&D'ing tasks can still create situations where a parent task due
    date and its child due date are not compatible. This cannot be fixed
    now since D&D is done in liblarch and there are no hooks available
    from the GTG code to handle tasks updates when reparenting them...

    This patch also means that from now on, undefined due date are presented
    explicitely in the list as not being set, even when constrained by a
    parent. Therefore, it's up to the user to explicitely define it if needed
    (which she/he can do by directly setting the due date of the task, or by
    setting the due date of the parent). It's possibly more work for her/him,
    but at least the outcome is clear and therefore predictable/usable: explicit
    is always better than implicit.

    Note: some code from the task editor that checks if the start and due
    date are compatible has been removed, since it's done in set_due_date
    now.

-- 
https://code.launchpad.net/~bertrand-rousseau/gtg/get_due_date/+merge/109534
Your team Gtg developers is requested to review the proposed merge of lp:~bertrand-rousseau/gtg/get_due_date into lp:gtg.
=== modified file 'GTG/core/task.py'
--- GTG/core/task.py	2012-06-09 13:48:34 +0000
+++ GTG/core/task.py	2012-06-10 19:14:20 +0000
@@ -245,33 +245,46 @@
         self.last_modified = modified
 
     def set_due_date(self, fulldate):
-        self.due_date=Date(fulldate)
-        if self.get_start_date() > Date(fulldate) and self.get_start_date() != Date.no_date():
+        fulldate_obj = Date(fulldate)
+        self.prev_due_date=self.due_date
+        self.due_date=fulldate_obj
+        # if the task's start date happens later than the 
+        # new due date, we update it
+        if self.get_start_date() != Date.no_date() and \
+           self.get_start_date() > fulldate_obj:
             self.set_start_date(fulldate)
-        if Date(fulldate)!= Date.no_date():
+        if fulldate_obj != Date.no_date():
+            # if the parent's due date happens before the task's new
+            # due date, we update it
             for par_id in self.parents:
                 par = self.req.get_task(par_id)
-                if par.due_date != Date.no_date() and par.due_date < Date(fulldate):
+                if par.get_due_date() != Date.no_date() and \
+                   par.get_due_date() < fulldate_obj:
                     par.set_due_date(fulldate)
+            # the current task being one of its children's parents, we must
+            # apply the constraints on their due/start dates as well
             for sub_id in self.children:
                 sub=self.req.get_task(sub_id)
-                if sub.due_date > Date(fulldate) and sub.due_date != Date.no_date():
-                    sub.set_due_date(fulldate)
-                if sub.get_start_date() != Date.no_date() and sub.get_start_date() > Date(fulldate):
+                # child's due date is not set, we use the task's new 
+                # due date
+                if sub.get_due_date() == Date.no_date():
+                    sub.set_due_date(fulldate)
+                # child's due date happens later than the task's: we
+                # update it to the task's new due date
+                # (= the new most restrictive)
+                if sub.get_due_date() != Date.no_date() and \
+                   sub.get_due_date() > fulldate_obj:
+                    sub.set_due_date(fulldate)
+                # if the child's start date happens later than
+                # the task's new due date, we update it
+                if sub.get_start_date() != Date.no_date() and \
+                   sub.get_start_date() > fulldate_obj:
                     sub.set_start_date(fulldate)
-        self.sync()
+            self.sync()
 
     def get_due_date(self):
-        """ Due date return the most urgent date of all parents """
-        zedate = self.due_date
-
-        for par in self.get_parents():
-            # compare with the parent's due date
-            pardate = self.req.get_task(par).get_due_date()
-            if pardate and zedate > pardate:
-                zedate = pardate
-
-        return zedate
+        """ Returns the due date, which always respects all constraints """
+        return self.due_date
 
     def set_start_date(self, fulldate):
         self.start_date = Date(fulldate)

=== modified file 'GTG/gtk/editor/editor.py'
--- GTG/gtk/editor/editor.py	2012-05-20 18:14:23 +0000
+++ GTG/gtk/editor/editor.py	2012-06-10 19:14:20 +0000
@@ -356,13 +356,6 @@
                 self.task.set_due_date(datetoset)
             elif data == "closed":
                 self.task.set_closed_date(datetoset)
-
-            # Set the due date to be equal to the start date
-            # when it happens that the start date is later than the due date
-            start_date = self.task.get_start_date()
-            due_date = self.task.get_due_date()
-            if start_date and (start_date > due_date):
-                self.task.set_due_date(self.task.get_start_date())
         else:
             #We should write in red in the entry if the date is not valid
             widget.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("#F00"))
@@ -371,12 +364,7 @@
     def on_date_pressed(self, widget, date_kind):
         """Called when a date-changing button is clicked."""
         if date_kind == GTGCalendar.DATE_KIND_DUE:
-            date = self.task.get_due_date()
-            start_date = self.task.get_start_date()
-            due_before_start = start_date and start_date > date
-
-            if not date or due_before_start:
-                date = self.task.get_start_date()
+            date = self.task.get_start_date()
         elif date_kind == GTGCalendar.DATE_KIND_START:
             date = self.task.get_start_date()
         elif date_kind == GTGCalendar.DATE_KIND_CLOSED: