From aff49a5dc4b63443e780c8a4afeecd05bbfbc6ba Mon Sep 17 00:00:00 2001
From: Fergal Moran
Date: Thu, 26 Sep 2013 21:07:47 +0100
Subject: [PATCH] Fixed image resizing
---
spa/models/userprofile.py | 14 ++++++++-----
static/css/deepsouthsounds.css | 2 +-
static/js/app/views/mix/mixEditView.coffee | 2 +-
static/js/app/views/mix/mixEditView.js | 17 +++++++---------
static/js/app/views/user/userEditView.coffee | 6 ------
static/js/app/views/user/userEditView.js | 21 ++++----------------
templates/views/UserEditView.html | 7 -------
7 files changed, 22 insertions(+), 47 deletions(-)
diff --git a/spa/models/userprofile.py b/spa/models/userprofile.py
index 38f1d4e..95c834b 100755
--- a/spa/models/userprofile.py
+++ b/spa/models/userprofile.py
@@ -15,7 +15,7 @@ from dss import settings
from spa.models._basemodel import _BaseModel
from templated_email import send_templated_mail
from sorl import thumbnail
-
+from sorl.thumbnail.helpers import ThumbnailError
logger = logging.getLogger(__name__)
@@ -160,14 +160,18 @@ class UserProfile(_BaseModel):
def get_small_profile_image(self):
try:
- image = self.get_avatar_image()
if self.avatar_type == 'custom':
+ image = self.avatar_image
image = "%s%s" % (settings.MEDIA_URL, get_thumbnail(image, "32x32", crop='center').name)
- return image
+ return image
except SuspiciousOperation, ex:
- self.logger.warn("Error getting small profile image: %s", ex.message)
+ self.logger.error("Error getting small profile image: %s", ex.message)
except IOError, ex:
- self.logger.warn("Error getting small profile image: %s", ex.message)
+ self.logger.error("Error getting small profile image: %s", ex.message)
+ except ThumbnailError:
+ pass
+
+ return self.get_avatar_image()
def get_sized_avatar_image(self, width, height):
try:
diff --git a/static/css/deepsouthsounds.css b/static/css/deepsouthsounds.css
index b4599a6..e42b751 100755
--- a/static/css/deepsouthsounds.css
+++ b/static/css/deepsouthsounds.css
@@ -406,7 +406,7 @@ div.event-content td {
.mix-image-container img {
max-width: 100%;
- max-height: 100%;
+ height: autoE;
}
.btn.loading {
diff --git a/static/js/app/views/mix/mixEditView.coffee b/static/js/app/views/mix/mixEditView.coffee
index 65ef9be..f1bc34e 100755
--- a/static/js/app/views/mix/mixEditView.coffee
+++ b/static/js/app/views/mix/mixEditView.coffee
@@ -1,6 +1,6 @@
define ['app.lib/editableView', 'moment', 'utils', 'backbone.syphon', 'text!/tpl/MixEditView'
'jquery.fileupload', 'jquery.fileupload-process', 'jquery.fileupload-audio', 'jquery.fileupload-ui',
- 'jquery.iframe-transport', 'jquery.ui.widget',
+ 'jquery.iframe-transport', 'jquery.ui.widget', 'lib/bootstrap-fileupload',
'lib/select2', 'lib/ajaxfileupload', 'ace', 'lib/bootstrap-tag.min'],
(EditableView, moment, utils, Syphon, Template) ->
class MixEditView extends EditableView
diff --git a/static/js/app/views/mix/mixEditView.js b/static/js/app/views/mix/mixEditView.js
index ffc415c..2b04aa5 100755
--- a/static/js/app/views/mix/mixEditView.js
+++ b/static/js/app/views/mix/mixEditView.js
@@ -1,18 +1,18 @@
-// Generated by CoffeeScript 1.6.2
+// Generated by CoffeeScript 1.3.3
(function() {
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
- define(['app.lib/editableView', 'moment', 'utils', 'backbone.syphon', 'text!/tpl/MixEditView', 'jquery.fileupload', 'jquery.fileupload-process', 'jquery.fileupload-audio', 'jquery.fileupload-ui', 'jquery.iframe-transport', 'jquery.ui.widget', 'lib/select2', 'lib/ajaxfileupload', 'ace', 'lib/bootstrap-tag.min'], function(EditableView, moment, utils, Syphon, Template) {
- var MixEditView, _ref;
-
+ define(['app.lib/editableView', 'moment', 'utils', 'backbone.syphon', 'text!/tpl/MixEditView', 'jquery.fileupload', 'jquery.fileupload-process', 'jquery.fileupload-audio', 'jquery.fileupload-ui', 'jquery.iframe-transport', 'jquery.ui.widget', 'lib/bootstrap-fileupload', 'lib/select2', 'lib/ajaxfileupload', 'ace', 'lib/bootstrap-tag.min'], function(EditableView, moment, utils, Syphon, Template) {
+ var MixEditView;
return MixEditView = (function(_super) {
+
__extends(MixEditView, _super);
function MixEditView() {
- this.saveChanges = __bind(this.saveChanges, this); _ref = MixEditView.__super__.constructor.apply(this, arguments);
- return _ref;
+ this.saveChanges = __bind(this.saveChanges, this);
+ return MixEditView.__super__.constructor.apply(this, arguments);
}
MixEditView.prototype.template = _.template(Template);
@@ -45,7 +45,6 @@
MixEditView.prototype.onDomRefresh = function() {
var _this = this;
-
$("#fileupload", this.el).fileupload({
downloadTemplateId: void 0,
url: "/_upload/",
@@ -71,7 +70,6 @@
MixEditView.prototype.onRender = function() {
var parent;
-
console.log("MixEditView: onRender");
this.sendImage = false;
parent = this;
@@ -103,7 +101,6 @@
},
initSelection: function(element, callback) {
var genres, result;
-
console.log("MixEditView: genres:initSelection");
result = [];
genres = parent.model.get("genre-list");
@@ -134,7 +131,6 @@
MixEditView.prototype.saveChanges = function() {
var data,
_this = this;
-
console.log("MixEditView: saveChanges");
data = Syphon.serialize($("#mix-details-form", this.el)[0]);
this.model.set(data);
@@ -191,6 +187,7 @@
MixEditView;
+
return MixEditView;
})(EditableView);
diff --git a/static/js/app/views/user/userEditView.coffee b/static/js/app/views/user/userEditView.coffee
index c4cd4c9..1a9e4b6 100755
--- a/static/js/app/views/user/userEditView.coffee
+++ b/static/js/app/views/user/userEditView.coffee
@@ -11,12 +11,6 @@ define ['app', 'toastr', 'app.lib/editableView', 'moment', 'utils', 'backbone.sy
avatarType = @model.get('avatar_type')
$('#avatar_' + avatarType, @el).attr('checked', true);
if avatarType is "custom"
- @setupImageEditable
- el: $("#div_avatar_image_upload", @el)
- showbuttons: false
- chooseMessage: "Choose avatar image"
-
- $("#mix-imageupload", @el).jas_fileupload uploadtype: "image"
$("#div_avatar_image_upload", @el).show()
#$("#file_upload").uploadifive uploadScript: "ajax/upload_avatar_image/"
else
diff --git a/static/js/app/views/user/userEditView.js b/static/js/app/views/user/userEditView.js
index 769fa27..839b5e2 100755
--- a/static/js/app/views/user/userEditView.js
+++ b/static/js/app/views/user/userEditView.js
@@ -1,17 +1,16 @@
-// Generated by CoffeeScript 1.6.2
+// Generated by CoffeeScript 1.3.3
(function() {
var __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
define(['app', 'toastr', 'app.lib/editableView', 'moment', 'utils', 'backbone.syphon', 'text!/tpl/UserEditView'], function(App, toastr, EditableView, moment, utils, Syphon, Template) {
- var UserEditView, _ref;
-
+ var UserEditView;
UserEditView = (function(_super) {
+
__extends(UserEditView, _super);
function UserEditView() {
- _ref = UserEditView.__super__.constructor.apply(this, arguments);
- return _ref;
+ return UserEditView.__super__.constructor.apply(this, arguments);
}
UserEditView.prototype.template = _.template(Template);
@@ -23,19 +22,10 @@
UserEditView.prototype.onRender = function() {
var avatarType;
-
console.log("MixEditView: onRender");
avatarType = this.model.get('avatar_type');
$('#avatar_' + avatarType, this.el).attr('checked', true);
if (avatarType === "custom") {
- this.setupImageEditable({
- el: $("#div_avatar_image_upload", this.el),
- showbuttons: false,
- chooseMessage: "Choose avatar image"
- });
- $("#mix-imageupload", this.el).jas_fileupload({
- uploadtype: "image"
- });
$("#div_avatar_image_upload", this.el).show();
} else {
$("#div_avatar_image_upload", this.el).hide();
@@ -45,7 +35,6 @@
UserEditView.prototype.selectAvatar = function(evt) {
var type;
-
type = $(evt.currentTarget).val();
this.model.set("avatar_type", type);
if (type === "custom") {
@@ -57,14 +46,12 @@
UserEditView.prototype.saveChanges = function() {
var data, ref;
-
data = Backbone.Syphon.serialize(this);
this.model.set(data);
ref = this;
this._saveChanges({
success: function() {
var _this = this;
-
if (ref.model.get('avatar_type') === "custom") {
$.ajaxFileUpload({
url: "ajax/upload_avatar_image/",
diff --git a/templates/views/UserEditView.html b/templates/views/UserEditView.html
index 16d5fca..636a0d6 100755
--- a/templates/views/UserEditView.html
+++ b/templates/views/UserEditView.html
@@ -59,13 +59,6 @@
-
-
-
Tell us a bit about yourself.
-
-
-
What can we share about you?