Python classes for a simple GTD application

I am trying to encode a very rudimentary GTD application for myself, not just to organize myself, but to better understand the encoding and become better in Python. However, I have problems with classes.

Here are the classes that I still have:

class Project:
    def __init__(self, name, actions=[]):
        self.name = name
        self.actions = actions
    def add(self, action):
        self.actions.append(action)

class Action:
    def __init__(self, do='', context=''):
        self.do = do
        self.context = context

Each project has actions for it, but I want to make it so that projects can also consist of other projects. Say every day I wanted to print a list of everything. I'm having problems with how I built a list similar to this

> Project A
>        Actions for Project A
>     Project B
>         Sub project A
>             Actions for Sub project A
>         Sub project B
>             Actions for Sub project B
>         Sub project C
>             Sub sub project A
>                 Actions for sub sub project A
>             Sub sub project B
>                 Actions for sub sub project B
>             Actions for Sub project C
>         Actions for Project B

It is clear to me that recursion will be used. I'm struggling with whether to create another class for it, a subproject and a subclass of Project. Something there just makes my brain throw an exception.

action Project, , MegaProject.actions.action.actions.action.

- , !

+2
3

, , . .

class Project:
    def __init__(self, name, actions=[], subprojects=[]):
        self.name = name
        self.actions = actions
        self.subprojects = subprojects

    def add(self, action):
        self.actions.append(action)

    def add_project(self, project)
        self.subprojects.append(project)

, , Projects - , Actions - .

class Project:
    def __init__(self, name, children=[]):
        self.name = name
        self.children = children

    def add(self, object):
        self.children.append(object)

    def mark_done(self):
        for c in self.children:
            c.mark_done()

class Action:
    def __init__(self, do):
        self.do = do
        self.done = False

    def mark_done(self):
        self.done = True

, , ( /). . , .

, (Actions), Project.

def get_action_list(self):
    actions = []
    for c in self.children:
        if c.__class__ == self.__class__:
            actions += c.get_action_list()
        else:
            actions.append(c)
    return actions
+3

, "Project". , , .

, , Project (), ProjectComposite () .

0

Have you rated existing GTD tools? I would look at the file formats used by existing GTD tools, especially. those stored in XML. This will give you an idea of ​​how the organization of this kind of data tends to work.

The structure ranges from fairly simplified (TaskPaper) to baroque (OmniFocus). Look around and see what others have done before you.

0
source

Source: https://habr.com/ru/post/1713514/


All Articles