Reputation: 11
I take notes with cherrytree, an hierarchical note taking application written in python. A shortcut allows to insert date node, and the structure of date nodes in the tree is as follows:
├─ year
│ └─ month1
│ │ └─ day1
│ │ └─ day2
│ └─ month2
├─ year2
├─ a user node
I'd like to insert date nodes in a parent node named "journal" or whatever, as follows:
├─ journal
│ └─ year1
│ │ └─ month1
│ │ │ └─ day1
│ │ └─ month2
│ └─ year2
├─ a user node
The function node_date in core.py is:
def node_date(self, *args):
"""Insert Date Node in Tree"""
now_year = time.strftime("%Y").decode(locale.getlocale()[1])
now_month =time.strftime("%B").decode(locale.getlocale()[1])
now_day = time.strftime("%A %d %B %Y").decode(locale.getlocale()[1])
#print now_year, now_month, now_day
if self.curr_tree_iter:
curr_depth = self.treestore.iter_depth(self.curr_tree_iter)
if curr_depth == 0:
if self.treestore[self.curr_tree_iter][1] == now_year:
self.node_child_exist_or_create(self.curr_tree_iter, now_month)
self.node_date()
return
else:
if self.treestore[self.curr_tree_iter][1] == now_month\
and self.treestore[self.treestore.iter_parent(self.curr_tree_iter)][1] == now_year:
self.node_child_exist_or_create(self.curr_tree_iter, now_day)
return
if self.treestore[self.curr_tree_iter][1] == now_year:
self.node_child_exist_or_create(self.curr_tree_iter, now_month)
self.node_date()
return
self.node_child_exist_or_create(None, now_year)
self.node_date()
Could someone help me to adapt it? I'm not a developer (my skills in python stop at modifying now_day date format in the way I prefer...), and I'd like to separate notes and journal nodes, without having to move manually the date node automatically created by shortcut. Thank you for your help.
Upvotes: 0
Views: 286
Reputation: 11
I got help on a project repo issue. My node_date method is now:
def node_date(self, *args):
"""Insert Date Node in Tree"""
top_node = "journal"
now_year = time.strftime("%Y").decode(locale.getlocale()[1])
now_month =time.strftime("%Y-%B").decode(locale.getlocale()[1])
now_day = time.strftime("%A %d %B %Y").decode(locale.getlocale()[1])
#print now_year, now_month, now_day
self.node_child_exist_or_create(None, top_node)
self.node_child_exist_or_create(self.curr_tree_iter, now_year)
self.node_child_exist_or_create(self.curr_tree_iter, now_month)
self.node_child_exist_or_create(self.curr_tree_iter, now_day)
As I said to the contributor, I don't understand why all thoses if/else in the project code while his solution is so simple, but for now it seems to work in the way I wanted.
Upvotes: 1