Added download url

This commit is contained in:
=
2012-09-24 19:41:48 +01:00
parent d9a31b6028
commit 558917b764
5 changed files with 32 additions and 6 deletions

View File

@@ -18,10 +18,11 @@ def download(request, mix_id):
try:
mix = Mix.objects.get(pk=mix_id)
if mix is not None:
filename = mix.local_file.path # Select your file here.
file, ext = os.path.splitext(filename)
response = sendfile(request, filename, attachment=True, attachment_filename="%s.%s" % (mix.title, ext))
return response
if mix.download_allowed:
filename = mix.local_file.path # Select your file here.
file, ext = os.path.splitext(filename)
response = sendfile(request, filename, attachment=True, attachment_filename="%s.%s" % (mix.title, ext))
return response
except Exception, ex:
print ex

View File

@@ -33,6 +33,7 @@ class Mix(_BaseModel):
user = models.ForeignKey(UserProfile, editable=False)
waveform_generated = models.BooleanField(default=False)
uid = models.CharField(max_length=38, blank=True, unique=True)
download_allowed = models.BooleanField(default=False)
def __unicode__(self):
return self.title

View File

@@ -14,7 +14,8 @@ window.MixListItemView = Backbone.View.extend({
"click .play-button-small-pause":"pauseMix",
"click .like-button a":"likeMix",
"click .favourite-button a":"favouriteMix",
"click .share-button":"shareLink"
"click .share-button":"shareLink",
"click .download-button a":"downloadMix"
},
initialize:function () {
$(this.el).attr("id", "mixitem-" + this.model.get("id"));
@@ -49,6 +50,11 @@ window.MixListItemView = Backbone.View.extend({
else if (mode == "twitter")
sharePageToTwitter(this.model);
},
downloadMix:function (e) {
var id = $(e.currentTarget).data("id");
var mode = $(e.currentTarget).data("mode");
com.podnoms.utils.downloadURL("/audio/download/" + id);
},
likeMix:function (e) {
var id = $(e.currentTarget).data("id");
var mode = $(e.currentTarget).data("mode");

View File

@@ -88,6 +88,17 @@ com.podnoms.utils = {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
},
downloadURL:function downloadURL(url) {
var iframe;
iframe = document.getElementById("hiddenDownloader");
if (iframe === null) {
iframe = document.createElement('iframe');
iframe.id = "hiddenDownloader";
iframe.style.visibility = 'hidden';
document.body.appendChild(iframe);
}
iframe.src = url;
}
};

View File

@@ -16,7 +16,6 @@
<img id="waveform-image-<%= item.id %>" class="waveform_image"
alt="Audio waveform"
src="<%= item.waveform_url %>">
<div class="download-progress-overlay" id="progress-player-<%= item.id %>"></div>
<div class="playhead" id="playhead-player-<%= item.id %>" style="width: 0px"></div>
</div>
@@ -48,6 +47,14 @@
</ul>
</div>
</div>
{% if user.is_authenticated %}
<% if (item.download_allowed) { %>
<div class="download-button footer-button">
<a class="btn" data-mode="<%= item.mode %>" data-id="<%= item.id %>">
<i class="icon-download"></i> Download</a>
</div>
<% } %>
{% endif %}
<div class="footer-button">
<ul class="list-nostyle list-horiz">
<li title="<%= item.play_count %> Plays" class="stats-item bordered-right">