diff options
author | Joar Wandborg <git@wandborg.com> | 2011-07-03 05:46:00 +0200 |
---|---|---|
committer | Joar Wandborg <git@wandborg.com> | 2011-07-03 05:46:00 +0200 |
commit | 2c9e635ae2ecbef0649df78636503be357f16a7f (patch) | |
tree | b3f3c80c29c434c89b0d43f02e708a3610d7e5c7 /mediagoblin/db/models.py | |
parent | 93214d8e0287150aef3f4370237303bc73ec448c (diff) | |
download | mediagoblin-2c9e635ae2ecbef0649df78636503be357f16a7f.tar.lz mediagoblin-2c9e635ae2ecbef0649df78636503be357f16a7f.tar.xz mediagoblin-2c9e635ae2ecbef0649df78636503be357f16a7f.zip |
Feature #400 - Resize images to fit on page - Additions
* `migrations.py`
* Removed empty line
* Added empty line
* `models.py`
* Added `MediaEntry.get_display_media()` helper function
* `process_media.__init__.py`
* Updated `process_media_initial()`
* Renamed `main` => `original`.
* Added condition to `medium`, it's only created if the original
dimensions exceed the MEDIUM_SIZE dimensions.
* `media.html`
* The image tag is now populated by `MediaEntry.get_display_media()`
* `util.py`
* Added `DISPLAY_IMAGE_FETCHING_ORDER`, used by `MediaEntry.get_display_media()`
Diffstat (limited to 'mediagoblin/db/models.py')
-rw-r--r-- | mediagoblin/db/models.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py index bf825a23..3190d8fa 100644 --- a/mediagoblin/db/models.py +++ b/mediagoblin/db/models.py @@ -24,6 +24,7 @@ from mediagoblin import mg_globals from mediagoblin.db import migrations from mediagoblin.db.util import DESCENDING, ObjectId from mediagoblin.util import Pagination +from mediagoblin.util import DISPLAY_IMAGE_FETCHING_ORDER ################### # Custom validators @@ -109,6 +110,24 @@ class MediaEntry(Document): migration_handler = migrations.MediaEntryMigration + def get_display_media(self, media_map, fetch_order=DISPLAY_IMAGE_FETCHING_ORDER): + """ + Find the best media for display. + + Args: + - media_map: a dict like + {u'image_size': [u'dir1', u'dir2', u'image.jpg']} + - fetch_order: the order we should try fetching images in + + Returns: + (media_size, media_path) + """ + media_sizes = media_map.keys() + print media_sizes + for media_size in DISPLAY_IMAGE_FETCHING_ORDER: + if media_size in media_sizes: + return media_map[media_size] + def main_mediafile(self): pass |