Skip to content

Commit f837409

Browse files
committed
linting
1 parent b039a44 commit f837409

File tree

4 files changed

+50
-20
lines changed

4 files changed

+50
-20
lines changed

coral_credits/api/db_utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,10 @@ def get_all_active_reservations(resource_provider_account):
7272
def get_credit_allocation(id):
7373
now = timezone.now()
7474

75-
credit_allocation = models.CreditAllocation.objects.filter(
76-
id=id
77-
).first()
75+
credit_allocation = models.CreditAllocation.objects.filter(id=id).first()
7876
if credit_allocation == None:
7977
raise db_exceptions.NoCreditAllocation("Invalid allocation_id")
80-
78+
8179
return credit_allocation
8280

8381

coral_credits/api/serializers.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ class Consumer(serializers.ModelSerializer):
7878

7979
class Meta:
8080
model = models.Consumer
81-
fields = ["consumer_ref", "resource_provider_account", "start", "end", "resources"]
81+
fields = [
82+
"consumer_ref",
83+
"resource_provider_account",
84+
"start",
85+
"end",
86+
"resources",
87+
]
8288

8389

8490
class ResourceRequestSerializer(serializers.Serializer):

coral_credits/api/views.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ class CreditAllocationResourceViewSet(viewsets.ModelViewSet):
2727
permission_classes = [permissions.IsAuthenticated]
2828

2929
def get_queryset(self):
30-
return models.CreditAllocationResource.objects.filter(allocation__pk=self.kwargs["allocation_pk"])
30+
return models.CreditAllocationResource.objects.filter(
31+
allocation__pk=self.kwargs["allocation_pk"]
32+
)
3133

3234
def _create_update_credit_allocations(self, request, allocation_pk):
3335
"""Allocate credits to a dictionary of resource classes.
@@ -65,15 +67,15 @@ def _create_update_credit_allocations(self, request, allocation_pk):
6567
# When creating with multiple resources a list of multiple entries is returned,
6668
# each with their own unique ID
6769
if len(serializer.data) == 1:
68-
return Response(serializer.data[0], status=status.HTTP_201_CREATED)
70+
return Response(serializer.data[0], status=status.HTTP_201_CREATED)
6971
else:
70-
return Response(serializer.data, status=status.HTTP_201_CREATED)
72+
return Response(serializer.data, status=status.HTTP_201_CREATED)
7173

7274
def create(self, request, allocation_pk=None):
73-
return self._create_update_credit_allocations(request,allocation_pk)
74-
75+
return self._create_update_credit_allocations(request, allocation_pk)
76+
7577
def update(self, request, allocation_pk=None, pk=None):
76-
return self._create_update_credit_allocations(request,allocation_pk)
78+
return self._create_update_credit_allocations(request, allocation_pk)
7779

7880
def _validate_request(self, request):
7981

@@ -129,19 +131,25 @@ def retrieve(self, request, pk=None):
129131
)
130132

131133
# TODO(johngarbutt) look for any during the above allocations
132-
consumers_query = models.Consumer.objects.filter(resource_provider_account__account__pk=pk)
134+
consumers_query = models.Consumer.objects.filter(
135+
resource_provider_account__account__pk=pk
136+
)
133137
consumers = serializers.Consumer(
134138
consumers_query, many=True, context={"request": request}
135139
)
136140

137141
account_summary["allocations"] = allocations.data
138142
account_summary["consumers"] = consumers.data
139143

140-
all_allocation_resources_query = models.CreditAllocationResource.objects.filter(allocation__account__pk=pk)
144+
all_allocation_resources_query = models.CreditAllocationResource.objects.filter(
145+
allocation__account__pk=pk
146+
)
141147
# add resource_hours_remaining... must be a better way!
142148
# TODO(johngarbut) we don't check the dates line up!!
143149
for allocation in account_summary["allocations"]:
144-
resources_for_allocation_query = all_allocation_resources_query.filter(allocation__id=allocation["id"])
150+
resources_for_allocation_query = all_allocation_resources_query.filter(
151+
allocation__id=allocation["id"]
152+
)
145153
resources_for_allocation = serializers.CreditAllocationResourceSerializer(
146154
resources_for_allocation_query, many=True, context={"request": request}
147155
)

coral_credits/urls.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,25 @@
2828
#
2929
router = routers.DefaultRouter(trailing_slash=False)
3030
router.register(r"resource_class", views.ResourceClassViewSet)
31-
router.register(r"resource_class/", views.ResourceClassViewSet, basename="resourceclassslash")
31+
router.register(
32+
r"resource_class/", views.ResourceClassViewSet, basename="resourceclassslash"
33+
)
3234
router.register(r"resource_provider", views.ResourceProviderViewSet)
33-
router.register(r"resource_provider/", views.ResourceProviderViewSet, basename="resourceproviderslash")
35+
router.register(
36+
r"resource_provider/",
37+
views.ResourceProviderViewSet,
38+
basename="resourceproviderslash",
39+
)
3440
router.register(r"resource_provider_account", views.ResourceProviderAccountViewSet)
35-
router.register(r"resource_provider_account/", views.ResourceProviderAccountViewSet, basename="resourceprovideraccountslash")
41+
router.register(
42+
r"resource_provider_account/",
43+
views.ResourceProviderAccountViewSet,
44+
basename="resourceprovideraccountslash",
45+
)
3646
router.register(r"allocation", views.CreditAllocationViewSet)
37-
router.register(r"allocation/", views.CreditAllocationViewSet, basename="allocationslash")
47+
router.register(
48+
r"allocation/", views.CreditAllocationViewSet, basename="allocationslash"
49+
)
3850
router.register(r"account", views.AccountViewSet, basename="creditaccount")
3951
router.register(r"account/", views.AccountViewSet, basename="creditaccountslash")
4052
router.register(r"consumer", views.ConsumerViewSet, basename="resource-request")
@@ -43,8 +55,14 @@
4355
allocation_router = routers.NestedSimpleRouter(
4456
router, r"allocation", lookup="allocation", trailing_slash=False
4557
)
46-
allocation_router.register(r"resources", views.CreditAllocationResourceViewSet, basename="allocation-resource")
47-
allocation_router.register(r"resources/", views.CreditAllocationResourceViewSet, basename="allocation-resource-slash")
58+
allocation_router.register(
59+
r"resources", views.CreditAllocationResourceViewSet, basename="allocation-resource"
60+
)
61+
allocation_router.register(
62+
r"resources/",
63+
views.CreditAllocationResourceViewSet,
64+
basename="allocation-resource-slash",
65+
)
4866

4967

5068
def prometheus_metrics(request):

0 commit comments

Comments
 (0)