Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
2be621e4
Kaydet (Commit)
2be621e4
authored
Nis 05, 2014
tarafından
Riccardo Magliocchetti
Kaydeden (comit)
Tim Graham
Şub 04, 2015
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #14497 -- Improved admin widget for "read only" FileFields
Based on patch by Adam J Forster, Paul Collins, and Julien.
üst
5bc5ddd8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
15 deletions
+53
-15
utils.py
django/contrib/admin/utils.py
+11
-7
tests.py
tests/admin_widgets/tests.py
+36
-7
widgetadmin.py
tests/admin_widgets/widgetadmin.py
+6
-1
No files found.
django/contrib/admin/utils.py
Dosyayı görüntüle @
2be621e4
from
__future__
import
unicode_literals
from
collections
import
defaultdict
import
datetime
import
decimal
from
collections
import
defaultdict
from
django.contrib.auth
import
get_permission_codename
from
django.core.exceptions
import
FieldDoesNotExist
from
django.core.urlresolvers
import
reverse
,
NoReverseMatch
from
django.db
import
models
from
django.db.models.constants
import
LOOKUP_SEP
from
django.db.models.deletion
import
Collector
from
django.forms.forms
import
pretty_name
from
django.utils
import
formats
from
django.utils.html
import
format_html
from
django.utils.text
import
capfirst
from
django.utils
import
timezone
from
django.utils
import
formats
,
six
,
timezone
from
django.utils.encoding
import
force_str
,
force_text
,
smart_text
from
django.utils
import
six
from
django.utils.html
import
conditional_escape
,
format_html
from
django.utils.safestring
import
mark_safe
from
django.utils.text
import
capfirst
from
django.utils.translation
import
ungettext
from
django.core.urlresolvers
import
reverse
,
NoReverseMatch
def
lookup_needs_distinct
(
opts
,
lookup_path
):
...
...
@@ -389,6 +388,11 @@ def display_for_field(value, field):
return
formats
.
number_format
(
value
,
field
.
decimal_places
)
elif
isinstance
(
field
,
models
.
FloatField
):
return
formats
.
number_format
(
value
)
elif
isinstance
(
field
,
models
.
FileField
):
return
mark_safe
(
'<a href="
%
s">
%
s</a>'
%
(
conditional_escape
(
value
.
url
),
conditional_escape
(
value
),
))
else
:
return
smart_text
(
value
)
...
...
tests/admin_widgets/tests.py
Dosyayı görüntüle @
2be621e4
...
...
@@ -350,26 +350,55 @@ class AdminURLWidgetTest(DjangoTestCase):
)
class
AdminFileWidgetTest
(
DjangoTestCase
):
def
test_render
(
self
):
@override_settings
(
PASSWORD_HASHERS
=
[
'django.contrib.auth.hashers.SHA1PasswordHasher'
],
ROOT_URLCONF
=
'admin_widgets.urls'
,
)
class
AdminFileWidgetTests
(
DjangoTestCase
):
fixtures
=
[
'admin-widgets-users.xml'
]
def
setUp
(
self
):
band
=
models
.
Band
.
objects
.
create
(
name
=
'Linkin Park'
)
album
=
band
.
album_set
.
create
(
self
.
album
=
band
.
album_set
.
create
(
name
=
'Hybrid Theory'
,
cover_art
=
r'albums\hybrid_theory.jpg'
)
def
test_render
(
self
):
w
=
widgets
.
AdminFileWidget
()
self
.
assertHTMLEqual
(
w
.
render
(
'test'
,
album
.
cover_art
),
'<p class="file-upload">Currently: <a href="
%(STORAGE_URL)
salbums/hybrid_theory.jpg">albums
\
hybrid_theory.jpg</a> <span class="clearable-file-input"><input type="checkbox" name="test-clear" id="test-clear_id" /> <label for="test-clear_id">Clear</label></span><br />Change: <input type="file" name="test" /></p>'
%
{
'STORAGE_URL'
:
default_storage
.
url
(
''
)
w
.
render
(
'test'
,
self
.
album
.
cover_art
),
'<p class="file-upload">Currently: <a href="
%(STORAGE_URL)
salbums/'
'hybrid_theory.jpg">albums
\
hybrid_theory.jpg</a> '
'<span class="clearable-file-input">'
'<input type="checkbox" name="test-clear" id="test-clear_id" /> '
'<label for="test-clear_id">Clear</label></span><br />'
'Change: <input type="file" name="test" /></p>'
%
{
'STORAGE_URL'
:
default_storage
.
url
(
''
),
},
)
self
.
assertHTMLEqual
(
w
.
render
(
'test'
,
SimpleUploadedFile
(
'test'
,
b
'content'
)),
'<input type="file" name="test" />'
,
)
def
test_readonly_fields
(
self
):
"""
File widgets should render as a link when they're marked "read only."
"""
self
.
client
.
login
(
username
=
"super"
,
password
=
"secret"
)
response
=
self
.
client
.
get
(
'/admin_widgets/album/
%
s/'
%
self
.
album
.
id
)
self
.
assertContains
(
response
,
'<p><a href="
%(STORAGE_URL)
salbums/hybrid_theory.jpg">'
'albums
\
hybrid_theory.jpg</a></p>'
%
{
'STORAGE_URL'
:
default_storage
.
url
(
''
)},
html
=
True
,
)
self
.
assertNotContains
(
response
,
'<input type="file" name="cover_art" id="id_cover_art" />'
,
html
=
True
,
)
@override_settings
(
ROOT_URLCONF
=
'admin_widgets.urls'
)
class
ForeignKeyRawIdWidgetTest
(
DjangoTestCase
):
...
...
tests/admin_widgets/widgetadmin.py
Dosyayı görüntüle @
2be621e4
...
...
@@ -24,6 +24,11 @@ class EventAdmin(admin.ModelAdmin):
raw_id_fields
=
[
'main_band'
,
'supporting_bands'
]
class
AlbumAdmin
(
admin
.
ModelAdmin
):
fields
=
(
'name'
,
'cover_art'
,)
readonly_fields
=
(
'cover_art'
,)
class
SchoolAdmin
(
admin
.
ModelAdmin
):
filter_vertical
=
(
'students'
,)
filter_horizontal
=
(
'alumni'
,)
...
...
@@ -37,7 +42,7 @@ site.register(models.CarTire, CarTireAdmin)
site
.
register
(
models
.
Member
)
site
.
register
(
models
.
Band
)
site
.
register
(
models
.
Event
,
EventAdmin
)
site
.
register
(
models
.
Album
)
site
.
register
(
models
.
Album
,
AlbumAdmin
)
site
.
register
(
models
.
Inventory
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment