Skip to content

Commit

Permalink
Update views.py
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeshingles committed Sep 3, 2024
1 parent 5d083a7 commit 6b71028
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions atlasserver/forcephot/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,11 @@ def create(self, request, *args, **kwargs) -> Response:
def perform_create(self, serializer) -> None:
"""Create new task(s)."""
if self.request.user and self.request.user.is_authenticated:
usertaskcount = Task.objects.filter(user_id=self.request.user.pk, request_type="IMGZIP").count()
if usertaskcount >= maximgziptasks:
msg = f"You have too many IMGZIP tasks ({usertaskcount} >= {maximgziptasks}). Issue delete requests to remove some."
userimziptaskcount = Task.objects.filter(
user_id=self.request.user.pk, request_type="IMGZIP", is_archived=False
).count()
if userimziptaskcount >= maximgziptasks:
msg = f"You have too many IMGZIP tasks ({userimziptaskcount} >= {maximgziptasks}). Issue delete requests to remove some."
raise ValidationError(msg)

extra_fields: dict[str, Any] = {
Expand Down Expand Up @@ -357,9 +359,11 @@ def get(self, request, pk):
redirurl = reverse("task-list")

if self.request.user and self.request.user.is_authenticated:
usertaskcount = Task.objects.filter(user_id=self.request.user.pk, request_type="IMGZIP").count()
if usertaskcount >= maximgziptasks:
msg = f"You have too many IMGZIP tasks ({usertaskcount} >= {maximgziptasks}). Delete some before making new requests."
userimziptaskcount = Task.objects.filter(
user_id=self.request.user.pk, request_type="IMGZIP", is_archived=False
).count()
if userimziptaskcount >= maximgziptasks:
msg = f"You have too many IMGZIP tasks ({userimziptaskcount} >= {maximgziptasks}). Delete some before making new requests."
return JsonResponse({"error": msg}, status=429)

if not parent_task.error_msg and parent_task.finishtimestamp:
Expand Down

0 comments on commit 6b71028

Please sign in to comment.