Commits

Anonymous committed 6c66ed8

Changed many-to-many API to be get_FOO_list instead of get_FOOs

  • Participants
  • Parent commits 613553d

Comments (0)

Files changed (8)

File django/core/extensions.py

     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):

File django/core/meta.py

 
         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)
     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
     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),

File django/models/auth.py

     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
 

File django/models/comments.py

         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

File django/parts/auth/anonymoususers.py

 """
 
 class AnonymousUser:
-    
+
     def __init__(self):
         pass
 
     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):

File django/views/admin/main.py

             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))()):
                         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.

File django/views/comments/comments.py

             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

File django/views/defaults.py

     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'):