@@ -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
8671def 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):
330309def 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
343319def 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