Skip to content

Commit 7c72b3e

Browse files
committed
Removed django-custom-field support
1 parent 8f35cba commit 7c72b3e

File tree

2 files changed

+9
-36
lines changed

2 files changed

+9
-36
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Project is now stable and feature complete. Of course it's always a good idea to
1818
## 2.0
1919

2020
2.0 adds support for Django 1.9 and 1.10. Support for 1.8 and under is dropped. Support for Python 2 is dropped.
21+
Removed support for django-custom-field
2122
Use 1.x for older environments.
2223

2324
## 1.17
@@ -31,7 +32,6 @@ atomic transactions. Please report any issues. I test against mysql innodb, post
3132
- Guess matches
3233
- Create, update, or both
3334
- Allow programmers to define special import methods for custom handling
34-
- Support for [django-custom-field](https://github.com/burke-software/django-custom-field)
3535
- Set related objects by any unique field
3636
- Simulate imports before commiting to database
3737
- Undo (create only) imports

simple_import/views.py

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,6 @@ def validate_match_columns(import_log, model_class, header_row):
6767
return errors
6868

6969

70-
def get_custom_fields_from_model(model_class):
71-
""" django-custom-fields support
72-
"""
73-
if 'custom_field' in settings.INSTALLED_APPS:
74-
from custom_field.models import CustomField
75-
try:
76-
content_type = ContentType.objects.get(
77-
model=model_class._meta.module_name,
78-
app_label=model_class._meta.app_label)
79-
except ContentType.DoesNotExist:
80-
content_type = None
81-
custom_fields = CustomField.objects.filter(content_type=content_type)
82-
return custom_fields
83-
84-
8570
@staff_member_required
8671
def match_columns(request, import_log_id):
8772
""" View to match import spreadsheet columns with database fields
@@ -180,12 +165,6 @@ def match_columns(request, import_log_id):
180165
if add:
181166
field_choices += ((field_name, field_verbose),)
182167

183-
# Include django-custom-field support
184-
custom_fields = get_custom_fields_from_model(model_class)
185-
if custom_fields:
186-
for custom_field in custom_fields:
187-
field_choices += (("simple_import_custom__{0}".format(custom_field),
188-
"{0} (Custom)".format(custom_field)),)
189168
# Include defined methods
190169
# Model must have a simple_import_methods defined
191170
if hasattr(model_class, 'simple_import_methods'):
@@ -231,8 +210,7 @@ def match_relations(request, import_log_id):
231210
for match in matches.exclude(field_name=""):
232211
field_name = match.field_name
233212

234-
if not field_name.startswith('simple_import_custom__') and \
235-
not field_name.startswith('simple_import_method__'):
213+
if not field_name.startswith('simple_import_method__'):
236214
field = model_class._meta.get_field(field_name)
237215
m2m = field.many_to_many
238216

@@ -293,15 +271,16 @@ def set_field_from_cell(import_log, new_object, header_row_field_name, cell):
293271
""" Set a field from a import cell. Use referenced fields the field
294272
is m2m or a foreign key.
295273
"""
296-
if (not header_row_field_name.startswith('simple_import_custom__') and
297-
not header_row_field_name.startswith('simple_import_method__')):
274+
if not header_row_field_name.startswith('simple_import_method__'):
298275
field = new_object._meta.get_field(header_row_field_name)
299-
direct = field.concrete
300276
m2m = field.many_to_many
301277
if m2m:
302278
new_object.simple_import_m2ms[header_row_field_name] = cell
303279
elif isinstance(field, ForeignKey):
304-
related_field_name = RelationalMatch.objects.get(import_log=import_log, field_name=field.name).related_field_name
280+
related_field_name = RelationalMatch.objects.get(
281+
import_log=import_log,
282+
field_name=field.name,
283+
).related_field_name
305284
related_model = field.remote_field.parent_model
306285
related_object = related_model.objects.get(**{related_field_name:cell})
307286
setattr(new_object, header_row_field_name, related_object)
@@ -330,19 +309,15 @@ def set_field_from_cell(import_log, new_object, header_row_field_name, cell):
330309
def set_method_from_cell(import_log, new_object, header_row_field_name, cell):
331310
""" Run a method from a import cell.
332311
"""
333-
if (not header_row_field_name.startswith('simple_import_custom__') and
334-
not header_row_field_name.startswith('simple_import_method__')):
312+
if not header_row_field_name.startswith('simple_import_method__'):
335313
pass
336-
elif header_row_field_name.startswith('simple_import_custom__'):
337-
new_object.set_custom_value(header_row_field_name[22:], cell)
338314
elif header_row_field_name.startswith('simple_import_method__'):
339315
getattr(new_object, header_row_field_name[22:])(cell)
340316

341317

342318
@staff_member_required
343319
def do_import(request, import_log_id):
344-
""" Import the data!
345-
"""
320+
""" Import the data! """
346321
import_log = get_object_or_404(ImportLog, id=import_log_id)
347322
if import_log.import_type == "N" and 'undo' in request.GET and request.GET['undo'] == "True":
348323
import_log.undo()
@@ -417,8 +392,6 @@ def do_import(request, import_log_id):
417392
set_method_from_cell(import_log, new_object, header_row_field_names[i], cell)
418393
elif header_row_default[i]:
419394
set_method_from_cell(import_log, new_object, header_row_field_names[i], header_row_default[i])
420-
# set_custom_value() calls save() on its own, but the same cannot be assumed
421-
# for other methods, e.g. set_password()
422395
new_object.save()
423396

424397
for key in new_object.simple_import_m2ms.keys():

0 commit comments

Comments
 (0)