2
# Copyright 2012-2013 Canonical Ltd.
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU Affero General Public License version 3, as
6
# published by the Free Software Foundation.
8
# This program is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranties of
10
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
# PURPOSE. See the GNU Affero General Public License for more details.
13
# You should have received a copy of the GNU Affero General Public License
14
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
from tastypie.api import Api
17
from tastypie.http import HttpAccepted, HttpApplicationError
18
from tastypie.resources import ALL
20
from ppa_assigner.models import PPA, LaunchpadError
22
from ci_utils.tastypie.resource import AuthorizedResource
25
class PPAResource(AuthorizedResource):
26
class Meta(AuthorizedResource.Meta):
27
queryset = PPA.objects.filter()
35
def obj_create(self, bundle, **kwargs):
36
'''We don't really create an object, so override tastypie.'''
37
lockname = bundle.data.get('lockname')
38
clean = bundle.data.get('clean')
39
bundle.obj = PPA.reserve(lockname, clean)
42
def patch_list(self, request, **kwargs):
43
if request.body == '{"populate": true}':
45
# populate is a bit different than normal "patch" operations
46
PPA.populate_from_launchpad()
48
except LaunchpadError as e:
49
return HttpApplicationError(e)
50
return super(PPAResource, self).patch_list(request, **kwargs)
53
v1_api = Api(api_name='v1')
54
v1_api.register(PPAResource())