1
# Copyright 2010 Canonical Ltd.
3
# This file is part of desktopcouch-tasks.
5
# desktopcouch is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU Lesser General Public License version 3
7
# as published by the Free Software Foundation.
9
# desktopcouch is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU Lesser General Public License for more details.
14
# You should have received a copy of the GNU Lesser General Public License
15
# along with desktopcouch. If not, see <http://www.gnu.org/licenses/>.
17
# Authors: Rodrigo Moya <rodrigo.moya@canonical.com>
20
"""A dictionary based task record representation."""
22
from desktopcouch.records.record import Record
24
TASK_RECORD_TYPE = 'http://www.freedesktop.org/wiki/Specifications/desktopcouch/task'
25
# keep in sync with the above tasks record type
30
class TaskBase(Record):
32
A base for Task records.
34
Use make_task_class to create the Note class with the required fields.
37
def __init__(self, data=None, record_id=None):
38
super(TaskBase, self).__init__(
39
record_id=record_id, data=data, record_type=TASK_RECORD_TYPE)
41
def make_task_class(field_names):
42
"""Task class factory function. field_names is a list of strings."""
43
TaskClass = type('Task', (TaskBase,), {})
44
for field_name in field_names:
46
def fget(self, _field_name=field_name):
47
return self.get(_field_name)
49
def fset(self, value, _field_name=field_name):
50
self[_field_name] = value
52
setattr(TaskClass, field_name, property(fget, fset))
55
Task = make_task_class(FIELD_NAMES)