Skip to content

Commit

Permalink
Fix code style issues with Black
Browse files Browse the repository at this point in the history
  • Loading branch information
Lint Action committed Mar 24, 2021
1 parent 8286951 commit 08f6a3c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 11 deletions.
4 changes: 3 additions & 1 deletion model_clone/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class CloneModelAdminMixin(object):

def change_view(self, request, object_id, form_url="", extra_context=None):
extra_context = extra_context or {}
extra_context["include_duplicate_object_link"] = self.include_duplicate_object_link
extra_context[
"include_duplicate_object_link"
] = self.include_duplicate_object_link
if self.include_duplicate_object_link:
to_field = request.POST.get(TO_FIELD_VAR, request.GET.get(TO_FIELD_VAR))
if to_field and not self.to_field_allowed(request, to_field):
Expand Down
20 changes: 15 additions & 5 deletions model_clone/mixins/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ def check(cls, **kwargs):
"Conflicting configuration.",
hint=(
'Please provide either "_clone_fields"'
+ ' or "_clone_excluded_fields" for model {}'.format(cls.__name__)
+ ' or "_clone_excluded_fields" for model {}'.format(
cls.__name__
)
),
obj=cls,
id="{}.E002".format(ModelCloneConfig.name),
Expand All @@ -219,7 +221,9 @@ def check(cls, **kwargs):
"Conflicting configuration.",
hint=(
'Please provide either "_clone_m2m_fields"'
+ ' or "_clone_excluded_m2m_fields" for model {}'.format(cls.__name__)
+ ' or "_clone_excluded_m2m_fields" for model {}'.format(
cls.__name__
)
),
obj=cls,
id="{}.E002".format(ModelCloneConfig.name),
Expand All @@ -239,7 +243,9 @@ def check(cls, **kwargs):
"Please provide either "
+ '"_clone_m2o_or_o2m_fields"'
+ " or "
+ '"_clone_excluded_m2o_or_o2m_fields" for {}'.format(cls.__name__)
+ '"_clone_excluded_m2o_or_o2m_fields" for {}'.format(
cls.__name__
)
),
obj=cls,
id="{}.E002".format(ModelCloneConfig.name),
Expand Down Expand Up @@ -364,7 +370,9 @@ def make_clone(self, attrs=None, sub_clone=False):
for field in one_to_one_fields:
rel_object = getattr(self, field.related_name, None)
if rel_object:
if hasattr(rel_object, "make_clone") and callable(rel_object.make_clone):
if hasattr(rel_object, "make_clone") and callable(
rel_object.make_clone
):
rel_object.make_clone(
attrs={field.remote_field.name: duplicate}, sub_clone=True
)
Expand All @@ -380,7 +388,9 @@ def make_clone(self, attrs=None, sub_clone=False):
items = []
for item in getattr(self, field.related_name).all():
try:
item_clone = item.make_clone(attrs={field.remote_field.name: duplicate})
item_clone = item.make_clone(
attrs={field.remote_field.name: duplicate}
)
except IntegrityError:
item_clone = item.make_clone(
attrs={field.remote_field.name: duplicate}, sub_clone=True
Expand Down
8 changes: 6 additions & 2 deletions model_clone/tests/test_clone_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def test_cloning_with_field_overridden(self):

def test_cloning_using_auto_now_field_is_updated(self):
name = "New Book"
instance = Book.objects.create(name=name, created_by=self.user1, slug=slugify(name))
instance = Book.objects.create(
name=name, created_by=self.user1, slug=slugify(name)
)
new_name = "My New Book"
clone = instance.make_clone(attrs={"name": new_name})

Expand Down Expand Up @@ -185,7 +187,9 @@ def test_cloning_unique_fields_is_valid(self):
"{} {} {}".format(first_name, Author.UNIQUE_DUPLICATE_SUFFIX, 1),
)

@patch("sample.models.Author.USE_UNIQUE_DUPLICATE_SUFFIX", new_callable=PropertyMock)
@patch(
"sample.models.Author.USE_UNIQUE_DUPLICATE_SUFFIX", new_callable=PropertyMock
)
def test_cloning_unique_field_with_use_unique_duplicate_suffix_set_to_False(
self,
use_unique_duplicate_suffix_mock,
Expand Down
4 changes: 3 additions & 1 deletion model_clone/tests/test_create_copy_of_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def test_cloning_unique_fk_field_without_a_fallback_value_is_invalid(self):

def test_cloning_excluded_field_without_a_fallback_value_is_invalid(self):
name = "New Library"
instance = Book.objects.create(name=name, created_by=self.user1, slug=slugify(name))
instance = Book.objects.create(
name=name, created_by=self.user1, slug=slugify(name)
)

with self.assertRaises(IntegrityError):
create_copy_of_instance(
Expand Down
10 changes: 8 additions & 2 deletions model_clone/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ def create_copy_of_instance(instance, exclude=(), save_new=True, attrs=None):
f.name
for f in instance._meta.fields
if any(
[all([f.name not in defaults, f.attname not in defaults]), f.has_default(), f.null]
[
all([f.name not in defaults, f.attname not in defaults]),
f.has_default(),
f.null,
]
)
]

Expand Down Expand Up @@ -137,7 +141,9 @@ def generate_value(value, suffix, transform, max_length, max_attempts):
yield get_value(value, suffix, transform, max_length, i)

raise StopIteration(
"CloneError: max unique attempts for {} exceeded ({})".format(value, max_attempts)
"CloneError: max unique attempts for {} exceeded ({})".format(
value, max_attempts
)
)


Expand Down

0 comments on commit 08f6a3c

Please sign in to comment.