1
# Copyright (C) 2007-2012 by the Free Software Foundation, Inc.
3
# This file is part of GNU Mailman.
5
# GNU Mailman is free software: you can redistribute it and/or modify it under
6
# the terms of the GNU General Public License as published by the Free
7
# Software Foundation, either version 3 of the License, or (at your option)
10
# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15
# You should have received a copy of the GNU General Public License along with
16
# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
18
"""Interfaces for the request database.
20
The request database handles events that must be approved by the list
21
moderators, such as subscription requests and held messages.
24
from __future__ import absolute_import, unicode_literals
33
from flufl.enum import Enum
34
from zope.interface import Interface, Attribute
38
class RequestType(Enum):
45
class IListRequests(Interface):
46
"""Held requests for a specific mailing list."""
48
mailing_list = Attribute(
49
"""The IMailingList for these requests.""")
52
"""The total number of requests held for the mailing list.""")
54
def count_of(request_type):
55
"""The total number of requests held of the given request type.
57
:param request_type: A `RequestType` enum value.
61
def hold_request(request_type, key, data=None):
62
"""Hold some data for moderator approval.
64
:param request_type: A `RequestType` enum value.
65
:param key: The key piece of request data being held.
66
:param data: Additional optional data in the form of a dictionary that
67
is associated with the held request.
68
:return: A unique id for this held request.
71
held_requests = Attribute(
72
"""An iterator over the held requests.
74
Returned items have two attributes:
75
* `id` is the held request's unique id;
76
* `type` is a `RequestType` enum value.
79
def of_type(request_type):
80
"""An iterator over the held requests of the given type.
82
Returned items have two attributes:
83
* `id` is the held request's unique id;
84
* `type` is a `RequestType` enum value.
86
Only items with a matching `type' are returned.
89
def get_request(request_id, request_type):
90
"""Get the data associated with the request id, or None.
92
:param request_id: The unique id for the request.
94
:param request_type: Optional request type that the requested id must
95
match, otherwise no match is returned.
96
:type request_type: `RequestType`
97
:return: A 2-tuple of the key and data originally held, or None if the
98
`request_id` is not in the database.
101
def delete_request(request_id):
102
"""Delete the request associated with the id.
104
:param request_id: The unique id for the request.
105
:raises KeyError: If `request_id` is not in the database.