Esempio n. 1
0
class TodoView(object):
    def __init__(self, request):
        self.request = request
        self.dm = PickleDataManager()
        t = transaction.get()
        t.join(self.dm)

    @view_config(context=Root, request_method="GET", renderer=template)
    def todo_view(self):
        tasks = self.dm.items()
        tasks.sort()
        return {"tasks": tasks, "status": None}

    @view_config(context=Root, request_param="add", renderer=template)
    def add_view(self):
        text = self.request.params.get("text")
        key = str(time.time())
        self.dm[key] = {"task_description": text, "task_completed": False}
        tasks = self.dm.items()
        tasks.sort()
        return {"tasks": tasks, "status": "New task inserted."}

    @view_config(context=Root, request_param="done", renderer=template)
    def done_view(self):
        tasks = self.request.params.getall("tasks")
        for task in tasks:
            self.dm[task]["task_completed"] = True
        tasks = self.dm.items()
        tasks.sort()
        return {"tasks": tasks, "status": "Marked tasks as done."}

    @view_config(context=Root, request_param="not done", renderer=template)
    def not_done_view(self):
        tasks = self.request.params.getall("tasks")
        for task in tasks:
            self.dm[task]["task_completed"] = False
        tasks = self.dm.items()
        tasks.sort()
        return {"tasks": tasks, "status": "Marked tasks as not done."}

    @view_config(context=Root, request_param="delete", renderer=template)
    def delete_view(self):
        tasks = self.request.params.getall("tasks")
        for task in tasks:
            del (self.dm[task])
        tasks = self.dm.items()
        tasks.sort()
        return {"tasks": tasks, "status": "Deleted tasks."}
Esempio n. 2
0
class TodoView(object):
    def __init__(self, request):
        self.request = request
        self.dm = PickleDataManager()
        t = transaction.get()
        t.join(self.dm)

    @view_config(context=Root, request_method='GET', renderer=template)
    def todo_view(self):
        tasks = self.dm.items()
        tasks.sort()
        return {'tasks': tasks, 'status': None}

    @view_config(context=Root, request_param='add', renderer=template)
    def add_view(self):
        text = self.request.params.get('text')
        key = str(time.time())
        self.dm[key] = {'task_description': text, 'task_completed': False}
        tasks = self.dm.items()
        tasks.sort()
        return {'tasks': tasks, 'status': 'New task inserted.'}

    @view_config(context=Root, request_param='done', renderer=template)
    def done_view(self):
        tasks = self.request.params.getall('tasks')
        for task in tasks:
            self.dm[task]['task_completed'] = True
        tasks = self.dm.items()
        tasks.sort()
        return {'tasks': tasks, 'status': 'Marked tasks as done.'}

    @view_config(context=Root, request_param='not done', renderer=template)
    def not_done_view(self):
        tasks = self.request.params.getall('tasks')
        for task in tasks:
            self.dm[task]['task_completed'] = False
        tasks = self.dm.items()
        tasks.sort()
        return {'tasks': tasks, 'status': 'Marked tasks as not done.'}

    @view_config(context=Root, request_param='delete', renderer=template)
    def delete_view(self):
        tasks = self.request.params.getall('tasks')
        for task in tasks:
            del (self.dm[task])
        tasks = self.dm.items()
        tasks.sort()
        return {'tasks': tasks, 'status': 'Deleted tasks.'}
Esempio n. 3
0
 def __init__(self, request):
     self.request = request
     self.dm = PickleDataManager()
     t = transaction.get()
     t.join(self.dm)
Esempio n. 4
0
 def __init__(self, request):
     self.request = request
     self.dm = PickleDataManager()
     t = transaction.get()
     t.join(self.dm)