|
1 | 1 | # Python imports |
2 | 2 | import json |
3 | | -import requests |
4 | | -import base64 |
5 | 3 |
|
6 | 4 | # Django import |
7 | 5 | from django.utils import timezone |
|
11 | 9 | from django.contrib.postgres.fields import ArrayField |
12 | 10 | from django.db.models import Value, UUIDField |
13 | 11 | from django.db.models.functions import Coalesce |
14 | | -from django.http import StreamingHttpResponse |
15 | | -from django.conf import settings |
16 | | - |
17 | 12 |
|
18 | 13 | # Third party imports |
19 | 14 | from rest_framework import status |
|
45 | 40 |
|
46 | 41 |
|
47 | 42 | class IntakeViewSet(BaseViewSet): |
| 43 | + |
48 | 44 | serializer_class = IntakeSerializer |
49 | 45 | model = Intake |
50 | 46 |
|
@@ -93,6 +89,7 @@ def destroy(self, request, slug, project_id, pk): |
93 | 89 |
|
94 | 90 |
|
95 | 91 | class IntakeIssueViewSet(BaseViewSet): |
| 92 | + |
96 | 93 | serializer_class = IntakeIssueSerializer |
97 | 94 | model = IntakeIssue |
98 | 95 |
|
@@ -643,82 +640,3 @@ def destroy(self, request, slug, project_id, pk): |
643 | 640 |
|
644 | 641 | intake_issue.delete() |
645 | 642 | return Response(status=status.HTTP_204_NO_CONTENT) |
646 | | - |
647 | | - @allow_permission([ROLE.ADMIN, ROLE.MEMBER, ROLE.GUEST]) |
648 | | - def retrieve_description(self, request, slug, project_id, pk): |
649 | | - issue = Issue.objects.filter( |
650 | | - pk=pk, workspace__slug=slug, project_id=project_id |
651 | | - ).first() |
652 | | - if issue is None: |
653 | | - return Response( |
654 | | - {"error": "Issue not found"}, |
655 | | - status=404, |
656 | | - ) |
657 | | - binary_data = issue.description_binary |
658 | | - |
659 | | - def stream_data(): |
660 | | - if binary_data: |
661 | | - yield binary_data |
662 | | - else: |
663 | | - yield b"" |
664 | | - |
665 | | - response = StreamingHttpResponse( |
666 | | - stream_data(), content_type="application/octet-stream" |
667 | | - ) |
668 | | - response["Content-Disposition"] = ( |
669 | | - 'attachment; filename="issue_description.bin"' |
670 | | - ) |
671 | | - return response |
672 | | - |
673 | | - @allow_permission([ROLE.ADMIN, ROLE.MEMBER, ROLE.GUEST]) |
674 | | - def update_description(self, request, slug, project_id, pk): |
675 | | - issue = Issue.objects.get( |
676 | | - workspace__slug=slug, project_id=project_id, pk=pk |
677 | | - ) |
678 | | - base64_description = issue.description_binary |
679 | | - # convert to base64 string |
680 | | - if base64_description: |
681 | | - base64_description = base64.b64encode(base64_description).decode( |
682 | | - "utf-8" |
683 | | - ) |
684 | | - data = { |
685 | | - "original_document": base64_description, |
686 | | - "updates": request.data.get("description_binary"), |
687 | | - } |
688 | | - base_url = f"{settings.LIVE_BASE_URL}/resolve-document-conflicts/" |
689 | | - try: |
690 | | - response = requests.post(base_url, json=data, headers=None) |
691 | | - except requests.RequestException: |
692 | | - return Response( |
693 | | - {"error": "Failed to connect to the external service"}, |
694 | | - status=status.HTTP_502_BAD_GATEWAY, |
695 | | - ) |
696 | | - |
697 | | - if response.status_code == 200: |
698 | | - issue.description = response.json().get( |
699 | | - "description", issue.description |
700 | | - ) |
701 | | - issue.description_html = response.json().get("description_html") |
702 | | - response_description_binary = response.json().get( |
703 | | - "description_binary" |
704 | | - ) |
705 | | - issue.description_binary = base64.b64decode( |
706 | | - response_description_binary |
707 | | - ) |
708 | | - issue.save() |
709 | | - |
710 | | - def stream_data(): |
711 | | - if issue.description_binary: |
712 | | - yield issue.description_binary |
713 | | - else: |
714 | | - yield b"" |
715 | | - |
716 | | - response = StreamingHttpResponse( |
717 | | - stream_data(), content_type="application/octet-stream" |
718 | | - ) |
719 | | - response["Content-Disposition"] = ( |
720 | | - 'attachment; filename="issue_description.bin"' |
721 | | - ) |
722 | | - return response |
723 | | - |
724 | | - return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR) |
0 commit comments