mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
Replaced property() usage with decorator in several places.
This commit is contained in:
parent
ebdfd656b4
commit
a02b5848ae
@ -56,12 +56,12 @@ class AdminForm(object):
|
|||||||
**options
|
**options
|
||||||
)
|
)
|
||||||
|
|
||||||
def _media(self):
|
@property
|
||||||
|
def media(self):
|
||||||
media = self.form.media
|
media = self.form.media
|
||||||
for fs in self:
|
for fs in self:
|
||||||
media = media + fs.media
|
media = media + fs.media
|
||||||
return media
|
return media
|
||||||
media = property(_media)
|
|
||||||
|
|
||||||
|
|
||||||
class Fieldset(object):
|
class Fieldset(object):
|
||||||
@ -74,7 +74,8 @@ class Fieldset(object):
|
|||||||
self.model_admin = model_admin
|
self.model_admin = model_admin
|
||||||
self.readonly_fields = readonly_fields
|
self.readonly_fields = readonly_fields
|
||||||
|
|
||||||
def _media(self):
|
@property
|
||||||
|
def media(self):
|
||||||
if 'collapse' in self.classes:
|
if 'collapse' in self.classes:
|
||||||
extra = '' if settings.DEBUG else '.min'
|
extra = '' if settings.DEBUG else '.min'
|
||||||
js = [
|
js = [
|
||||||
@ -84,7 +85,6 @@ class Fieldset(object):
|
|||||||
]
|
]
|
||||||
return forms.Media(js=['admin/js/%s' % url for url in js])
|
return forms.Media(js=['admin/js/%s' % url for url in js])
|
||||||
return forms.Media()
|
return forms.Media()
|
||||||
media = property(_media)
|
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for field in self.fields:
|
for field in self.fields:
|
||||||
@ -303,12 +303,12 @@ class InlineAdminFormSet(object):
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
def _media(self):
|
@property
|
||||||
|
def media(self):
|
||||||
media = self.opts.media + self.formset.media
|
media = self.opts.media + self.formset.media
|
||||||
for fs in self:
|
for fs in self:
|
||||||
media = media + fs.media
|
media = media + fs.media
|
||||||
return media
|
return media
|
||||||
media = property(_media)
|
|
||||||
|
|
||||||
|
|
||||||
class InlineAdminForm(AdminForm):
|
class InlineAdminForm(AdminForm):
|
||||||
|
@ -412,10 +412,10 @@ class AdminPasswordChangeForm(forms.Form):
|
|||||||
self.user.save()
|
self.user.save()
|
||||||
return self.user
|
return self.user
|
||||||
|
|
||||||
def _get_changed_data(self):
|
@property
|
||||||
|
def changed_data(self):
|
||||||
data = super(AdminPasswordChangeForm, self).changed_data
|
data = super(AdminPasswordChangeForm, self).changed_data
|
||||||
for name in self.fields.keys():
|
for name in self.fields.keys():
|
||||||
if name not in data:
|
if name not in data:
|
||||||
return []
|
return []
|
||||||
return ['password']
|
return ['password']
|
||||||
changed_data = property(_get_changed_data)
|
|
||||||
|
@ -412,13 +412,13 @@ class AnonymousUser(object):
|
|||||||
def check_password(self, raw_password):
|
def check_password(self, raw_password):
|
||||||
raise NotImplementedError("Django doesn't provide a DB representation for AnonymousUser.")
|
raise NotImplementedError("Django doesn't provide a DB representation for AnonymousUser.")
|
||||||
|
|
||||||
def _get_groups(self):
|
@property
|
||||||
|
def groups(self):
|
||||||
return self._groups
|
return self._groups
|
||||||
groups = property(_get_groups)
|
|
||||||
|
|
||||||
def _get_user_permissions(self):
|
@property
|
||||||
|
def user_permissions(self):
|
||||||
return self._user_permissions
|
return self._user_permissions
|
||||||
user_permissions = property(_get_user_permissions)
|
|
||||||
|
|
||||||
def get_group_permissions(self, obj=None):
|
def get_group_permissions(self, obj=None):
|
||||||
return set()
|
return set()
|
||||||
|
@ -38,7 +38,8 @@ class Message(object):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return force_text(self.message)
|
return force_text(self.message)
|
||||||
|
|
||||||
def _get_tags(self):
|
@property
|
||||||
|
def tags(self):
|
||||||
extra_tags = force_text(self.extra_tags, strings_only=True)
|
extra_tags = force_text(self.extra_tags, strings_only=True)
|
||||||
if extra_tags and self.level_tag:
|
if extra_tags and self.level_tag:
|
||||||
return ' '.join([extra_tags, self.level_tag])
|
return ' '.join([extra_tags, self.level_tag])
|
||||||
@ -47,7 +48,6 @@ class Message(object):
|
|||||||
elif self.level_tag:
|
elif self.level_tag:
|
||||||
return self.level_tag
|
return self.level_tag
|
||||||
return ''
|
return ''
|
||||||
tags = property(_get_tags)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def level_tag(self):
|
def level_tag(self):
|
||||||
|
@ -68,9 +68,9 @@ class Sitemap(object):
|
|||||||
def location(self, obj):
|
def location(self, obj):
|
||||||
return obj.get_absolute_url()
|
return obj.get_absolute_url()
|
||||||
|
|
||||||
def _get_paginator(self):
|
@property
|
||||||
|
def paginator(self):
|
||||||
return paginator.Paginator(self.items(), self.limit)
|
return paginator.Paginator(self.items(), self.limit)
|
||||||
paginator = property(_get_paginator)
|
|
||||||
|
|
||||||
def get_urls(self, page=1, site=None, protocol=None):
|
def get_urls(self, page=1, site=None, protocol=None):
|
||||||
# Determine protocol
|
# Determine protocol
|
||||||
|
@ -14,13 +14,13 @@ class ImageFile(File):
|
|||||||
A mixin for use alongside django.core.files.base.File, which provides
|
A mixin for use alongside django.core.files.base.File, which provides
|
||||||
additional features for dealing with images.
|
additional features for dealing with images.
|
||||||
"""
|
"""
|
||||||
def _get_width(self):
|
@property
|
||||||
|
def width(self):
|
||||||
return self._get_image_dimensions()[0]
|
return self._get_image_dimensions()[0]
|
||||||
width = property(_get_width)
|
|
||||||
|
|
||||||
def _get_height(self):
|
@property
|
||||||
|
def height(self):
|
||||||
return self._get_image_dimensions()[1]
|
return self._get_image_dimensions()[1]
|
||||||
height = property(_get_height)
|
|
||||||
|
|
||||||
def _get_image_dimensions(self):
|
def _get_image_dimensions(self):
|
||||||
if not hasattr(self, '_dimensions_cache'):
|
if not hasattr(self, '_dimensions_cache'):
|
||||||
|
@ -134,13 +134,13 @@ class WSGIRequest(http.HttpRequest):
|
|||||||
raw_cookie = get_str_from_wsgi(self.environ, 'HTTP_COOKIE', '')
|
raw_cookie = get_str_from_wsgi(self.environ, 'HTTP_COOKIE', '')
|
||||||
return http.parse_cookie(raw_cookie)
|
return http.parse_cookie(raw_cookie)
|
||||||
|
|
||||||
def _get_files(self):
|
@property
|
||||||
|
def FILES(self):
|
||||||
if not hasattr(self, '_files'):
|
if not hasattr(self, '_files'):
|
||||||
self._load_post_and_files()
|
self._load_post_and_files()
|
||||||
return self._files
|
return self._files
|
||||||
|
|
||||||
POST = property(_get_post, _set_post)
|
POST = property(_get_post, _set_post)
|
||||||
FILES = property(_get_files)
|
|
||||||
|
|
||||||
|
|
||||||
class WSGIHandler(base.BaseHandler):
|
class WSGIHandler(base.BaseHandler):
|
||||||
|
@ -60,22 +60,22 @@ class FieldFile(File):
|
|||||||
|
|
||||||
file = property(_get_file, _set_file, _del_file)
|
file = property(_get_file, _set_file, _del_file)
|
||||||
|
|
||||||
def _get_path(self):
|
@property
|
||||||
|
def path(self):
|
||||||
self._require_file()
|
self._require_file()
|
||||||
return self.storage.path(self.name)
|
return self.storage.path(self.name)
|
||||||
path = property(_get_path)
|
|
||||||
|
|
||||||
def _get_url(self):
|
@property
|
||||||
|
def url(self):
|
||||||
self._require_file()
|
self._require_file()
|
||||||
return self.storage.url(self.name)
|
return self.storage.url(self.name)
|
||||||
url = property(_get_url)
|
|
||||||
|
|
||||||
def _get_size(self):
|
@property
|
||||||
|
def size(self):
|
||||||
self._require_file()
|
self._require_file()
|
||||||
if not self._committed:
|
if not self._committed:
|
||||||
return self.file.size
|
return self.file.size
|
||||||
return self.storage.size(self.name)
|
return self.storage.size(self.name)
|
||||||
size = property(_get_size)
|
|
||||||
|
|
||||||
def open(self, mode='rb'):
|
def open(self, mode='rb'):
|
||||||
self._require_file()
|
self._require_file()
|
||||||
@ -120,10 +120,10 @@ class FieldFile(File):
|
|||||||
self.instance.save()
|
self.instance.save()
|
||||||
delete.alters_data = True
|
delete.alters_data = True
|
||||||
|
|
||||||
def _get_closed(self):
|
@property
|
||||||
|
def closed(self):
|
||||||
file = getattr(self, '_file', None)
|
file = getattr(self, '_file', None)
|
||||||
return file is None or file.closed
|
return file is None or file.closed
|
||||||
closed = property(_get_closed)
|
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
file = getattr(self, '_file', None)
|
file = getattr(self, '_file', None)
|
||||||
|
@ -438,7 +438,8 @@ class Client(RequestFactory):
|
|||||||
"""
|
"""
|
||||||
self.exc_info = sys.exc_info()
|
self.exc_info = sys.exc_info()
|
||||||
|
|
||||||
def _session(self):
|
@property
|
||||||
|
def session(self):
|
||||||
"""
|
"""
|
||||||
Obtains the current session variables.
|
Obtains the current session variables.
|
||||||
"""
|
"""
|
||||||
@ -451,7 +452,6 @@ class Client(RequestFactory):
|
|||||||
session.save()
|
session.save()
|
||||||
self.cookies[settings.SESSION_COOKIE_NAME] = session.session_key
|
self.cookies[settings.SESSION_COOKIE_NAME] = session.session_key
|
||||||
return session
|
return session
|
||||||
session = property(_session)
|
|
||||||
|
|
||||||
def request(self, **request):
|
def request(self, **request):
|
||||||
"""
|
"""
|
||||||
|
@ -751,10 +751,10 @@ For example, this model has a few custom methods::
|
|||||||
else:
|
else:
|
||||||
return "Post-boomer"
|
return "Post-boomer"
|
||||||
|
|
||||||
def _get_full_name(self):
|
@property
|
||||||
|
def full_name(self):
|
||||||
"Returns the person's full name."
|
"Returns the person's full name."
|
||||||
return '%s %s' % (self.first_name, self.last_name)
|
return '%s %s' % (self.first_name, self.last_name)
|
||||||
full_name = property(_get_full_name)
|
|
||||||
|
|
||||||
The last method in this example is a :term:`property`.
|
The last method in this example is a :term:`property`.
|
||||||
|
|
||||||
|
@ -188,10 +188,10 @@ For example, the static definition for our Calendar Widget could also
|
|||||||
be defined in a dynamic fashion::
|
be defined in a dynamic fashion::
|
||||||
|
|
||||||
class CalendarWidget(forms.TextInput):
|
class CalendarWidget(forms.TextInput):
|
||||||
def _media(self):
|
@property
|
||||||
|
def media(self):
|
||||||
return forms.Media(css={'all': ('pretty.css',)},
|
return forms.Media(css={'all': ('pretty.css',)},
|
||||||
js=('animations.js', 'actions.js'))
|
js=('animations.js', 'actions.js'))
|
||||||
media = property(_media)
|
|
||||||
|
|
||||||
See the section on `Media objects`_ for more details on how to construct
|
See the section on `Media objects`_ for more details on how to construct
|
||||||
return values for dynamic ``media`` properties.
|
return values for dynamic ``media`` properties.
|
||||||
|
Loading…
Reference in New Issue
Block a user