Пример #1
0
def upload(request):
    # The assumption here is that jQuery File Upload
    # has been configured to send files one at a time.
    # If multiple files can be uploaded simultaneously,
    # 'file' may be a list of files.
    try:
        uid = request.POST['upload-hash']
        in_file = request.FILES['file'] if request.FILES else None
        file_name, extension = os.path.splitext(in_file.name)

        file_storage = FileSystemStorage(location=os.path.join(settings.CACHE_ROOT, "mixes"))
        cache_file = file_storage.save("%s%s" % (uid, extension), ContentFile(in_file.read()))
        response = ''

        try:
            create_waveform_task.delay(in_file=os.path.join(file_storage.base_location, cache_file), uid=uid)
        except:
            logger.debug("Unable to connect to celery")
            response = 'Unable to connect to waveform generation task, there may be a delay in getting your mix online'

        file_dict = {
            'response': response,
            'size': in_file.size,
            'uid': uid
        }

        return UploadResponse(request, file_dict)
    except Exception, ex:
        logger.exception(ex.message)
        raise
Пример #2
0
    def handle(self, *args, **options):
        print "Scanning for missing waveforms"
        unprocessed = Mix.objects.filter(waveform_generated=False)
        for mix in unprocessed:
            print "Found %s" % mix.slug
            mix_file = self._get_file(mix)

            if mix_file is not "":
                if options['nocelery']:
                    create_waveform_task(in_file=mix_file, uid=mix.uid)
                else:
                    create_waveform_task.delay(in_file=mix_file, uid=mix.uid)