[extensions-web] extensions: Don't use server-side screenshot downscaling



commit 013ad3fb5170492e3fbf22a69ac7fc1dc1cc7cff
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Mon Aug 6 18:21:26 2012 -0300

    extensions: Don't use server-side screenshot downscaling
    
    This breaks for interlaced PNGs

 requirements.txt                                   |    1 -
 .../auth/templates/registration/profile.html       |    1 -
 sweettooth/extensions/admin.py                     |    1 -
 .../0019_auto__chg_field_extension_screenshot.py   |   99 ++++++++++++++++++++
 sweettooth/extensions/models.py                    |    3 +-
 .../extensions/templates/extensions/detail.html    |    5 +-
 .../templates/extensions/detail_edit.html          |    2 +-
 sweettooth/extensions/views.py                     |    3 +-
 sweettooth/review/templates/review/review.html     |    5 +-
 sweettooth/static/css/sweettooth.css               |    7 ++
 sweettooth/static/js/main.js                       |    2 +-
 sweettooth/static/js/uploader.js                   |    3 +-
 12 files changed, 113 insertions(+), 19 deletions(-)
---
diff --git a/requirements.txt b/requirements.txt
index 78e8cd3..03b3b75 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -3,6 +3,5 @@ PIL==1.1.7
 Pygments==1.4
 django-autoslug==1.4.1
 django-registration==0.7
-sorl-thumbnail==11.05.2
 wsgiref==0.1.2
 South==0.7.3
diff --git a/sweettooth/auth/templates/registration/profile.html b/sweettooth/auth/templates/registration/profile.html
index 53191b4..e57e6fa 100644
--- a/sweettooth/auth/templates/registration/profile.html
+++ b/sweettooth/auth/templates/registration/profile.html
@@ -2,7 +2,6 @@
 {% block title %}{{ display_name }}'s Profile - {{ block.super }}{% endblock %}
 
 {% block body %}
-{% load thumbnail %}
 {% load gravatar %}
 <div class="profile">
   {% if is_editable %}
diff --git a/sweettooth/extensions/admin.py b/sweettooth/extensions/admin.py
index e818463..96e9c0f 100644
--- a/sweettooth/extensions/admin.py
+++ b/sweettooth/extensions/admin.py
@@ -1,6 +1,5 @@
 
 from django.contrib import admin
-from sorl.thumbnail.admin import AdminImageMixin
 
 from extensions.models import Extension, ExtensionVersion
 from extensions.models import STATUS_ACTIVE, STATUS_REJECTED
diff --git a/sweettooth/extensions/migrations/0019_auto__chg_field_extension_screenshot.py b/sweettooth/extensions/migrations/0019_auto__chg_field_extension_screenshot.py
new file mode 100644
index 0000000..9addbba
--- /dev/null
+++ b/sweettooth/extensions/migrations/0019_auto__chg_field_extension_screenshot.py
@@ -0,0 +1,99 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        
+        # Changing field 'Extension.screenshot'
+        db.alter_column('extensions_extension', 'screenshot', self.gf('django.db.models.fields.files.ImageField')(max_length=100))
+
+
+    def backwards(self, orm):
+        
+        # Changing field 'Extension.screenshot'
+        db.alter_column('extensions_extension', 'screenshot', self.gf('sorl.thumbnail.fields.ImageField')(max_length=100))
+
+
+    models = {
+        'auth.group': {
+            'Meta': {'object_name': 'Group'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+        },
+        'auth.permission': {
+            'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+        },
+        'auth.user': {
+            'Meta': {'object_name': 'User'},
+            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+        },
+        'contenttypes.contenttype': {
+            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        },
+        'extensions.extension': {
+            'Meta': {'object_name': 'Extension'},
+            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'creator': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}),
+            'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+            'downloads': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}),
+            'icon': ('django.db.models.fields.files.ImageField', [], {'default': "'/static/images/plugin.png'", 'max_length': '100', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+            'popularity': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
+            'screenshot': ('django.db.models.fields.files.ImageField', [], {'max_length': '100', 'blank': 'True'}),
+            'slug': ('autoslug.fields.AutoSlugField', [], {'unique_with': '()', 'max_length': '50', 'populate_from': 'None', 'db_index': 'True'}),
+            'url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'blank': 'True'}),
+            'uuid': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '200', 'db_index': 'True'})
+        },
+        'extensions.extensionpopularityitem': {
+            'Meta': {'object_name': 'ExtensionPopularityItem'},
+            'date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'extension': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'popularity_items'", 'to': "orm['extensions.Extension']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'offset': ('django.db.models.fields.IntegerField', [], {})
+        },
+        'extensions.extensionversion': {
+            'Meta': {'unique_together': "(('extension', 'version'),)", 'object_name': 'ExtensionVersion'},
+            'extension': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'versions'", 'to': "orm['extensions.Extension']"}),
+            'extra_json_fields': ('django.db.models.fields.TextField', [], {}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'shell_versions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['extensions.ShellVersion']", 'symmetrical': 'False'}),
+            'source': ('django.db.models.fields.files.FileField', [], {'max_length': '223'}),
+            'status': ('django.db.models.fields.PositiveIntegerField', [], {}),
+            'version': ('django.db.models.fields.IntegerField', [], {'default': '0'})
+        },
+        'extensions.shellversion': {
+            'Meta': {'object_name': 'ShellVersion'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'major': ('django.db.models.fields.PositiveIntegerField', [], {}),
+            'minor': ('django.db.models.fields.PositiveIntegerField', [], {}),
+            'point': ('django.db.models.fields.IntegerField', [], {})
+        }
+    }
+
+    complete_apps = ['extensions']
diff --git a/sweettooth/extensions/models.py b/sweettooth/extensions/models.py
index 4e933d2..79aa355 100644
--- a/sweettooth/extensions/models.py
+++ b/sweettooth/extensions/models.py
@@ -13,7 +13,6 @@ from django.dispatch import Signal
 
 import autoslug
 import re
-from sorl import thumbnail
 
 (STATUS_UNREVIEWED,
  STATUS_REJECTED,
@@ -86,7 +85,7 @@ class Extension(models.Model):
     def make_screenshot_filename(self, filename=None):
         return "screenshots/screenshot_%d.png" % (self.pk,)
 
-    screenshot = thumbnail.ImageField(upload_to=make_screenshot_filename, blank=True)
+    screenshot = models.ImageField(upload_to=make_screenshot_filename, blank=True)
 
     def make_icon_filename(self, filename=None):
         return "icons/icon_%d.png" % (self.pk,)
diff --git a/sweettooth/extensions/templates/extensions/detail.html b/sweettooth/extensions/templates/extensions/detail.html
index 0def42a..4605fde 100644
--- a/sweettooth/extensions/templates/extensions/detail.html
+++ b/sweettooth/extensions/templates/extensions/detail.html
@@ -1,5 +1,4 @@
 {% extends "base.html" %}
-{% load thumbnail %}
 {% block title %}{{ extension.name }} - {{ block.super }}{% endblock %}
 
 {% block body %}
@@ -24,11 +23,9 @@
 
       <div class="extension-details">
         {% if extension.screenshot %}
-        {% thumbnail extension.screenshot "300x200" as th %}
         {% block screenshot %}
-        <a href="{{ extension.screenshot.url }}" class="screenshot"><img src="{{ th.url }}" /></a>
+        <a href="{{ extension.screenshot.url }}" class="screenshot"><img src="{{ extension.screenshot.url }}" /></a>
         {% endblock screenshot %}
-        {% endthumbnail %}
         {% else %}
         {% block no-screenshot %}
         {% endblock %}
diff --git a/sweettooth/extensions/templates/extensions/detail_edit.html b/sweettooth/extensions/templates/extensions/detail_edit.html
index bd6464e..0fef195 100644
--- a/sweettooth/extensions/templates/extensions/detail_edit.html
+++ b/sweettooth/extensions/templates/extensions/detail_edit.html
@@ -53,7 +53,7 @@
 
 {% block screenshot %}
 <div class="screenshot upload">
-  <img src="{{ th.url }}" />
+  <img src="{{ extension.screenshot.url }}" />
 </div>
 <input type="file" accept="image/*">
 {% endblock %}
diff --git a/sweettooth/extensions/views.py b/sweettooth/extensions/views.py
index df0a851..9b48125 100644
--- a/sweettooth/extensions/views.py
+++ b/sweettooth/extensions/views.py
@@ -12,7 +12,6 @@ from django.shortcuts import get_object_or_404, redirect
 from django.template.loader import render_to_string
 from django.utils import simplejson as json
 from django.views.decorators.http import require_POST
-from sorl.thumbnail.shortcuts import get_thumbnail
 
 from extensions import models, search
 from extensions.forms import UploadForm
@@ -291,7 +290,7 @@ def ajax_inline_edit_view(request, extension):
 def ajax_upload_screenshot_view(request, extension):
     extension.screenshot = request.FILES['file']
     extension.save(replace_metadata_json=False)
-    return get_thumbnail(extension.screenshot, request.GET['geometry']).url
+    return extension.screenshot.url
 
 @ajax_view
 @require_POST
diff --git a/sweettooth/review/templates/review/review.html b/sweettooth/review/templates/review/review.html
index 52dfaf5..222b4e8 100644
--- a/sweettooth/review/templates/review/review.html
+++ b/sweettooth/review/templates/review/review.html
@@ -1,5 +1,4 @@
 {% extends "base.html" %}
-{% load thumbnail %}
 
 {% block title %}Review "{{ extension.name }}" - {{ block.super }}{% endblock %}
 
@@ -17,9 +16,7 @@
 
     <div>
       {% if extension.screenshot %}
-      {% thumbnail extension.screenshot "300x200" as th %}
-      <a href="{{ extension.screenshot.url }}" class="screenshot"><img src="{{ th.url }}" /></a>
-      {% endthumbnail %}
+      <a href="{{ extension.screenshot.url }}" class="screenshot"><img src="{{ extension.screenshot.url }}"></a>
       {% endif %}
 
       <p class="description">{{ extension.description }}</p>
diff --git a/sweettooth/static/css/sweettooth.css b/sweettooth/static/css/sweettooth.css
index b6dd569..572e63f 100644
--- a/sweettooth/static/css/sweettooth.css
+++ b/sweettooth/static/css/sweettooth.css
@@ -367,6 +367,13 @@ li.extension:last-child {
     float: left;
 }
 
+.extension .screenshot img {
+    max-width: 300px;
+    max-height: 200px;
+    -ms-interpolation-mode: bicubic;
+    image-rendering: optimizeQuality;
+}
+
 .extension .icon, .extension .icon img {
     width: 32px;
     height: 32px;
diff --git a/sweettooth/static/js/main.js b/sweettooth/static/js/main.js
index 07deea6..6e021e7 100644
--- a/sweettooth/static/js/main.js
+++ b/sweettooth/static/js/main.js
@@ -165,7 +165,7 @@ function($, messages, modal, hashParamUtils) {
             $('#extension_name, #extension_url').csrfEditable(inlineEditURL);
             $('#extension_description').csrfEditable(inlineEditURL, {type: 'textarea'});
 
-            $('.screenshot.upload').uploadify('/ajax/upload/screenshot/'+pk+'?geometry=300x200');
+            $('.screenshot.upload').uploadify('/ajax/upload/screenshot/'+pk);
             $('.icon.upload').uploadify('/ajax/upload/icon/'+pk);
         }
     });
diff --git a/sweettooth/static/js/uploader.js b/sweettooth/static/js/uploader.js
index 95de3c5..9358f0a 100644
--- a/sweettooth/static/js/uploader.js
+++ b/sweettooth/static/js/uploader.js
@@ -20,8 +20,7 @@ define(['jquery'], function($) {
 
         function uploadComplete(result) {
             var $old = $elem.children().first();
-            var $img = $('<img>', { 'src': result });
-            $img.replaceAll($old);
+            $old.attr('src', result);
             $elem.removeClass('placeholder');
         }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]