magic-removal: Renamed get_method_name_part() to get_accessor_name()

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2126 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-01-26 04:12:16 +00:00
parent faf9ff6316
commit 1833c53b21
5 changed files with 17 additions and 16 deletions

View File

@ -332,7 +332,7 @@ def change_stage(request, app_label, model_name, object_id):
wrt = related.opts.order_with_respect_to
if wrt and wrt.rel and wrt.rel.to == opts:
func = getattr(manipulator.original_object, 'get_%s_list' %
related.get_method_name_part())
related.get_accessor_name())
orig_list = func()
form.order_objects.extend(orig_list)
@ -362,7 +362,7 @@ def _get_deleted_objects(deleted_objects, perms_needed, user, obj, opts, current
if related.opts in opts_seen:
continue
opts_seen.append(related.opts)
rel_opts_name = related.get_method_name_part()
rel_opts_name = related.get_accessor_name()
if isinstance(related.field.rel, models.OneToOne):
try:
sub_obj = getattr(obj, 'get_%s' % rel_opts_name)()
@ -408,7 +408,7 @@ def _get_deleted_objects(deleted_objects, perms_needed, user, obj, opts, current
if related.opts in opts_seen:
continue
opts_seen.append(related.opts)
rel_opts_name = related.get_method_name_part()
rel_opts_name = related.get_accessor_name()
has_related_objs = False
for sub_obj in getattr(obj, 'get_%s_list' % rel_opts_name)():
has_related_objs = True

View File

@ -202,7 +202,7 @@ class Model(object):
seen_objs.setdefault(self.__class__, {})[pk_val] = self
for related in self._meta.get_all_related_objects():
rel_opts_name = related.get_method_name_part()
rel_opts_name = related.get_accessor_name()
if isinstance(related.field.rel, OneToOne):
try:
sub_obj = getattr(self, 'get_%s' % rel_opts_name)()

View File

@ -153,7 +153,7 @@ class ForeignKey(SharedMethods, Field):
return Field.flatten_data(self, follow, obj)
def contribute_to_related_class(self, cls, related):
rel_obj_name = related.get_method_name_part()
rel_obj_name = related.get_accessor_name()
# Add "get_thingie" methods for many-to-one related objects.
# EXAMPLE: Poll.get_choice()
setattr(cls, 'get_%s' % rel_obj_name, curry(cls._get_related, method_name='get_object', rel_class=related.model, rel_field=related.field))
@ -196,7 +196,7 @@ class OneToOneField(SharedMethods, IntegerField):
self.deprecated_args.append(name)
def contribute_to_related_class(self, cls, related):
rel_obj_name = related.get_method_name_part()
rel_obj_name = related.get_accessor_name()
# Add "get_thingie" methods for one-to-one related objects.
# EXAMPLE: Place.get_restaurants_restaurant()
setattr(cls, 'get_%s' % rel_obj_name,
@ -286,7 +286,7 @@ class ManyToManyField(RelatedField, Field):
setattr(cls, 'set_%s' % self.name, curry(cls._set_many_to_many_objects, field_with_rel=self))
def contribute_to_related_class(self, cls, related):
rel_obj_name = related.get_method_name_part()
rel_obj_name = related.get_accessor_name()
setattr(cls, 'get_%s' % rel_obj_name, curry(cls._get_related_many_to_many, method_name='get_object', rel_class=related.model, rel_field=related.field))
setattr(cls, 'get_%s_count' % rel_obj_name, curry(cls._get_related_many_to_many, method_name='get_count', rel_class=related.model, rel_field=related.field))
setattr(cls, 'get_%s_list' % rel_obj_name, curry(cls._get_related_many_to_many, method_name='get_list', rel_class=related.model, rel_field=related.field))

View File

@ -154,7 +154,7 @@ class AutomaticManipulator(forms.Manipulator):
if self.change:
if rel_new_data[related.opts.pk.name][0]:
try:
old_rel_obj = getattr(self.original_object, 'get_%s' % related.get_method_name_part() )(**{'%s__exact' % related.opts.pk.name: rel_new_data[related.opts.pk.attname][0]})
old_rel_obj = getattr(self.original_object, 'get_%s' % related.get_accessor_name() )(**{'%s__exact' % related.opts.pk.name: rel_new_data[related.opts.pk.attname][0]})
except ObjectDoesNotExist:
pass

View File

@ -44,7 +44,7 @@ class RelatedObject(object):
def get_list(self, parent_instance=None):
"Get the list of this type of object from an instance of the parent class."
if parent_instance != None:
func_name = 'get_%s_list' % self.get_method_name_part()
func_name = 'get_%s_list' % self.get_accessor_name()
func = getattr(parent_instance, func_name)
return func()
else:
@ -77,21 +77,22 @@ class RelatedObject(object):
def bind(self, field_mapping, original, bound_related_object_class=BoundRelatedObject):
return bound_related_object_class(self, field_mapping, original)
def get_method_name_part(self):
# This method encapsulates the logic that decides what name to give a
# method that retrieves related many-to-one or many-to-many objects.
# Usually it just uses the lower-cased object_name, but if the related
# object is in another app, the related object's app_label is appended.
def get_accessor_name(self):
# This method encapsulates the logic that decides what name to give an
# accessor descriptor that retrieves related many-to-one or
# many-to-many objects. Usually it just uses the lower-cased
# object_name, but if the related object is in another app, the related
# object's app_label is appended.
#
# Examples:
#
# # Normal case -- a related object in the same app.
# # This method returns "choice".
# Poll.get_choice_list()
# Poll.choice_set
#
# # A related object in a different app.
# # This method returns "lcom_bestofaward".
# Place.get_lcom_bestofaward_list() # "lcom_bestofaward"
# Place.lcom_bestofaward_set # "lcom_bestofaward"
rel_obj_name = self.field.rel.related_name or self.opts.object_name.lower()
if self.parent_opts.app_label != self.opts.app_label:
rel_obj_name = '%s_%s' % (self.opts.app_label, rel_obj_name)