Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix admin images with Django 1.9 and multi usage of file picker widget #670

Merged
merged 7 commits into from Feb 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions filer/admin/clipboardadmin.py
Expand Up @@ -8,7 +8,7 @@

from filer import settings as filer_settings
from filer.models import Folder, Clipboard, ClipboardItem, Image
from filer.utils.compatibility import DJANGO_1_4
from filer.utils.compatibility import LTE_DJANGO_1_4
from filer.utils.files import (
handle_upload, handle_request_files_upload, UploadException,
)
Expand Down Expand Up @@ -77,7 +77,7 @@ def ajax_upload(request, folder_id=None):
Receives an upload from the uploader. Receives only one file at a time.
"""
mimetype = "application/json" if request.is_ajax() else "text/html"
content_type_key = 'mimetype' if DJANGO_1_4 else 'content_type'
content_type_key = 'mimetype' if LTE_DJANGO_1_4 else 'content_type'
response_params = {content_type_key: mimetype}
folder = None
if folder_id:
Expand Down
4 changes: 2 additions & 2 deletions filer/admin/fileadmin.py
Expand Up @@ -8,7 +8,7 @@
from filer import settings
from filer.admin.permissions import PrimitivePermissionAwareModelAdmin
from filer.models import File, Image
from filer.utils.compatibility import DJANGO_1_5, unquote
from filer.utils.compatibility import LTE_DJANGO_1_5, unquote
from filer.views import (popup_param, selectfolder_param, popup_status,
selectfolder_status)

Expand All @@ -35,7 +35,7 @@ class FileAdmin(PrimitivePermissionAwareModelAdmin):
form = FileAdminChangeFrom

def get_queryset(self, request):
if DJANGO_1_5:
if LTE_DJANGO_1_5:
return super(FileAdmin, self).queryset(request)
return super(FileAdmin, self).get_queryset(request)

Expand Down
4 changes: 2 additions & 2 deletions filer/admin/permissions.py
Expand Up @@ -3,7 +3,7 @@
from django.contrib import admin
from django.core.urlresolvers import reverse

from filer.utils.compatibility import DJANGO_1_7
from filer.utils.compatibility import LTE_DJANGO_1_7


class PrimitivePermissionAwareModelAdmin(admin.ModelAdmin):
Expand Down Expand Up @@ -33,7 +33,7 @@ def _get_post_url(self, obj):
"""
# Code from django ModelAdmin to determine changelist on the fly
opts = obj._meta
if DJANGO_1_7:
if LTE_DJANGO_1_7:
model_name = opts.module_name
else:
model_name = opts.model_name
Expand Down
6 changes: 3 additions & 3 deletions filer/admin/tools.py
Expand Up @@ -2,13 +2,13 @@

from django.core.exceptions import PermissionDenied

from filer.utils.compatibility import DJANGO_1_7, DJANGO_1_6
from filer.utils.compatibility import LTE_DJANGO_1_7, LTE_DJANGO_1_6


if DJANGO_1_6:
if LTE_DJANGO_1_6:
def admin_each_context(admin_site, request):
return {}
elif DJANGO_1_7:
elif LTE_DJANGO_1_7:
def admin_each_context(admin_site, request):
return admin_site.each_context()
else:
Expand Down
12 changes: 6 additions & 6 deletions filer/fields/file.py
Expand Up @@ -11,7 +11,7 @@
from django.template.loader import render_to_string
from django.utils.safestring import mark_safe

from filer.utils.compatibility import truncate_words
from filer.utils.compatibility import truncate_words, LTE_DJANGO_1_8, LTE_DJANGO_1_7
from filer.utils.model_label import get_model_label
from filer.models import File
from filer import settings as filer_settings
Expand All @@ -26,8 +26,6 @@ class AdminFileWidget(ForeignKeyRawIdWidget):
def render(self, name, value, attrs=None):
obj = self.obj_for_value(value)
css_id = attrs.get('id', 'id_image_x')
css_id_thumbnail_img = "%s_thumbnail_img" % css_id
css_id_description_txt = "%s_description_txt" % css_id
related_url = None
if value:
try:
Expand Down Expand Up @@ -58,12 +56,14 @@ def render(self, name, value, attrs=None):
context = {
'hidden_input': hidden_input,
'lookup_url': '%s%s' % (related_url, lookup_url),
'thumb_id': css_id_thumbnail_img,
'span_id': css_id_description_txt,
'object': obj,
'lookup_name': name,
'clear_id': '%s_clear' % css_id,
'id': css_id,
'admin_icon_delete': (
'admin/img/icon_deletelink.gif' if LTE_DJANGO_1_8
else 'admin/img/icon-deletelink.svg'
),
'LTE_DJANGO_1_7': LTE_DJANGO_1_7,
}
html = render_to_string('admin/filer/widgets/admin_file.html', context)
return mark_safe(html)
Expand Down
4 changes: 2 additions & 2 deletions filer/models/filemodels.py
Expand Up @@ -22,7 +22,7 @@
from filer.fields.multistorage_file import MultiStorageFileField
from filer.models import mixins
from filer.models.foldermodels import Folder
from filer.utils.compatibility import python_2_unicode_compatible, DJANGO_1_7
from filer.utils.compatibility import python_2_unicode_compatible, LTE_DJANGO_1_7


class FileManager(PolymorphicManager):
Expand Down Expand Up @@ -225,7 +225,7 @@ def __str__(self):
return text

def get_admin_url_path(self):
if DJANGO_1_7:
if LTE_DJANGO_1_7:
model_name = self._meta.module_name
else:
model_name = self._meta.model_name
Expand Down
4 changes: 2 additions & 2 deletions filer/server/backends/default.py
Expand Up @@ -4,7 +4,7 @@
from django.http import Http404, HttpResponse, HttpResponseNotModified
from django.utils.http import http_date
from django.views.static import was_modified_since
from filer.utils.compatibility import DJANGO_1_4
from filer.utils.compatibility import LTE_DJANGO_1_4
from filer.server.backends.base import ServerBase


Expand All @@ -24,7 +24,7 @@ def serve(self, request, file_obj, **kwargs):
# Respect the If-Modified-Since header.
statobj = os.stat(fullpath)

content_type_key = 'mimetype' if DJANGO_1_4 else 'content_type'
content_type_key = 'mimetype' if LTE_DJANGO_1_4 else 'content_type'
response_params = {content_type_key: self.get_mimetype(fullpath)}
if not was_modified_since(request.META.get('HTTP_IF_MODIFIED_SINCE'),
statobj[stat.ST_MTIME], statobj[stat.ST_SIZE]):
Expand Down