Skip to content

Commit

Permalink
Update naming
Browse files Browse the repository at this point in the history
  • Loading branch information
yalef committed Feb 22, 2024
1 parent 3f458a2 commit a373b2b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
16 changes: 9 additions & 7 deletions import_export_extensions/api/serializers/import_job_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,23 @@ def to_representation(self, instance: models.ImportJob):
continue

original_fields = [
resource.export_field(f, row.original) if row.original else ""
for f in resource.get_user_visible_fields()
resource.export_field(field, row.original)
if row.original else ""
for field in resource.get_user_visible_fields()
]
current_fields = [
resource.export_field(f, row.instance)
for f in resource.get_user_visible_fields()
resource.export_field(field, row.instance)
for field in resource.get_user_visible_fields()
]

rows.append({
"operation": row.import_type,
"parsed_fields": [
{
"previous": v1,
"current": v2,
} for v1, v2 in itertools.zip_longest(
"previous": original_field,
"current": current_field,
} for original_field, current_field
in itertools.zip_longest(
original_fields,
current_fields,
fillvalue="",
Expand Down
10 changes: 5 additions & 5 deletions import_export_extensions/models/import_job.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import pathlib
import traceback
import uuid
Expand All @@ -8,7 +7,6 @@
from django.core.files import base as django_files
from django.db import models, transaction
from django.utils import encoding, module_loading, timezone
from django.utils.encoding import force_bytes
from django.utils.translation import gettext_lazy as _

import tablib
Expand Down Expand Up @@ -485,7 +483,7 @@ def _get_import_format_by_ext(

def _get_data_to_import(self) -> tablib.Dataset:
"""Read ``self.data_file`` content and convert it to dataset."""
_, file_ext = os.path.splitext(self.data_file.name)
file_ext = pathlib.Path(self.data_file.name).suffix
input_format = self._get_import_format_by_ext(
file_ext=file_ext,
)()
Expand Down Expand Up @@ -581,7 +579,7 @@ def _save_input_errors_file(self):
or self.input_errors_file
):
return
_, file_ext = os.path.splitext(self.data_file.name)
file_ext = pathlib.Path(self.data_file.name).suffix
file_format = self._get_import_format_by_ext(
file_ext=file_ext,
)()
Expand All @@ -591,7 +589,9 @@ def _save_input_errors_file(self):

# create file if `export_data` is not file
if not hasattr(export_data, "read"):
export_data = django_files.ContentFile(force_bytes(export_data))
export_data = django_files.ContentFile(
encoding.force_bytes(export_data),
)

file_name = self.resource.generate_export_filename(
file_format,
Expand Down
5 changes: 1 addition & 4 deletions tests/fake_app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ def __str__(self) -> str:

class Artist(models.Model):
"""Model representing artist."""
name = models.CharField(
max_length=100,
blank=False,
)
name = models.CharField(max_length=100)
bands = models.ManyToManyField("Band", through="Membership")

instrument = models.ForeignKey(
Expand Down

0 comments on commit a373b2b

Please sign in to comment.