Пример #1
0
    def handle(self, *args, **options):
        from django.db import transaction

        path, slug, name = args

        # Start transaction management.
        transaction.commit_unless_managed()
        transaction.enter_transaction_management()
        transaction.managed(True)

        book = Book.objects.get(slug=slug)

        root, ext = os.path.splitext(path)
        ext = ext.lower()
        if ext:
            ext = ext[1:]
            if ext == "zip":
                ext = "daisy"

        source_sha1 = BookMedia.read_source_sha1(path, ext)
        print "Source file SHA1:", source_sha1
        try:
            assert source_sha1
            bm = book.media.get(type=ext, source_sha1=source_sha1)
            print "Replacing media: %s (%s)" % (bm.name.encode("utf-8"), ext)
        except (AssertionError, BookMedia.DoesNotExist):
            bm = BookMedia(book=book, type=ext)
            print "Creating new media"
        bm.name = name
        bm.file.save(None, ExistingFile(path))
        bm.save()
        transaction.commit()
        transaction.leave_transaction_management()
Пример #2
0
    def handle(self, *args, **options):
        from django.db import transaction

        path, slug, name = args

        # Start transaction management.
        transaction.commit_unless_managed()
        transaction.enter_transaction_management()
        transaction.managed(True)

        book = Book.objects.get(slug=slug)

        root, ext = os.path.splitext(path)
        ext = ext.lower()
        if ext:
            ext = ext[1:]
            if ext == 'zip':
                ext = 'daisy'

        source_sha1 = BookMedia.read_source_sha1(path, ext)
        print "Source file SHA1:", source_sha1
        try:
            assert source_sha1
            bm = book.media.get(type=ext, source_sha1=source_sha1)
            print "Replacing media: %s (%s)" % (bm.name.encode('utf-8'), ext)
        except (AssertionError, BookMedia.DoesNotExist):
            bm = BookMedia(book=book, type=ext)
            print "Creating new media"
        bm.name = name
        bm.file.save(None, ExistingFile(path))
        bm.save()
        transaction.commit()
        transaction.leave_transaction_management()
Пример #3
0
    def post_audiobook(self, request, **kwargs):
        index = int(request.POST['part_index'])
        parts_count = int(request.POST['parts_count'])
        media_type = request.POST['type'].lower()
        source_sha1 = request.POST.get('source_sha1')
        name = request.POST.get('name', '')
        part_name = request.POST.get('part_name', '')

        _rest, slug = request.POST['book'].rstrip('/').rsplit('/', 1)
        book = Book.objects.get(slug=slug)

        try:
            assert source_sha1
            bm = book.media.get(type=media_type, source_sha1=source_sha1)
        except (AssertionError, BookMedia.DoesNotExist):
            bm = BookMedia(book=book, type=media_type)
        bm.name = name
        bm.part_name = part_name
        bm.index = index
        bm.file.save(None, request.data['file'], save=False)
        bm.save(parts_count=parts_count)

        return Response({}, status=status.HTTP_201_CREATED)
Пример #4
0
    def handle(self, *args, **options):
        path, slug, name = args

        book = Book.objects.get(slug=slug)

        root, ext = os.path.splitext(path)
        ext = ext.lower()
        if ext:
            ext = ext[1:]
            if ext == 'zip':
                ext = 'daisy'

        source_sha1 = BookMedia.read_source_sha1(path, ext)
        print "Source file SHA1:", source_sha1
        try:
            assert source_sha1
            bm = book.media.get(type=ext, source_sha1=source_sha1)
            print "Replacing media: %s (%s)" % (bm.name.encode('utf-8'), ext)
        except (AssertionError, BookMedia.DoesNotExist):
            bm = BookMedia(book=book, type=ext)
            print "Creating new media"
        bm.name = name
        bm.file.save(None, ExistingFile(path))
        bm.save()