Remove transformation manager methods
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -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)
|
||||
===================
|
||||
|
||||
@@ -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
|
||||
--------
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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={}
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
)
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user