Add klass argument to get_object_or_404 usage

Signed-off-by: Roberto Rosario <Roberto.Rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2018-12-16 01:55:33 -04:00
parent 727d2ecd71
commit 798446f362
39 changed files with 164 additions and 164 deletions
+6 -6
View File
@@ -32,7 +32,7 @@ class APIResolvedSmartLinkDocumentListView(generics.ListAPIView):
serializer_class = ResolvedSmartLinkDocumentSerializer
def get_document(self):
document = get_object_or_404(Document, pk=self.kwargs['pk'])
document = get_object_or_404(klass=Document, pk=self.kwargs['pk'])
AccessControlList.objects.check_access(
permissions=permission_document_view, user=self.request.user,
@@ -43,7 +43,7 @@ class APIResolvedSmartLinkDocumentListView(generics.ListAPIView):
def get_smart_link(self):
smart_link = get_object_or_404(
SmartLink.objects.get_for(document=self.get_document()),
klass=SmartLink.objects.get_for(document=self.get_document()),
pk=self.kwargs['smart_link_pk']
)
@@ -86,7 +86,7 @@ class APIResolvedSmartLinkView(generics.RetrieveAPIView):
serializer_class = ResolvedSmartLinkSerializer
def get_document(self):
document = get_object_or_404(Document, pk=self.kwargs['pk'])
document = get_object_or_404(klass=Document, pk=self.kwargs['pk'])
AccessControlList.objects.check_access(
permissions=permission_document_view, user=self.request.user,
@@ -123,7 +123,7 @@ class APIResolvedSmartLinkListView(generics.ListAPIView):
serializer_class = ResolvedSmartLinkSerializer
def get_document(self):
document = get_object_or_404(Document, pk=self.kwargs['pk'])
document = get_object_or_404(klass=Document, pk=self.kwargs['pk'])
AccessControlList.objects.check_access(
permissions=permission_document_view, user=self.request.user,
@@ -182,7 +182,7 @@ class APISmartLinkConditionListView(generics.ListCreateAPIView):
else:
permission_required = permission_smart_link_edit
smart_link = get_object_or_404(SmartLink, pk=self.kwargs['pk'])
smart_link = get_object_or_404(klass=SmartLink, pk=self.kwargs['pk'])
AccessControlList.objects.check_access(
permissions=permission_required, user=self.request.user,
@@ -225,7 +225,7 @@ class APISmartLinkConditionView(generics.RetrieveUpdateDestroyAPIView):
else:
permission_required = permission_smart_link_edit
smart_link = get_object_or_404(SmartLink, pk=self.kwargs['pk'])
smart_link = get_object_or_404(klass=SmartLink, pk=self.kwargs['pk'])
AccessControlList.objects.check_access(
permissions=permission_required, user=self.request.user,
+4 -4
View File
@@ -129,11 +129,11 @@ class SmartLinkDocumentsViewTestCase(GenericDocumentViewTestCase):
'linking:smart_link_instances_for_document',
args=(self.document.pk,)
)
# Text must appear 2 times, only for the windows title and template
# Text must appear 3 times, 2 for the window titles and template
# heading. The two smart links are not shown.
self.assertContains(
response, text=self.document.label, count=2, status_code=200
response, text=self.document.label, count=3, status_code=200
)
def test_document_smart_link_list_view_with_permission(self):
@@ -152,9 +152,9 @@ class SmartLinkDocumentsViewTestCase(GenericDocumentViewTestCase):
args=(self.document.pk,)
)
# Text must appear 4 times: 2 for the windows title and template
# Text must appear 5 times: 3 for the window titles and template
# heading, plus 2 for the test.
self.assertContains(
response, text=self.document.label, count=4, status_code=200
response, text=self.document.label, count=5, status_code=200
)
+6 -6
View File
@@ -33,10 +33,10 @@ logger = logging.getLogger(__name__)
class ResolvedSmartLinkView(DocumentListView):
def dispatch(self, request, *args, **kwargs):
self.document = get_object_or_404(
Document, pk=self.kwargs['document_pk']
klass=Document, pk=self.kwargs['document_pk']
)
self.smart_link = get_object_or_404(
SmartLink, pk=self.kwargs['smart_link_pk']
klass=SmartLink, pk=self.kwargs['smart_link_pk']
)
AccessControlList.objects.check_access(
@@ -114,7 +114,7 @@ class SetupSmartLinkDocumentTypesView(AssignRemoveView):
}
def get_object(self):
return get_object_or_404(SmartLink, pk=self.kwargs['pk'])
return get_object_or_404(klass=SmartLink, pk=self.kwargs['pk'])
def left_list(self):
# TODO: filter document type list by user ACL
@@ -166,7 +166,7 @@ class SmartLinkListView(SingleObjectListView):
class DocumentSmartLinkListView(SmartLinkListView):
def dispatch(self, request, *args, **kwargs):
self.document = get_object_or_404(Document, pk=self.kwargs['pk'])
self.document = get_object_or_404(klass=Document, pk=self.kwargs['pk'])
AccessControlList.objects.check_access(
permissions=permission_document_view, user=request.user,
@@ -262,7 +262,7 @@ class SmartLinkConditionListView(SingleObjectListView):
return self.get_smart_link().conditions.all()
def get_smart_link(self):
return get_object_or_404(SmartLink, pk=self.kwargs['pk'])
return get_object_or_404(klass=SmartLink, pk=self.kwargs['pk'])
class SmartLinkConditionCreateView(SingleObjectCreateView):
@@ -300,7 +300,7 @@ class SmartLinkConditionCreateView(SingleObjectCreateView):
return self.get_smart_link().conditions.all()
def get_smart_link(self):
return get_object_or_404(SmartLink, pk=self.kwargs['pk'])
return get_object_or_404(klass=SmartLink, pk=self.kwargs['pk'])
class SmartLinkConditionEditView(SingleObjectEditView):