forked from pulp/pulp_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewsets.py
More file actions
62 lines (47 loc) · 1.89 KB
/
Copy pathviewsets.py
File metadata and controls
62 lines (47 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from gettext import gettext as _
from pulpcore.plugin import viewsets as platform
from pulpcore.plugin.models import Repository
from rest_framework import decorators
from . import models, serializers, tasks
class PythonPackageContentViewSet(platform.ContentViewSet):
"""
The ViewSet for PythonPackageContent.
"""
endpoint_name = 'python'
queryset = models.PythonPackageContent.objects.all()
serializer_class = serializers.PythonPackageContentSerializer
class PythonImporterViewSet(platform.ImporterViewSet):
"""
A ViewSet for PythonImporter.
Similar to the PythonContentViewSet above, define endpoint_name,
queryset and serializer, at a minimum.
"""
endpoint_name = 'python'
queryset = models.PythonImporter.objects.all()
serializer_class = serializers.PythonImporterSerializer
@decorators.detail_route(methods=('post',))
def sync(self, request, pk):
"""
Dispatches a sync task.
"""
importer = self.get_object()
repository = self.get_resource(request.data['repository'], Repository)
if not importer.feed_url:
raise ValueError(_("An importer must have a 'feed_url' attribute to sync."))
async_result = tasks.sync.apply_async_with_reservation(
platform.tags.RESOURCE_REPOSITORY_TYPE, str(repository.pk),
kwargs={
'importer_pk': importer.pk,
'repository_pk': repository.pk
}
)
return platform.OperationPostponedResponse([async_result], request)
class PythonPublisherViewSet(platform.PublisherViewSet):
"""
A ViewSet for PythonPublisher.
Similar to the PythonContentViewSet above, define endpoint_name,
queryset and serializer, at a minimum.
"""
endpoint_name = 'python'
queryset = models.PythonPublisher.objects.all()
serializer_class = serializers.PythonPublisherSerializer