From 2e4322123f61160470ef7c879470a364f5f968e7 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Thu, 14 Jul 2005 03:17:09 +0000 Subject: [PATCH] Changed many-to-many API to be get_FOO_list instead of get_FOOs git-svn-id: http://code.djangoproject.com/svn/django/trunk@9 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/extensions.py | 2 +- django/core/meta.py | 8 ++++---- django/models/auth.py | 2 +- django/models/comments.py | 2 +- django/parts/auth/anonymoususers.py | 6 +++--- django/views/admin/main.py | 4 ++-- django/views/comments/comments.py | 2 +- django/views/defaults.py | 4 ++-- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/django/core/extensions.py b/django/core/extensions.py index c7a7c609aff..f37fac680e9 100644 --- a/django/core/extensions.py +++ b/django/core/extensions.py @@ -25,7 +25,7 @@ class PermLookupDict: def __init__(self, user, module_name): self.user, self.module_name = user, module_name def __repr__(self): - return str(self.user.get_permissions()) + return str(self.user.get_permission_list()) def __getitem__(self, perm_name): return self.user.has_perm("%s.%s" % (self.module_name, perm_name)) def __nonzero__(self): diff --git a/django/core/meta.py b/django/core/meta.py index be203efa37a..3915d5d1b86 100644 --- a/django/core/meta.py +++ b/django/core/meta.py @@ -517,10 +517,10 @@ class ModelBase(type): for f in opts.many_to_many: # Add "get_thingie" methods for many-to-many related objects. - # EXAMPLES: Poll.get_sites(), Story.get_bylines() + # EXAMPLES: Poll.get_site_list(), Story.get_byline_list() func = curry(method_get_many_to_many, f) func.__doc__ = "Returns a list of associated `%s.%s` objects." % (f.rel.to.app_label, f.rel.to.module_name) - attrs['get_%s' % f.name] = func + attrs['get_%s_list' % f.rel.name] = func # Add "set_thingie" methods for many-to-many related objects. # EXAMPLES: Poll.set_sites(), Story.set_bylines() func = curry(method_set_many_to_many, f) @@ -809,7 +809,7 @@ def method_get_many_to_one(field_with_rel, self): return getattr(self, cache_var) # Handles getting many-to-many related objects. -# Example: Poll.get_sites() +# Example: Poll.get_site_list() def method_get_many_to_many(field_with_rel, self): rel = field_with_rel.rel.to cache_var = '_%s_cache' % field_with_rel.name @@ -2064,7 +2064,7 @@ class ManyToManyField(Field): def __init__(self, to, **kwargs): kwargs['name'] = kwargs.get('name', to._meta.module_name) kwargs['verbose_name'] = kwargs.get('verbose_name', to._meta.verbose_name_plural) - kwargs['rel'] = ManyToMany(to, to._meta.object_name.lower() + '_id', + kwargs['rel'] = ManyToMany(to, to._meta.object_name.lower(), num_in_admin=kwargs.pop('num_in_admin', 0), related_name=kwargs.pop('related_name', None), filter_interface=kwargs.pop('filter_interface', None), diff --git a/django/models/auth.py b/django/models/auth.py index 96e6af9667e..6743d591ae3 100644 --- a/django/models/auth.py +++ b/django/models/auth.py @@ -101,7 +101,7 @@ class User(meta.Model): def get_all_permissions(self): if not hasattr(self, '_perm_cache'): import sets - self._perm_cache = sets.Set(["%s.%s" % (p.package, p.codename) for p in self.get_user_permissions()]) + self._perm_cache = sets.Set(["%s.%s" % (p.package, p.codename) for p in self.get_permission_list()]) self._perm_cache.update(self.get_group_permissions()) return self._perm_cache diff --git a/django/models/comments.py b/django/models/comments.py index 0d610c965c8..61988595dbc 100644 --- a/django/models/comments.py +++ b/django/models/comments.py @@ -152,7 +152,7 @@ class Comment(meta.Model): from django.conf.settings import COMMENTS_MODERATORS_GROUP if user.is_superuser: return True - for g in user.get_groups(): + for g in user.get_group_list(): if g.id == COMMENTS_MODERATORS_GROUP: return True return False diff --git a/django/parts/auth/anonymoususers.py b/django/parts/auth/anonymoususers.py index 2a86911f155..13fa44c434f 100644 --- a/django/parts/auth/anonymoususers.py +++ b/django/parts/auth/anonymoususers.py @@ -3,7 +3,7 @@ Anonymous users """ class AnonymousUser: - + def __init__(self): pass @@ -22,13 +22,13 @@ class AnonymousUser: def check_password(self, raw_password): raise NotImplementedError - def get_groups(self): + def get_group_list(self): return [] def set_groups(self, group_id_list): raise NotImplementedError - def get_permissions(self): + def get_permission_list(self): return [] def set_permissions(self, permission_id_list): diff --git a/django/views/admin/main.py b/django/views/admin/main.py index 73a1a5fda6b..8caeb6218e6 100644 --- a/django/views/admin/main.py +++ b/django/views/admin/main.py @@ -897,7 +897,7 @@ def change_stage(request, app_label, module_name, object_id): new_data.update(_get_flattened_data(f, getattr(obj, f.name))) for f in opts.many_to_many: if not f.rel.edit_inline: - new_data[f.name] = [i.id for i in getattr(obj, 'get_%s' % f.name)()] + new_data[f.name] = [i.id for i in getattr(obj, 'get_%s_list' % f.rel.name)()] for rel_obj, rel_field in inline_related_objects: var_name = rel_obj.object_name.lower() for i, rel_instance in enumerate(getattr(obj, 'get_%s_list' % opts.get_rel_object_method_name(rel_obj, rel_field))()): @@ -906,7 +906,7 @@ def change_stage(request, app_label, module_name, object_id): for k, v in _get_flattened_data(f, getattr(rel_instance, f.name)).items(): new_data['%s.%d.%s' % (var_name, i, k)] = v for f in rel_obj.many_to_many: - new_data['%s.%d.%s' % (var_name, i, f.name)] = [j.id for j in getattr(rel_instance, 'get_%s' % f.name)()] + new_data['%s.%d.%s' % (var_name, i, f.name)] = [j.id for j in getattr(rel_instance, 'get_%s_list' % f.rel.name)()] # If the object has ordered objects on its admin page, get the existing # order and flatten it into a comma-separated list of IDs. diff --git a/django/views/comments/comments.py b/django/views/comments/comments.py index 213faf42e64..ffad921ad32 100644 --- a/django/views/comments/comments.py +++ b/django/views/comments/comments.py @@ -108,7 +108,7 @@ class PublicCommentManipulator(AuthenticationForm): message = 'This comment was posted by a user who has posted fewer than %s comments:\n\n%s' % \ (COMMENTS_FIRST_FEW, c.get_as_text()) mail_managers("Comment posted by rookie user", message) - if COMMENTS_SKETCHY_USERS_GROUP and COMMENTS_SKETCHY_USERS_GROUP in [g.id for g in self.user_cache.get_groups()]: + if COMMENTS_SKETCHY_USERS_GROUP and COMMENTS_SKETCHY_USERS_GROUP in [g.id for g in self.user_cache.get_group_list()]: message = 'This comment was posted by a sketchy user:\n\n%s' % c.get_as_text() mail_managers("Comment posted by sketchy user (%s)" % self.user_cache.username, c.get_as_text()) return c diff --git a/django/views/defaults.py b/django/views/defaults.py index 72cb027b001..7677ecd8cd7 100644 --- a/django/views/defaults.py +++ b/django/views/defaults.py @@ -14,8 +14,8 @@ def shortcut(request, content_type_id, object_id): if not hasattr(obj, 'get_absolute_url'): raise Http404, "%s objects don't have get_absolute_url() methods" % content_type.name object_domain = None - if hasattr(obj, 'get_sites'): - site_list = obj.get_sites() + if hasattr(obj, 'get_site_list'): + site_list = obj.get_site_list() if site_list: object_domain = site_list[0].domain elif hasattr(obj, 'get_site'):