From de40977f5f8f2705e3f2c5791da6cb2fd430da5b Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Mon, 30 May 2016 19:14:34 -0400 Subject: [PATCH] Convert checkouts app to use organizations. --- mayan/apps/checkouts/api_views.py | 2 +- mayan/apps/checkouts/managers.py | 4 ++-- mayan/apps/checkouts/tests/test_models.py | 5 ++++- mayan/apps/checkouts/views.py | 7 +++---- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/mayan/apps/checkouts/api_views.py b/mayan/apps/checkouts/api_views.py index 939cf28f1d..e1052ddfef 100644 --- a/mayan/apps/checkouts/api_views.py +++ b/mayan/apps/checkouts/api_views.py @@ -66,7 +66,7 @@ class APICheckedoutDocumentListView(generics.ListCreateAPIView): if serializer.is_valid(): document = get_object_or_404( - Document, pk=serializer.data['document'] + Document.on_organization, pk=serializer.data['document'] ) try: Permission.check_permissions( diff --git a/mayan/apps/checkouts/managers.py b/mayan/apps/checkouts/managers.py index 5af640227f..cb10095132 100644 --- a/mayan/apps/checkouts/managers.py +++ b/mayan/apps/checkouts/managers.py @@ -25,14 +25,14 @@ class DocumentCheckoutManager(models.Manager): ) def checked_out_documents(self): - return Document.objects.filter( + return Document.on_organization.filter( pk__in=self.model.objects.all().values_list( 'document__pk', flat=True ) ) def expired_check_outs(self): - expired_list = Document.objects.filter( + expired_list = Document.on_organization.filter( pk__in=self.model.objects.filter( expiration_datetime__lte=now() ).values_list('document__pk', flat=True) diff --git a/mayan/apps/checkouts/tests/test_models.py b/mayan/apps/checkouts/tests/test_models.py index 74a5b256a3..3502253236 100644 --- a/mayan/apps/checkouts/tests/test_models.py +++ b/mayan/apps/checkouts/tests/test_models.py @@ -12,6 +12,7 @@ from documents.models import DocumentType from documents.tests.literals import ( TEST_DOCUMENT_TYPE, TEST_SMALL_DOCUMENT_PATH ) +from organizations.tests.base import OrganizationTestCase from user_management.tests.literals import ( TEST_ADMIN_USERNAME, TEST_ADMIN_EMAIL, TEST_ADMIN_PASSWORD ) @@ -21,8 +22,9 @@ from ..models import DocumentCheckout @override_settings(OCR_AUTO_OCR=False) -class DocumentCheckoutTestCase(TestCase): +class DocumentCheckoutTestCase(OrganizationTestCase): def setUp(self): + super(DocumentCheckoutTestCase, self).setUp() self.admin_user = get_user_model().objects.create_superuser( username=TEST_ADMIN_USERNAME, email=TEST_ADMIN_EMAIL, password=TEST_ADMIN_PASSWORD @@ -39,6 +41,7 @@ class DocumentCheckoutTestCase(TestCase): def tearDown(self): self.document_type.delete() + super(DocumentCheckoutTestCase, self).tearDown() def test_document_checkout(self): expiration_datetime = now() + datetime.timedelta(days=1) diff --git a/mayan/apps/checkouts/views.py b/mayan/apps/checkouts/views.py index a469265964..0c4b7dfe73 100644 --- a/mayan/apps/checkouts/views.py +++ b/mayan/apps/checkouts/views.py @@ -30,7 +30,7 @@ class CheckoutDocumentView(SingleObjectCreateView): form_class = DocumentCheckoutForm def dispatch(self, request, *args, **kwargs): - self.document = get_object_or_404(Document, pk=self.kwargs['pk']) + self.document = get_object_or_404(Document.on_organization, pk=self.kwargs['pk']) try: Permission.check_permissions( @@ -108,7 +108,6 @@ class CheckoutListView(DocumentListView): class CheckoutDetailView(SingleObjectDetailView): form_class = DocumentCheckoutDefailForm - model = Document object_permission = permission_document_checkout_detail_view def get_extra_context(self): @@ -120,7 +119,7 @@ class CheckoutDetailView(SingleObjectDetailView): } def get_object(self): - return get_object_or_404(Document, pk=self.kwargs['pk']) + return get_object_or_404(Document.on_organization, pk=self.kwargs['pk']) class DocumentCheckinView(ConfirmView): @@ -142,7 +141,7 @@ class DocumentCheckinView(ConfirmView): return context def get_object(self): - return get_object_or_404(Document, pk=self.kwargs['pk']) + return get_object_or_404(Document.on_organization, pk=self.kwargs['pk']) def get_post_action_redirect(self): return reverse('checkouts:checkout_info', args=(self.get_object().pk,))