Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit 2e4322123f61160470ef7c879470a364f5f968e7 1 parent 2fb6c3b
Adrian Holovaty authored July 14, 2005
2  django/core/extensions.py
@@ -25,7 +25,7 @@ class PermLookupDict:
25 25
     def __init__(self, user, module_name):
26 26
         self.user, self.module_name = user, module_name
27 27
     def __repr__(self):
28  
-        return str(self.user.get_permissions())
  28
+        return str(self.user.get_permission_list())
29 29
     def __getitem__(self, perm_name):
30 30
         return self.user.has_perm("%s.%s" % (self.module_name, perm_name))
31 31
     def __nonzero__(self):
8  django/core/meta.py
@@ -517,10 +517,10 @@ def __new__(cls, name, bases, attrs):
517 517
 
518 518
         for f in opts.many_to_many:
519 519
             # Add "get_thingie" methods for many-to-many related objects.
520  
-            # EXAMPLES: Poll.get_sites(), Story.get_bylines()
  520
+            # EXAMPLES: Poll.get_site_list(), Story.get_byline_list()
521 521
             func = curry(method_get_many_to_many, f)
522 522
             func.__doc__ = "Returns a list of associated `%s.%s` objects." % (f.rel.to.app_label, f.rel.to.module_name)
523  
-            attrs['get_%s' % f.name] = func
  523
+            attrs['get_%s_list' % f.rel.name] = func
524 524
             # Add "set_thingie" methods for many-to-many related objects.
525 525
             # EXAMPLES: Poll.set_sites(), Story.set_bylines()
526 526
             func = curry(method_set_many_to_many, f)
@@ -809,7 +809,7 @@ def method_get_many_to_one(field_with_rel, self):
809 809
     return getattr(self, cache_var)
810 810
 
811 811
 # Handles getting many-to-many related objects.
812  
-# Example: Poll.get_sites()
  812
+# Example: Poll.get_site_list()
813 813
 def method_get_many_to_many(field_with_rel, self):
814 814
     rel = field_with_rel.rel.to
815 815
     cache_var = '_%s_cache' % field_with_rel.name
@@ -2064,7 +2064,7 @@ class ManyToManyField(Field):
2064 2064
     def __init__(self, to, **kwargs):
2065 2065
         kwargs['name'] = kwargs.get('name', to._meta.module_name)
2066 2066
         kwargs['verbose_name'] = kwargs.get('verbose_name', to._meta.verbose_name_plural)
2067  
-        kwargs['rel'] = ManyToMany(to, to._meta.object_name.lower() + '_id',
  2067
+        kwargs['rel'] = ManyToMany(to, to._meta.object_name.lower(),
2068 2068
             num_in_admin=kwargs.pop('num_in_admin', 0),
2069 2069
             related_name=kwargs.pop('related_name', None),
2070 2070
             filter_interface=kwargs.pop('filter_interface', None),
2  django/models/auth.py
@@ -101,7 +101,7 @@ def get_group_permissions(self):
101 101
     def get_all_permissions(self):
102 102
         if not hasattr(self, '_perm_cache'):
103 103
             import sets
104  
-            self._perm_cache = sets.Set(["%s.%s" % (p.package, p.codename) for p in self.get_user_permissions()])
  104
+            self._perm_cache = sets.Set(["%s.%s" % (p.package, p.codename) for p in self.get_permission_list()])
105 105
             self._perm_cache.update(self.get_group_permissions())
106 106
         return self._perm_cache
107 107
 
2  django/models/comments.py
@@ -152,7 +152,7 @@ def _module_user_is_moderator(user):
152 152
         from django.conf.settings import COMMENTS_MODERATORS_GROUP
153 153
         if user.is_superuser:
154 154
             return True
155  
-        for g in user.get_groups():
  155
+        for g in user.get_group_list():
156 156
             if g.id == COMMENTS_MODERATORS_GROUP:
157 157
                 return True
158 158
         return False
6  django/parts/auth/anonymoususers.py
@@ -3,7 +3,7 @@
3 3
 """
4 4
 
5 5
 class AnonymousUser:
6  
-    
  6
+
7 7
     def __init__(self):
8 8
         pass
9 9
 
@@ -22,13 +22,13 @@ def set_password(self, raw_password):
22 22
     def check_password(self, raw_password):
23 23
         raise NotImplementedError
24 24
 
25  
-    def get_groups(self):
  25
+    def get_group_list(self):
26 26
         return []
27 27
 
28 28
     def set_groups(self, group_id_list):
29 29
         raise NotImplementedError
30 30
 
31  
-    def get_permissions(self):
  31
+    def get_permission_list(self):
32 32
         return []
33 33
 
34 34
     def set_permissions(self, permission_id_list):
4  django/views/admin/main.py
@@ -897,7 +897,7 @@ def change_stage(request, app_label, module_name, object_id):
897 897
             new_data.update(_get_flattened_data(f, getattr(obj, f.name)))
898 898
         for f in opts.many_to_many:
899 899
             if not f.rel.edit_inline:
900  
-                new_data[f.name] = [i.id for i in getattr(obj, 'get_%s' % f.name)()]
  900
+                new_data[f.name] = [i.id for i in getattr(obj, 'get_%s_list' % f.rel.name)()]
901 901
         for rel_obj, rel_field in inline_related_objects:
902 902
             var_name = rel_obj.object_name.lower()
903 903
             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):
906 906
                         for k, v in _get_flattened_data(f, getattr(rel_instance, f.name)).items():
907 907
                             new_data['%s.%d.%s' % (var_name, i, k)] = v
908 908
                 for f in rel_obj.many_to_many:
909  
-                    new_data['%s.%d.%s' % (var_name, i, f.name)] = [j.id for j in getattr(rel_instance, 'get_%s' % f.name)()]
  909
+                    new_data['%s.%d.%s' % (var_name, i, f.name)] = [j.id for j in getattr(rel_instance, 'get_%s_list' % f.rel.name)()]
910 910
 
911 911
         # If the object has ordered objects on its admin page, get the existing
912 912
         # order and flatten it into a comma-separated list of IDs.
2  django/views/comments/comments.py
@@ -108,7 +108,7 @@ def save(self, new_data):
108 108
             message = 'This comment was posted by a user who has posted fewer than %s comments:\n\n%s' % \
109 109
                 (COMMENTS_FIRST_FEW, c.get_as_text())
110 110
             mail_managers("Comment posted by rookie user", message)
111  
-        if COMMENTS_SKETCHY_USERS_GROUP and COMMENTS_SKETCHY_USERS_GROUP in [g.id for g in self.user_cache.get_groups()]:
  111
+        if COMMENTS_SKETCHY_USERS_GROUP and COMMENTS_SKETCHY_USERS_GROUP in [g.id for g in self.user_cache.get_group_list()]:
112 112
             message = 'This comment was posted by a sketchy user:\n\n%s' % c.get_as_text()
113 113
             mail_managers("Comment posted by sketchy user (%s)" % self.user_cache.username, c.get_as_text())
114 114
         return c
4  django/views/defaults.py
@@ -14,8 +14,8 @@ def shortcut(request, content_type_id, object_id):
14 14
     if not hasattr(obj, 'get_absolute_url'):
15 15
         raise Http404, "%s objects don't have get_absolute_url() methods" % content_type.name
16 16
     object_domain = None
17  
-    if hasattr(obj, 'get_sites'):
18  
-        site_list = obj.get_sites()
  17
+    if hasattr(obj, 'get_site_list'):
  18
+        site_list = obj.get_site_list()
19 19
         if site_list:
20 20
             object_domain = site_list[0].domain
21 21
     elif hasattr(obj, 'get_site'):

0 notes on commit 2e43221

Please sign in to comment.
Something went wrong with that request. Please try again.