From 800cac7e3180858bcd3c2ecf467c4d2497a0eea4 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Sat, 10 Dec 2005 05:32:05 +0000 Subject: [PATCH] Negligible refactoring in django.core.meta.fields and django.contrib.admin.views.main. Taken from #1020. Refs #1020 git-svn-id: http://code.djangoproject.com/svn/django/trunk@1591 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/admin/views/main.py | 10 +++++----- django/core/meta/fields.py | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py index 879fc298f0..a3a7ddfb18 100644 --- a/django/contrib/admin/views/main.py +++ b/django/contrib/admin/views/main.py @@ -552,11 +552,11 @@ def _get_deleted_objects(deleted_objects, perms_needed, user, obj, opts, current nh = _nest_help # Bind to local variable for performance if current_depth > 16: return # Avoid recursing too deep. - objects_seen = [] + opts_seen = [] for related in opts.get_all_related_objects(): - if related.opts in objects_seen: + if related.opts in opts_seen: continue - objects_seen.append(related.opts) + opts_seen.append(related.opts) rel_opts_name = related.get_method_name_part() if isinstance(related.field.rel, meta.OneToOne): try: @@ -600,9 +600,9 @@ def _get_deleted_objects(deleted_objects, perms_needed, user, obj, opts, current if not user.has_perm(p): perms_needed.add(rel_opts.verbose_name) for related in opts.get_all_related_many_to_many_objects(): - if related.opts in objects_seen: + if related.opts in opts_seen: continue - objects_seen.append(related.opts) + opts_seen.append(related.opts) rel_opts_name = related.get_method_name_part() has_related_objs = False for sub_obj in getattr(obj, 'get_%s_list' % rel_opts_name)(): diff --git a/django/core/meta/fields.py b/django/core/meta/fields.py index c761295f33..e8ae73a84d 100644 --- a/django/core/meta/fields.py +++ b/django/core/meta/fields.py @@ -518,10 +518,11 @@ class FileField(Field): def save_file(self, new_data, new_object, original_object, change, rel): upload_field_name = self.get_manipulator_field_names('')[0] if new_data.get(upload_field_name, False): + func = getattr(new_object, 'save_%s_file' % self.name) if rel: - getattr(new_object, 'save_%s_file' % self.name)(new_data[upload_field_name][0]["filename"], new_data[upload_field_name][0]["content"]) + func(new_data[upload_field_name][0]["filename"], new_data[upload_field_name][0]["content"]) else: - getattr(new_object, 'save_%s_file' % self.name)(new_data[upload_field_name]["filename"], new_data[upload_field_name]["content"]) + func(new_data[upload_field_name]["filename"], new_data[upload_field_name]["content"]) def get_directory_name(self): return os.path.normpath(datetime.datetime.now().strftime(self.upload_to))