Remove transformation manager methods

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2019-04-27 02:21:19 -04:00
parent 89bc78bd55
commit cd5bc8ba4b
9 changed files with 35 additions and 27 deletions

View File

@@ -168,6 +168,10 @@
* Commit the group event in conjunction with the role event * Commit the group event in conjunction with the role event
when a group is added or remove from role. when a group is added or remove from role.
* Update the role permission view to use the new AddRemoveView. * 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) 3.1.11 (2019-04-XX)
=================== ===================

View File

@@ -200,6 +200,10 @@ Other changes
* Commit the group event in conjunction with the role event * Commit the group event in conjunction with the role event
when a group is added or remove from role. when a group is added or remove from role.
* Update the role permission view to use the new AddRemoveView. * 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 Removals
-------- --------

View File

@@ -18,8 +18,8 @@ logger = logging.getLogger(__name__)
class TransformationManager(models.Manager): class TransformationManager(models.Manager):
def add_for_model(self, obj, transformation, arguments=None): def add_to_object(self, obj, transformation, arguments=None):
content_type = ContentType.objects.get_for_model(obj) content_type = ContentType.objects.get_for_model(model=obj)
self.create( self.create(
content_type=content_type, object_id=obj.pk, content_type=content_type, object_id=obj.pk,
@@ -32,7 +32,7 @@ class TransformationManager(models.Manager):
""" """
Copy transformation from source to all targets 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 # Get transformations
transformations = self.filter( transformations = self.filter(
@@ -67,7 +67,7 @@ class TransformationManager(models.Manager):
map(lambda entry: self.model(**entry), results), 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 as_classes == True returns the transformation classes from .classes
ready to be feed to the converter class ready to be feed to the converter class

View File

@@ -116,7 +116,7 @@ class TransformationTestCase(GenericDocumentTestCase):
document_page = self.document.pages.first() document_page = self.document.pages.first()
Transformation.objects.add_for_model( Transformation.objects.add_to_object(
obj=document_page, transformation=TransformationCrop, obj=document_page, transformation=TransformationCrop,
arguments={'top': '10'} arguments={'top': '10'}
) )
@@ -128,7 +128,7 @@ class TransformationTestCase(GenericDocumentTestCase):
document_page = self.document.pages.first() document_page = self.document.pages.first()
Transformation.objects.add_for_model( Transformation.objects.add_to_object(
obj=document_page, transformation=TransformationCrop, obj=document_page, transformation=TransformationCrop,
arguments={'top': 'x', 'left': '-'} arguments={'top': 'x', 'left': '-'}
) )
@@ -140,7 +140,7 @@ class TransformationTestCase(GenericDocumentTestCase):
document_page = self.document.pages.first() document_page = self.document.pages.first()
Transformation.objects.add_for_model( Transformation.objects.add_to_object(
obj=document_page, transformation=TransformationCrop, obj=document_page, transformation=TransformationCrop,
arguments={'top': '-1000', 'bottom': '100000000'} arguments={'top': '-1000', 'bottom': '100000000'}
) )
@@ -152,12 +152,12 @@ class TransformationTestCase(GenericDocumentTestCase):
document_page = self.document.pages.first() document_page = self.document.pages.first()
Transformation.objects.add_for_model( Transformation.objects.add_to_object(
obj=document_page, transformation=TransformationCrop, obj=document_page, transformation=TransformationCrop,
arguments={'top': '1000', 'bottom': '1000'} arguments={'top': '1000', 'bottom': '1000'}
) )
Transformation.objects.add_for_model( Transformation.objects.add_to_object(
obj=document_page, transformation=TransformationCrop, obj=document_page, transformation=TransformationCrop,
arguments={'left': '1000', 'right': '10000'} arguments={'left': '1000', 'right': '10000'}
) )
@@ -167,7 +167,7 @@ class TransformationTestCase(GenericDocumentTestCase):
def test_lineart_transformations(self): def test_lineart_transformations(self):
document_page = self.document.pages.first() document_page = self.document.pages.first()
Transformation.objects.add_for_model( Transformation.objects.add_to_object(
obj=document_page, transformation=TransformationLineArt, obj=document_page, transformation=TransformationLineArt,
arguments={} arguments={}
) )
@@ -177,21 +177,21 @@ class TransformationTestCase(GenericDocumentTestCase):
def test_rotate_transformations(self): def test_rotate_transformations(self):
document_page = self.document.pages.first() document_page = self.document.pages.first()
Transformation.objects.add_for_model( Transformation.objects.add_to_object(
obj=document_page, transformation=TransformationRotate90, obj=document_page, transformation=TransformationRotate90,
arguments={} arguments={}
) )
self.assertTrue(document_page.generate_image().startswith('page')) self.assertTrue(document_page.generate_image().startswith('page'))
Transformation.objects.add_for_model( Transformation.objects.add_to_object(
obj=document_page, transformation=TransformationRotate180, obj=document_page, transformation=TransformationRotate180,
arguments={} arguments={}
) )
self.assertTrue(document_page.generate_image().startswith('page')) self.assertTrue(document_page.generate_image().startswith('page'))
Transformation.objects.add_for_model( Transformation.objects.add_to_object(
obj=document_page, transformation=TransformationRotate270, obj=document_page, transformation=TransformationRotate270,
arguments={} arguments={}
) )

View File

@@ -83,7 +83,7 @@ class TransformationCreateView(SingleObjectCreateView):
) )
def get_queryset(self): 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): class TransformationDeleteView(SingleObjectDeleteView):
@@ -233,4 +233,4 @@ class TransformationListView(SingleObjectListView):
} }
def get_object_list(self): 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)

View File

@@ -165,7 +165,7 @@ class DocumentPage(models.Model):
transformation_list = [] transformation_list = []
# Stored transformations first # 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) transformation_list.append(stored_transformation)
# Interactive transformations second # Interactive transformations second

View File

@@ -143,7 +143,7 @@ class DocumentVersion(models.Model):
for page in self.pages.all(): for page in self.pages.all():
degrees = page.detect_orientation() degrees = page.detect_orientation()
if degrees: if degrees:
Transformation.objects.add_for_model( Transformation.objects.add_to_object(
obj=page, transformation=TransformationRotate, obj=page, transformation=TransformationRotate,
arguments='{{"degrees": {}}}'.format(360 - degrees) arguments='{{"degrees": {}}}'.format(360 - degrees)
) )

View File

@@ -388,7 +388,7 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
) )
self.assertQuerysetEqual( self.assertQuerysetEqual(
Transformation.objects.get_for_model(document_page), Transformation.objects.get_for_object(obj=document_page),
(repr(transformation),) (repr(transformation),)
) )
@@ -400,7 +400,7 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
self.assertEqual(response.status_code, 302) self.assertEqual(response.status_code, 302)
self.assertQuerysetEqual( self.assertQuerysetEqual(
Transformation.objects.get_for_model(document_page), Transformation.objects.get_for_object(obj=document_page),
(repr(transformation),) (repr(transformation),)
) )
@@ -413,7 +413,7 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
arguments=TEST_TRANSFORMATION_ARGUMENT arguments=TEST_TRANSFORMATION_ARGUMENT
) )
self.assertQuerysetEqual( self.assertQuerysetEqual(
Transformation.objects.get_for_model(document_page), Transformation.objects.get_for_object(obj=document_page),
(repr(transformation),) (repr(transformation),)
) )
@@ -428,7 +428,7 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
self.assertEqual(response.status_code, 302) self.assertEqual(response.status_code, 302)
self.assertEqual( 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): def _request_document_multiple_clear_transformations(self):
@@ -447,7 +447,7 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
) )
self.assertQuerysetEqual( self.assertQuerysetEqual(
Transformation.objects.get_for_model(document_page), Transformation.objects.get_for_object(obj==document_page),
(repr(transformation),) (repr(transformation),)
) )
@@ -456,7 +456,7 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
response = self._request_document_multiple_clear_transformations() response = self._request_document_multiple_clear_transformations()
self.assertEqual(response.status_code, 302) self.assertEqual(response.status_code, 302)
self.assertQuerysetEqual( self.assertQuerysetEqual(
Transformation.objects.get_for_model(document_page), Transformation.objects.get_for_object(obj=document_page),
(repr(transformation),) (repr(transformation),)
) )
@@ -470,7 +470,7 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
) )
self.assertQuerysetEqual( self.assertQuerysetEqual(
Transformation.objects.get_for_model(document_page), Transformation.objects.get_for_object(obj=document_page),
(repr(transformation),) (repr(transformation),)
) )
@@ -485,7 +485,7 @@ class DocumentsViewsTestCase(GenericDocumentViewTestCase):
self.assertEqual(response.status_code, 302) self.assertEqual(response.status_code, 302)
self.assertEqual( 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): def _request_empty_trash_view(self):

View File

@@ -515,7 +515,7 @@ class DocumentTransformationsClearView(MultipleObjectConfirmActionView):
def object_action(self, form, instance): def object_action(self, form, instance):
try: try:
for page in instance.pages.all(): 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: except Exception as exception:
messages.error( messages.error(
self.request, _( self.request, _(
@@ -539,7 +539,7 @@ class DocumentTransformationsCloneView(FormView):
) )
for page in target_pages: for page in target_pages:
Transformation.objects.get_for_model(page).delete() Transformation.objects.get_for_object(obj=page).delete()
Transformation.objects.copy( Transformation.objects.copy(
source=form.cleaned_data['page'], targets=target_pages source=form.cleaned_data['page'], targets=target_pages