Skip to content

Instantly share code, notes, and snippets.

@joshourisman
Created July 7, 2011 23:57
Show Gist options
  • Save joshourisman/1070824 to your computer and use it in GitHub Desktop.
Save joshourisman/1070824 to your computer and use it in GitHub Desktop.
class RingtoneDetailView(SingleObjectTemplateResponseMixin, ChooseTemplateMixin, SingleObjectMixin, FormMixin, TemplateResponseMixin, ProcessFormView):
model = Ringtone
form_class = RingtoneForm
def dispatch(self, *args, **kwargs):
request = args[0]
device_info = choose_site(request)
self.site_type = device_info['site_type']
self.device = device_info['device']
return super(RingtoneDetailView, self).dispatch(*args, **kwargs)
def get(self, request, *args, **kwargs):
self.object = self.get_object()
if self.device != 'iPhone':
return self.direct_download()
return super(RingtoneDetailView, self).get(request, *args, **kwargs)
def direct_download(self):
filename = self.object.mp3.file.name
response = HttpResponse(open(filename).read(), 'audio/mp3')
response['Content-Disposition'] = 'attachment; filename=%s' % \
os.path.basename(filename)
response['Content-Length'] = os.path.getsize(filename)
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment