Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions questions/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ def before_import_row(self, row, **kwargs):
- Issue with BooleanFields because Notion exports Yes/No
"""
# 'id' field
if "id" not in row:
if "id" not in row and "\ufeffid" in row:
row["id"] = row["\ufeffid"]

# boolean fields
BOOLEAN_FIELDS = ["has_ordered_answers"]
for boolean_field in BOOLEAN_FIELDS:
row[boolean_field] = True if (row[boolean_field] == "Yes") else False
if boolean_field in row:
row[boolean_field] = True if (row[boolean_field] == "Yes") else False

def import_obj(self, instance, row, dry_run):
def import_obj(self, instance, row, dry_run, **kwargs):
"""
Manually manage M2M column
- tags in an existing instance: get the row's comma-seperated tags, get their ids,
Expand All @@ -68,15 +70,15 @@ def import_obj(self, instance, row, dry_run):
if list(instance.tags.values_list("id", flat=True)) != tag_ids:
instance.tags.set(tag_ids)
self._m2m_updated = True
super(QuestionResource, self).import_obj(instance, row, dry_run)
super(QuestionResource, self).import_obj(instance, row, dry_run, **kwargs)

def skip_row(self, instance, original):
def skip_row(self, instance, original, *args, **kwargs):
"""
Highlight row if M2M column was updated
"""
if self._m2m_updated:
return False
return super(QuestionResource, self).skip_row(instance, original)
return super(QuestionResource, self).skip_row(instance, original, *args, **kwargs)

def after_import(self, dataset, result, using_transactions, dry_run, **kwargs):
# result.totals: OrderedDict, keys: 'new', 'update', 'delete', 'skip', 'error', 'invalid'
Expand All @@ -86,6 +88,7 @@ def after_import(self, dataset, result, using_transactions, dry_run, **kwargs):

class Meta:
model = Question
import_id_fields = ("id",)
skip_unchanged = True
report_skipped = False

Expand Down Expand Up @@ -313,7 +316,7 @@ def get_import_formats(self):
"""
Restrict import formats to csv only
"""
formats = ImportMixin.formats[:1]
formats = self.formats[:1]
return [f for f in formats if f().can_import()]

def has_answer_explanation(self, instance):
Expand Down
Loading