~unity-2d-team/unity-2d/Shell-MultiMonitor

« back to all changes in this revision

Viewing changes to grackle/model.py

  • Committer: William Grant
  • Date: 2012-01-22 10:39:15 UTC
  • Revision ID: william.grant@canonical.com-20120122103915-lqjw4jsaw3ug1q2g
Merge grackle.server into grackle. Alter Makefile to run all the tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
113
113
            'date': message.get('date'),
114
114
            'from': message.get('from'),
115
115
            'subject': message.get('subject'),
116
 
            'message-id': message.get('message-id'),
117
116
            }
118
117
 
119
 
    def _trim(self, sequence, end):
120
 
        if end:
121
 
            return sequence[:-1]
122
 
        else:
123
 
            return sequence[1:]
124
 
 
125
 
    def get_messages(self, archive_uuid, order, count, memo, backward=False):
 
118
    def get_messages(self, archive_uuid, order, count, start):
126
119
        if order in ("date", "-date"):
127
120
            reversed = order[0] == '-'
128
121
        else:
129
122
            raise AssertionError("Unsupported order.")
130
 
        if memo != '':
131
 
            memo = uuid.UUID(memo)
132
 
        # Get up to n+1 messages from the memo: the last item of the
133
 
        # previous batch (because that's where the memo starts) + this
134
 
        # batch.
135
 
        if backward:
136
 
            start = ''
137
 
            finish = memo
138
 
        else:
139
 
            start = memo
140
 
            finish = ''
141
123
        pairs = self.archive_messages.get(
142
 
            archive_uuid, column_count=count + 1, column_start=start,
143
 
            column_finish=finish, column_reversed=reversed).items()
144
 
        if memo and len(pairs) and pairs[0][0] <= memo:
145
 
            pairs = self._trim(pairs, False ^ backward)
146
 
        elif len(pairs) > count:
147
 
            pairs = self._trim(pairs, True ^ backward)
148
 
 
149
 
        if len(pairs) == 0:
150
 
            return (None, [], None)
151
 
 
152
 
        assert 0 < len(pairs) <= count
153
 
 
 
124
            archive_uuid, column_count=count + 1,
 
125
            column_start=start, column_reversed=reversed).items()
154
126
        ids = [v for k, v in pairs]
155
127
        messages = self.messages.multiget(
156
 
            ids, columns=['date', 'from', 'subject', 'message-id'])
157
 
 
 
128
            ids, columns=['date', 'from', 'subject'])
 
129
        actual_count = len(pairs)
 
130
        if len(pairs) > count:
 
131
            assert len(pairs) == count + 1
 
132
            actual_count -= 1
 
133
            next_memo = str(pairs[count][0])
 
134
        else:
 
135
            next_memo = None
158
136
        return (
159
 
            str(pairs[0][0]),
160
 
            [self._format_message(messages[id]) for id in ids],
161
 
            str(pairs[-1][0]),
 
137
            [self._format_message(messages[id]) for id in ids[:actual_count]],
 
138
            next_memo,
162
139
            )