diff --git a/HISTORY.rst b/HISTORY.rst index f6347ec0d7..a0c08311fb 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -168,6 +168,10 @@ * Commit the group event in conjunction with the role event when a group is added or remove from role. * Update the role permission view to use the new AddRemoveView. +* Rename transformation manager method add_for_model to + add_to_object. +* Rename transformation manager method get_for_model to + get_for_object. 3.1.11 (2019-04-XX) =================== diff --git a/docs/releases/3.2.rst b/docs/releases/3.2.rst index c88b2765d3..d99900cea6 100644 --- a/docs/releases/3.2.rst +++ b/docs/releases/3.2.rst @@ -200,6 +200,10 @@ Other changes * Commit the group event in conjunction with the role event when a group is added or remove from role. * Update the role permission view to use the new AddRemoveView. +* Rename transformation manager method add_for_model to + add_to_object. +* Rename transformation manager method get_for_model to + get_for_object. Removals -------- diff --git a/mayan/apps/converter/managers.py b/mayan/apps/converter/managers.py index b71e580e8b..444907cac1 100644 --- a/mayan/apps/converter/managers.py +++ b/mayan/apps/converter/managers.py @@ -18,8 +18,8 @@ logger = logging.getLogger(__name__) class TransformationManager(models.Manager): - def add_for_model(self, obj, transformation, arguments=None): - content_type = ContentType.objects.get_for_model(obj) + def add_to_object(self, obj, transformation, arguments=None): + content_type = ContentType.objects.get_for_model(model=obj) self.create( content_type=content_type, object_id=obj.pk, @@ -32,7 +32,7 @@ class TransformationManager(models.Manager): """ Copy transformation from source to all targets """ - content_type = ContentType.objects.get_for_model(source) + content_type = ContentType.objects.get_for_model(model=source) # Get transformations transformations = self.filter( @@ -67,7 +67,7 @@ class TransformationManager(models.Manager): map(lambda entry: self.model(**entry), results), ) - def get_for_model(self, obj, as_classes=False): + def get_for_object(self, obj, as_classes=False): """ as_classes == True returns the transformation classes from .classes ready to be feed to the converter class diff --git a/mayan/apps/converter/tests/test_transformations.py b/mayan/apps/converter/tests/test_transformations.py index cde27af70e..40051d4544 100644 --- a/mayan/apps/converter/tests/test_transformations.py +++ b/mayan/apps/converter/tests/test_transformations.py @@ -116,7 +116,7 @@ class TransformationTestCase(GenericDocumentTestCase): document_page = self.document.pages.first() - Transformation.objects.add_for_model( + Transformation.objects.add_to_object( obj=document_page, transformation=TransformationCrop, arguments={'top': '10'} ) @@ -128,7 +128,7 @@ class TransformationTestCase(GenericDocumentTestCase): document_page = self.document.pages.first() - Transformation.objects.add_for_model( + Transformation.objects.add_to_object( obj=document_page, transformation=TransformationCrop, arguments={'top': 'x', 'left': '-'} ) @@ -140,7 +140,7 @@ class TransformationTestCase(GenericDocumentTestCase): document_page = self.document.pages.first() - Transformation.objects.add_for_model( + Transformation.objects.add_to_object( obj=document_page, transformation=TransformationCrop, arguments={'top': '-1000', 'bottom': '100000000'} ) @@ -152,12 +152,12 @@ class TransformationTestCase(GenericDocumentTestCase): document_page = self.document.pages.first() - Transformation.objects.add_for_model( + Transformation.objects.add_to_object( obj=document_page, transformation=TransformationCrop, arguments={'top': '1000', 'bottom': '1000'} ) - Transformation.objects.add_for_model( + Transformation.objects.add_to_object( obj=document_page, transformation=TransformationCrop, arguments={'left': '1000', 'right': '10000'} ) @@ -167,7 +167,7 @@ class TransformationTestCase(GenericDocumentTestCase): def test_lineart_transformations(self): document_page = self.document.pages.first() - Transformation.objects.add_for_model( + Transformation.objects.add_to_object( obj=document_page, transformation=TransformationLineArt, arguments={} ) @@ -177,21 +177,21 @@ class TransformationTestCase(GenericDocumentTestCase): def test_rotate_transformations(self): document_page = self.document.pages.first() - Transformation.objects.add_for_model( + Transformation.objects.add_to_object( obj=document_page, transformation=TransformationRotate90, arguments={} ) self.assertTrue(document_page.generate_image().startswith('page')) - Transformation.objects.add_for_model( + Transformation.objects.add_to_object( obj=document_page, transformation=TransformationRotate180, arguments={} ) self.assertTrue(document_page.generate_image().startswith('page')) - Transformation.objects.add_for_model( + Transformation.objects.add_to_object( obj=document_page, transformation=TransformationRotate270, arguments={} ) diff --git a/mayan/apps/converter/views.py b/mayan/apps/converter/views.py index c2bb5cb281..847eaef017 100644 --- a/mayan/apps/converter/views.py +++ b/mayan/apps/converter/views.py @@ -83,7 +83,7 @@ class TransformationCreateView(SingleObjectCreateView): ) def get_queryset(self): - return Transformation.objects.get_for_model(self.content_object) + return Transformation.objects.get_for_object(obj=self.content_object) class TransformationDeleteView(SingleObjectDeleteView): @@ -233,4 +233,4 @@ class TransformationListView(SingleObjectListView): } def get_object_list(self): - return Transformation.objects.get_for_model(obj=self.content_object) + return Transformation.objects.get_for_object(obj=self.content_object) diff --git a/mayan/apps/documents/models/document_page_models.py b/mayan/apps/documents/models/document_page_models.py index 4c6f42fdd6..5ec7d6c2c4 100644 --- a/mayan/apps/documents/models/document_page_models.py +++ b/mayan/apps/documents/models/document_page_models.py @@ -165,7 +165,7 @@ class DocumentPage(models.Model): transformation_list = [] # Stored transformations first - for stored_transformation in Transformation.objects.get_for_model(self, as_classes=True): + for stored_transformation in Transformation.objects.get_for_object(self, as_classes=True): transformation_list.append(stored_transformation) # Interactive transformations second diff --git a/mayan/apps/documents/models/document_version_models.py b/mayan/apps/documents/models/document_version_models.py index edccfb6372..b76c048b65 100644 --- a/mayan/apps/documents/models/document_version_models.py +++ b/mayan/apps/documents/models/document_version_models.py @@ -143,7 +143,7 @@ class DocumentVersion(models.Model): for page in self.pages.all(): degrees = page.detect_orientation() if degrees: - Transformation.objects.add_for_model( + Transformation.objects.add_to_object( obj=page, transformation=TransformationRotate, arguments='{{"degrees": {}}}'.format(360 - degrees) ) diff --git a/mayan/apps/documents/tests/test_document_views.py b/mayan/apps/documents/tests/test_document_views.py index e59c7462db..b100f1a688 100644 --- a/mayan/apps/documents/tests/test_document_views.py +++ b/mayan/apps/documents/tests/test_document_views.py @@ -388,7 +388,7 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase): ) self.assertQuerysetEqual( - Transformation.objects.get_for_model(document_page), + Transformation.objects.get_for_object(obj=document_page), (repr(transformation),) ) @@ -400,7 +400,7 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase): self.assertEqual(response.status_code, 302) self.assertQuerysetEqual( - Transformation.objects.get_for_model(document_page), + Transformation.objects.get_for_object(obj=document_page), (repr(transformation),) ) @@ -413,7 +413,7 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase): arguments=TEST_TRANSFORMATION_ARGUMENT ) self.assertQuerysetEqual( - Transformation.objects.get_for_model(document_page), + Transformation.objects.get_for_object(obj=document_page), (repr(transformation),) ) @@ -428,7 +428,7 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase): self.assertEqual(response.status_code, 302) self.assertEqual( - Transformation.objects.get_for_model(document_page).count(), 0 + Transformation.objects.get_for_object(obj=document_page).count(), 0 ) def _request_document_multiple_clear_transformations(self): @@ -447,7 +447,7 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase): ) self.assertQuerysetEqual( - Transformation.objects.get_for_model(document_page), + Transformation.objects.get_for_object(obj==document_page), (repr(transformation),) ) @@ -456,7 +456,7 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase): response = self._request_document_multiple_clear_transformations() self.assertEqual(response.status_code, 302) self.assertQuerysetEqual( - Transformation.objects.get_for_model(document_page), + Transformation.objects.get_for_object(obj=document_page), (repr(transformation),) ) @@ -470,7 +470,7 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase): ) self.assertQuerysetEqual( - Transformation.objects.get_for_model(document_page), + Transformation.objects.get_for_object(obj=document_page), (repr(transformation),) ) @@ -485,7 +485,7 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase): self.assertEqual(response.status_code, 302) self.assertEqual( - Transformation.objects.get_for_model(document_page).count(), 0 + Transformation.objects.get_for_object(obj=document_page).count(), 0 ) def _request_empty_trash_view(self): diff --git a/mayan/apps/documents/views/document_views.py b/mayan/apps/documents/views/document_views.py index b5c0c68f28..9d5f3fc750 100644 --- a/mayan/apps/documents/views/document_views.py +++ b/mayan/apps/documents/views/document_views.py @@ -515,7 +515,7 @@ class DocumentTransformationsClearView(MultipleObjectConfirmActionView): def object_action(self, form, instance): try: for page in instance.pages.all(): - Transformation.objects.get_for_model(page).delete() + Transformation.objects.get_for_object(obj=page).delete() except Exception as exception: messages.error( self.request, _( @@ -539,7 +539,7 @@ class DocumentTransformationsCloneView(FormView): ) for page in target_pages: - Transformation.objects.get_for_model(page).delete() + Transformation.objects.get_for_object(obj=page).delete() Transformation.objects.copy( source=form.cleaned_data['page'], targets=target_pages