Example #1
0
def media_edit(request, pk):
    """
    Form used for editing a single file. It uses a traditional
    html form and not ajax
    """
    media_file = get_object_or_404(MediaFile, pk=pk)

    if request.method == 'POST':
        form = MediaFileForm(request.POST, request.FILES, instance=media_file)

        if form.is_valid():
            media_file = form.save(commit=False)
            incoming_file = request.FILES.get('media_file')

            if incoming_file:
                if incoming_file.content_type in [
                    'image/jpeg', 'image/png', 'image/gif'
                ]:
                    media_file.thumbnail = incoming_file
                    media_file.thumbnail_medium = incoming_file

            media_file.save()

            # Redirect the user to simple view upon successful update
            messages.success(request, "Media File saved successfully")
            return redirect(media_view, media_file.pk)
    else:
        form = MediaFileForm(instance=media_file)

    page_data = {
        'media_file': media_file,
        'form': form,
    }

    return render(request, 'media/media/edit.html', page_data)
Example #2
0
def media_file_upload(request, manifest_id):
    """
    Form for uploading individual media files associated with a manifest
    """
    manifest = get_object_or_404(Manifest, id=manifest_id)

    manifest_files = MediaFile.objects.filter(manifest=manifest)
    total_files_count = manifest_files.count()
    files_needing_upload = manifest_files.filter(file='')
    files_needing_upload_count = files_needing_upload.count()

    file_to_upload = files_needing_upload.first()

    # If no files left to upload, mark the manifest complete and move on
    if files_needing_upload_count < 1:
        Manifest.objects.filter(id=manifest.id).update(all_media_present=True)
        return HttpResponseRedirect(reverse('manifest-view', args=(manifest.id,)))

    form = MediaFileForm(request.POST or None, request.FILES or None, instance=file_to_upload)

    if form.is_valid():
        form.save()
        return HttpResponseRedirect(reverse('file-upload', args=(manifest.id,)))  # Refresh view

    return render(request, 'file_manager/file_upload.html', {
        'form': form,
        'upload_number': total_files_count - files_needing_upload_count + 1,  # Which place in order of upload e.g. 2 of 3
        'total_files_count': manifest_files.count(),
        'file_to_upload': file_to_upload,
    })
def media_upload(request):
    """Uploads a file to the media library"""
    if request.method == 'POST':
        form = MediaFileForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('media_index'))
    else:
        form = MediaFileForm()

    context = {
        'form': form,
    }

    return render_to_response('wiki/media_upload.html',
            RequestContext(request, context))
Example #4
0
def media_edit(request, pk):
    """
    Form used for editing a single file. It uses a traditional
    html form and not ajax
    """
    media_file = get_object_or_404(MediaFile, pk=pk)

    if request.method == 'POST':
        form = MediaFileForm(request.POST, request.FILES, instance=media_file)

        if form.is_valid():
            media_file = form.save(commit=False)
            incoming_file = request.FILES.get('media_file')

            if incoming_file:
                if incoming_file.content_type in [
                        'image/jpeg', 'image/png', 'image/gif'
                ]:
                    media_file.thumbnail = incoming_file
                    media_file.thumbnail_medium = incoming_file

            media_file.save()

            # Redirect the user to simple view upon successful update
            messages.success(request, "Media File saved successfully")
            return redirect(media_view, media_file.pk)
    else:
        form = MediaFileForm(instance=media_file)

    page_data = {
        'media_file': media_file,
        'form': form,
    }

    return render(request, 'media/media/edit.html', page_data)
def media_upload(request):
    """Uploads a file to the media library"""
    if request.method == 'POST':
        form = MediaFileForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('media_index'))
    else:
        form = MediaFileForm()

    context = {
        'form': form,
    }

    return render_to_response('wiki/media_upload.html',
                              RequestContext(request, context))