Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Factoring out admin thumbnail size
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Turner committed Sep 1, 2016
1 parent 20186f1 commit e54c356
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
9 changes: 7 additions & 2 deletions icekit/project/settings/_base.py
Expand Up @@ -398,14 +398,19 @@
# Scoped aliases allows us to pre-generate all the necessary thumbnails for a
# given model/field, without generating additional unecessary thumbnails. This
# is essential when using a remote storage backend.
# THUMBNAIL_ALIASES = {
THUMBNAIL_ALIASES = {
# 'app[.model][.field]': {
# 'name-WxH': {
# 'size': (W, H),
# ...,
# },
# },
# }
'': {
'admin': {
'size': (150, 150),
}
}
}

THUMBNAIL_BASEDIR = 'thumbs'
THUMBNAIL_HIGH_RESOLUTION = True
Expand Down
19 changes: 10 additions & 9 deletions icekit/utils/admin/mixins.py
@@ -1,5 +1,6 @@
import logging

from django.conf import settings
from django.contrib.admin.views.main import TO_FIELD_VAR
from django.contrib.admin.widgets import (ForeignKeyRawIdWidget,
ManyToManyRawIdWidget,)
Expand Down Expand Up @@ -31,9 +32,9 @@ class ThumbnailAdminMixin(object):
"""

thumbnail_field = None
thumbnail_options = {
'size': (100, 100),
}
thumbnail_options = settings.THUMBNAIL_ALIASES[''].get(
'admin', {'size': (100, 100),}
)
thumbnail_show_exceptions = False

def get_thumbnail_source(self, obj):
Expand Down Expand Up @@ -117,16 +118,16 @@ class PolymorphicAdminRawIdFix(object):
Use this mixin in any ModelAdmin that has a foreign key to a polymorphic
model that you would like to be a raw id field.
"""

def _get_child_admin_site(self, rel):
"""
Returns the separate AdminSite instance that django-polymorphic
maintains for child models.
This admin site needs to be passed to the widget so that it passes the
check of whether the field is pointing to a model that's registered
in the admin.
The hackiness of this implementation reflects the hackiness of the way
django-polymorphic does things.
"""
Expand All @@ -139,7 +140,7 @@ def _get_child_admin_site(self, rel):
and hasattr(self.admin_site._registry[parent], '_child_admin_site'):
return self.admin_site._registry[parent]._child_admin_site
return self.admin_site

def formfield_for_foreignkey(self, db_field, request=None, **kwargs):
"""
Replicates the logic in ModelAdmin.forfield_for_foreignkey, replacing
Expand Down Expand Up @@ -189,12 +190,12 @@ class PolymorphicFluentAdminRawIdFix(PolymorphicAdminRawIdFix):
Use this mixin in any ModelAdmin for a Fluent content page to make sure
that any Fluent inlines in the admin for the page inherit from the mixin
above.
Using this as the FLUENT_PAGES_[PARENT/CHILD]_ADMIN_MIXIN setting does not
appear to work (possibly because of explicit model_admin declarations in
PagePlugins defining page types).
"""

def get_extra_inlines(self):
# Replicates the equivalent method on PlaceholderEditorAdmin, except
# adds the `base` kwarg to the inline generator, so that all inlines
Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
@@ -1 +1 @@
site_name: 'icekit'
site_name: 'ICEkit'

0 comments on commit e54c356

Please sign in to comment.