GTG

Merge lp:~jonathan-barnoud/gtg/quickadd into lp:~gtg/gtg/old-trunk

Proposed by Pititjo
Status: Merged
Merged at revision: not available
Proposed branch: lp:~jonathan-barnoud/gtg/quickadd
Merge into: lp:~gtg/gtg/old-trunk
Diff against target: None lines
To merge this branch: bzr merge lp:~jonathan-barnoud/gtg/quickadd
Reviewer Review Type Date Requested Status
Bertrand Rousseau (community) Needs Fixing
Review via email: mp+5070@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Pititjo (jonathan-barnoud) wrote :

Include due: and defer: attributes. The syntax is due:date or defer:date with date is yyyy-mm-dd or yyyymmdd or mmdd or today or a weekday name.

Revision history for this message
Bertrand Rousseau (bertrand-rousseau) wrote :

Very nice! I tested it and it works like a charm.

Just 2 remarks:

 - could you modify your patch to support i18n? Basically it means that you should put "_( )" around translatable strings. I'm thinking about day names here.
 - could you also support "tomorrow"? Since you already support "today", "tomorrow" would be quite nice too.

review: Needs Fixing
lp:~jonathan-barnoud/gtg/quickadd updated
225. By Pititjo

ajout de tomorrow et de la localisation pour due et defer dans le quick add

226. By Pititjo

add _() for attributes in quick add

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'GTG/taskbrowser/browser.py'
2--- GTG/taskbrowser/browser.py 2009-03-31 14:15:29 +0000
3+++ GTG/taskbrowser/browser.py 2009-03-31 15:28:25 +0000
4@@ -29,6 +29,7 @@
5 import os
6 import locale
7 import re
8+import datetime
9 from gnome import url_show
10
11 #our own imports
12@@ -536,9 +537,68 @@
13 self.quickadd_pane.show()
14 else :
15 self.quickadd_pane.hide()
16-
17+
18+ def canonical_date(self, arg) :
19+ """
20+ Transform "arg" in a valid yyyy-mm-dd date or return None.
21+ "arg" can be a yyyy-mm-dd, yyyymmdd, mmdd, today or a weekday name.
22+ """
23+ day_names_en = ["monday", "tuesday", "wednesday", "thursday",
24+ "friday", "saturday", "sunday"]
25+ if re.match(r'\d{4}-\d{2}-\d{2}', arg) :
26+ date = arg
27+ elif arg.isdigit() :
28+ if len(arg) == 8 :
29+ date = "%s-%s-%s" % (arg[:4],arg[4:6],arg[6:])
30+ elif len(arg) == 4 :
31+ year = datetime.date.today().year
32+ date = "%i-%s-%s" % (year,arg[:2],arg[2:])
33+ elif arg.lower() == "today" :
34+ today = datetime.date.today()
35+ year = today.year
36+ month = today.month
37+ day = today.day
38+ date = "%i-%i-%i" % (year,month,day)
39+ elif arg.lower() in day_names_en :
40+ today = datetime.date.today()
41+ today_day = today.weekday()
42+ arg_day = day_names_en.index(arg)
43+ if arg_day > today_day :
44+ delta = datetime.timedelta(days = arg_day-today_day)
45+ else :
46+ delta = datetime.timedelta(days = arg_day-today_day+7)
47+ next_date = today + delta
48+ year = next_date.year
49+ month = next_date.month
50+ day = next_date.day
51+ date = "%i-%i-%i" % (year,month,day)
52+ else :
53+ return None
54+ if self.is_date_valid(date) :
55+ return date
56+ else :
57+ return None
58+
59+ def is_date_valid(self, fulldate) :
60+ """
61+ Return True if the date exists. False else.
62+ "fulldate" is yyyy-mm-dd
63+ """
64+ splited_date = fulldate.split("-")
65+ if len(splited_date) != 3 :
66+ return False
67+ year,month,day = splited_date
68+ try :
69+ date = datetime.date(int(year),int(month),int(day))
70+ except ValueError :
71+ return False
72+ else :
73+ return True
74+
75 def quickadd(self,widget) : #pylint: disable-msg=W0613
76 text = self.quickadd_entry.get_text()
77+ due_date = None
78+ defer_date = None
79 if text :
80 tags,notagonly = self.get_selected_tags() #pylint: disable-msg=W0612
81 # Get tags in the title
82@@ -553,9 +613,14 @@
83 if attribute.lower() == "tags" :
84 for tag in args.split(",") :
85 tags.append(GTG.core.tagstore.Tag("@"+tag))
86- # Here you can add new commands
87- #elif attribute.lower() == "defer" :
88- #elif attribute.lower() == "due" :
89+ elif attribute.lower() == "defer" :
90+ defer_date = self.canonical_date(args)
91+ if defer_date is None :
92+ valid_attribute = False
93+ elif attribute.lower() == "due" :
94+ due_date = self.canonical_date(args)
95+ if due_date is None :
96+ valid_attribute = False
97 else :
98 # attribute is unknown
99 valid_attribute = False
100@@ -567,6 +632,10 @@
101 task = self.req.new_task(tags=tags,newtask=True)
102 if text != "" :
103 task.set_title(text)
104+ if not due_date is None :
105+ task.set_due_date(due_date)
106+ if not defer_date is None :
107+ task.set_start_date(defer_date)
108 id_toselect = task.get_id()
109 #############
110 self.quickadd_entry.set_text('')

Subscribers

People subscribed via source and target branches

to status/vote changes: