mirror of https://github.com/django/django.git
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
This commit is contained in:
parent
2fb6c3b845
commit
2e4322123f
|
@ -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):
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'):
|
||||
|
|
Loading…
Reference in New Issue