~ubuntu-branches/ubuntu/trusty/desktopcouch/trusty

« back to all changes in this revision

Viewing changes to desktopcouch/tasks/record.py

  • Committer: Bazaar Package Importer
  • Author(s): Ken VanDine
  • Date: 2010-04-19 12:52:22 UTC
  • mfrom: (12.1.9 lucid)
  • Revision ID: james.westby@ubuntu.com-20100419125222-zsh9lrm15h84951j
* debian/patches/lp_522538.patch
  - Handle reconnects if the server isn't running (LP: #522538)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2010 Canonical Ltd.
2
 
#
3
 
# This file is part of desktopcouch-tasks.
4
 
#
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.
8
 
#
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.
13
 
#
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/>.
16
 
#
17
 
# Authors: Rodrigo Moya <rodrigo.moya@canonical.com>
18
 
 
19
 
 
20
 
"""A dictionary based task record representation."""
21
 
 
22
 
from desktopcouch.records.record import Record
23
 
 
24
 
TASK_RECORD_TYPE = 'http://www.freedesktop.org/wiki/Specifications/desktopcouch/task'
25
 
# keep in sync with the above tasks record type
26
 
FIELD_NAMES = (
27
 
    'summary'
28
 
)
29
 
 
30
 
class TaskBase(Record):
31
 
    """
32
 
    A base for Task records.
33
 
 
34
 
    Use make_task_class to create the Note class with the required fields.
35
 
    """
36
 
 
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)
40
 
 
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:
45
 
 
46
 
        def fget(self, _field_name=field_name):
47
 
            return self.get(_field_name)
48
 
 
49
 
        def fset(self, value, _field_name=field_name):
50
 
            self[_field_name] = value
51
 
 
52
 
        setattr(TaskClass, field_name, property(fget, fset))
53
 
    return TaskClass
54
 
 
55
 
Task = make_task_class(FIELD_NAMES)