Fixed borked release upload..

This commit is contained in:
=
2012-09-17 20:09:54 +01:00
parent ab6ea0a78c
commit a91d495863
15 changed files with 108 additions and 74 deletions

View File

@@ -1,12 +1,12 @@
from unittest import TestCase
class Mix(object):
class MixTestItem(object):
def get_mix_at(self, hour):
pass
class MixTest(TestCase):
def test_simple(self):
m = Mix()
m = MixTestItem()

View File

@@ -236,7 +236,6 @@ PIPELINE_CSS = {
},
},
}
COMPRESS_ENABLED = True
COMPRESS_CSS_FILTERS = [
'compressor.filters.css_default.CssAbsoluteFilter',
]

View File

@@ -32,7 +32,7 @@ class MixResource(BackboneCompatibleResource):
return Mix.get_listing(sort, request.user)
def dehydrate_mix_image(self, bundle):
return bundle.obj.get_image()
return bundle.obj.get_image_url()
def dehydrate_description(self, bundle):
return bundle.obj.description.replace("\n", "<br />")

View File

@@ -0,0 +1,18 @@
from shutil import copyfile
from django.core.management.base import NoArgsCommand
import os
from spa.models import Mix
class Command(NoArgsCommand):
def handle_noargs(self, **options):
mixes = Mix.objects.all()
for mix in mixes:
filename = mix.mix_image.file.name
if os.path.isfile(filename):
filename, extension = os.path.splitext(filename)
new_file = "%s/%s%s" % (os.path.dirname(mix.mix_image.file.name), mix.uid, extension)
print "Moving %s to %s" % (mix.mix_image.file.name, new_file)
mix.mix_image = extension
mix.save()
copyfile(filename, new_file)

View File

@@ -53,7 +53,11 @@ class Mix(_BaseModel):
ret = "%s/%s.%s" % (waveform_root, self.uid, "png")
return ret
def get_image(self):
def get_image_url(self):
images_root = localsettings.IMAGE_URL if hasattr(localsettings, 'IMAGE_URL') else "%s/mix_images/" % settings.MEDIA_URL
ret = "%s/%s.%s" % (images_root, self.uid, self.mix_image)
return ret
"""
try:
if os.path.isfile(self.mix_image.path):
image_root = localsettings.IMAGE_URL if hasattr(localsettings, 'IMAGE_URL') else settings.MEDIA_URL
@@ -63,10 +67,11 @@ class Mix(_BaseModel):
return settings.STATIC_URL + 'img/default-track.png'
return settings.STATIC_URL + 'img/default-track.png'
"""
def get_stream_path(self):
#return 'media/%s/' % self.local_file.name
return '/audio/stream/%d' % self.id;
return '/audio/stream/%d' % self.id
@classmethod
def get_listing(cls, listing_type, user=None):

View File

@@ -25,6 +25,6 @@ class _BaseModel(models.Model):
def get_lookup_filter_field(cls):
field_list = cls._meta.get_all_field_names();
for field in field_list:
if field.endswith("_name"):
if field.endswith("name") or field.endswith("description"):
return field
return "description"

View File

@@ -28,7 +28,7 @@ def redirect_mix(request, mix_id):
except Mix.DoesNotExist:
raise Http404
image = mix.get_image()
image = mix.get_image_url()
audio_url = mix.get_stream_path()
redirect_url = mix.get_absolute_url()
response = render_to_response(

View File

@@ -10,19 +10,19 @@ var Release = DSSModel.extend({
urlRoot:com.podnoms.settings.urlRoot + "release/",
isValid:function () {
this.errors = {};
if (isEmpty(this.get('release_label'))) {
if (com.podnoms.utils.isEmpty(this.get('release_label'))) {
return this.addError('release_label', 'Please choose a label');
}
if (isEmpty(this.get('release_title'))) {
if (com.podnoms.utils.isEmpty(this.get('release_title'))) {
return this.addError('release_title', 'Please choose a title');
}
if (isEmpty(this.get('release_artist'))) {
if (com.podnoms.utils.isEmpty(this.get('release_artist'))) {
return this.addError('release_artist', 'Please choose an artist');
}
if (isEmpty(this.get('release_date'))) {
if (com.podnoms.utils.isEmpty(this.get('release_date'))) {
return this.addError('release_date', 'Please choose a valid date');
}
if (isEmpty(this.get('release_description'))) {
if (com.podnoms.utils.isEmpty(this.get('release_description'))) {
return this.addError('release_description', 'Please enter a description of some sort');
}
return "";

View File

@@ -73,7 +73,7 @@ var EventCreateView = DSSEditableView.extend({
"click #save-changes":"saveChanges",
"change input":"changed",
"change textarea":"changed",
"change select": "changeSelect"
"change select":"changeSelect"
},
initialize:function () {
this.render();
@@ -84,11 +84,13 @@ var EventCreateView = DSSEditableView.extend({
return this;
},
saveChanges:function () {
var model = this.model;
this.model.set('event_description', $('#event-description', this.el).html());
this.model.set('event_date', $('#event_date', this.el).val());
this._saveChanges({
success:function () {
com.podnoms.utils.showAlert("Success", "Event successfully added", "alert-info", true);
app.navigate('#/event/' + model.get('id'));
}
});
return false;

View File

@@ -69,14 +69,17 @@ var ReleaseView = Backbone.View.extend({
});
var ReleaseCreateView = DSSEditableView.extend({
events:{
"click #save-changes":"saveChanges"
"click #save-changes":"saveChanges",
"change input":"changed",
"change textarea":"changed",
"change select":"changeSelect"
},
initialize:function () {
this.render();
},
render:function () {
$(this.el).html(this.template({"item":this.model.toJSON()}));
this._bakeForm(this.el, 'release');
this._bakeForm(this.el, 'label');
},
saveChanges:function () {
var model = this.model;
@@ -89,27 +92,30 @@ var ReleaseCreateView = DSSEditableView.extend({
this._saveChanges({
success:function () {
$.ajaxFileUpload({
url:'ajax/upload_release_image/' + model.get('id') + '/',
secureuri:false,
fileElementId:'release_image',
success:function (data, status) {
if (typeof(data.error) != 'undefined') {
if (data.error != '') {
alert(data.error);
} else {
alert(data.msg);
}
} else {
com.podnoms.utils.showAlert("Success", "Release successfully added", "alert-info", true);
app.navigate('#/release/' + model.get('id'));
}
},
error:function (data, status, e) {
alert(e);
}
});
com.podnoms.utils.showAlert("Success", "Release successfully added", "alert-info", true);
window.app.navigate('#/release/' + model.get('id'), true);
}
/*
$.ajaxFileUpload({
url:'ajax/upload_release_image/' + model.get('id') + '/',
secureuri:false,
fileElementId:'release_image',
success:function (data, status) {
if (typeof(data.error) != 'undefined') {
if (data.error != '') {
alert(data.error);
} else {
alert(data.msg);
}
} else {
com.podnoms.utils.showAlert("Success", "Release successfully added", "alert-info", true);
app.navigate('#/release/' + model.get('id'));
}
},
error:function (data, status, e) {
alert(e);
}
});*/
});
return false;
}

View File

@@ -132,6 +132,7 @@ window.DSSEditableView = Backbone.View.extend({
});
},
_saveChanges:function () {
var args = arguments;
if (this.model.isValid() != "") {
if (this.model.errors) {
for (var error in this.model.errors) {
@@ -143,7 +144,7 @@ window.DSSEditableView = Backbone.View.extend({
this.model.save(
null, {
success:function () {
arguments.success();
args[0].success();
},
error:function () {
alert("Error saving release");

View File

@@ -79,10 +79,6 @@
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script src="http://fergalmoran.github.com/cdn/js/jquery.form.min.js"></script>
{% if debug %}
<script src="{{ STATIC_URL }}js/libs/jasny/jasny-bootstrap.js"></script>
<script src="{{ STATIC_URL }}js/libs/bootstrap/bootstrap-timepicker.js"></script>

View File

@@ -0,0 +1,26 @@
<div class="span6">
<div class="control-group" id="group-release_image">
<div class="fileupload fileupload-new" data-provides="fileupload">
<div class="fileupload-new thumbnail" style="width: 200px; height: 150px;">
<img src="http://www.placehold.it/200x150/EFEFEF/AAAAAA&text=no+image"/>
</div>
<div class="fileupload-preview fileupload-exists thumbnail"
style="max-width: 200px; max-height: 150px; line-height: 20px;">
</div>
<div>
<span class="btn btn-file">
<span class="fileupload-new">
Select image
</span>
<span class="fileupload-exists">
Change
</span>
<input id="release_image" type="file" size="45" name="release_image" class="input">
</span>
<a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>
</div>
</div>
<span class="help-inline" id="error-release_image"></span>
</div>
</div>

View File

@@ -7,7 +7,6 @@
<div class="span6">
<div class="control-group" id="group-event_venue">
<label class="control-label">Venue</label>
<div class="controls">
<input id="event_venue" class="typeahead" autocomplete="off" type="text"
data-provide="typeahead" value="<%= item.event_venue %>" placeholder="Where's it on...">

View File

@@ -6,6 +6,7 @@
<div class="span6">
<div class="control-group" id="group-release_label">
<label class="control-label">Label</label>
<div class="controls">
<input id="release_label" class="typeahead" autocomplete="off" type="text"
data-provide="typeahead">
@@ -15,6 +16,7 @@
</div>
<div class="control-group" id="group-release_artist">
<label class="control-label">Artist</label>
<div class="controls">
<input id="release_artist" type="text" placeholder="Who dunnit…">
<span class="help-inline" id="error-release_artist"></span>
@@ -24,6 +26,7 @@
<div class="span6">
<div class="control-group" id="group-release_title">
<label class="control-label">Title</label>
<div class="controls">
<input id="release_title" type="text" placeholder="What they dun…">
<span class="help-inline" id="error-release_title"></span>
@@ -31,6 +34,7 @@
</div>
<div class="control-group" id="group-release_date">
<label class="control-label">Release date</label>
<div class="controls">
<input id="release_date" class="datepicker" type="text" value="<%= item.release_date %>">
<span class="help-inline" id="error-release_date"></span>
@@ -39,43 +43,21 @@
</div>
</div>
<div class="row">
<div class="control-group" id="group-release_description">
<label class="control-label">Description</label>
<div class="control-group">
<label class="control-label">Embed Code</label>
<div class="controls">
<textarea style="width:100%" class="tinymce" id="release-description" rows="10"/>
<span class="help-inline" id="error-release_description"></span>
<textarea style="width:98%" id="embed_code" rows="3"/>
</div>
</div>
</div>
<div class="row">
<div class="span6">
<div class="control-group">
<label class="control-label">Embed Code</label>
<div class="controls">
<textarea style="width:100%" id="embed_code" rows="10"/>
</div>
</div>
</div>
<div class="span6">
<div class="fileupload fileupload-new" data-provides="fileupload">
<div class="fileupload-new thumbnail" style="width: 200px; height: 150px;">
<img src="http://www.placehold.it/200x150/EFEFEF/AAAAAA&text=no+image"/>
</div>
<div class="fileupload-preview fileupload-exists thumbnail"
style="max-width: 200px; max-height: 150px; line-height: 20px;">
</div>
<div>
<span class="btn btn-file">
<span class="fileupload-new">
Select image
</span>
<span class="fileupload-exists">
Change
</span>
<input id="release_image" type="file" size="45" name="release_image" class="input">
</span>
<a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>
</div>
<div class="control-group" id="group-release_description">
<label class="control-label">Description</label>
<div class="controls">
<textarea style="width:100%" class="tinymce" id="release-description" rows="10"/>
<span class="help-inline" id="error-release_description"></span>
</div>
</div>
</div>