def ajax_metadata_edit(request, gallery_id, media_id):
    if not request.user.is_staff:
        raise Http404
    
    site = get_current_site(request)
    gallery = get_object_or_404(Gallery, pk=gallery_id, sites=site)
    media = get_object_or_404(MediaUpload, pk=media_id)
    attached = _check_attached(media, gallery)

    if request.method == 'POST':
        if attached:
            return HttpResponse(
                'Media is already attached elsewhere and cannot be edited.',
                status_code=409,
                content_type='text/plain'
            )
        edit_form = MetadataForm(request.POST, instance=media)
        if edit_form.is_valid():
            edit_form.save()
            return HttpResponse('SUCCESS')
    else:
        edit_form = MetadataForm(instance=media)

    post_url = reverse('mediagal_ajax_metadata_edit', args=[gallery_id, media_id])
    return render(request, 'mediagal/ajax_metadata_edit.html',
        {'form': edit_form, 'post_url': post_url})
Exemplo n.º 2
0
def media_selector_edit(request, media_id):
    media_item = get_object_or_404(MediaUpload, pk=media_id)
    if media_item.mediaassociation_set.count():
        return HttpResponseBadRequest('Media has already been attached.')
    if request.method == 'POST':
        form = MetadataForm(request.POST, instance=media_item, prefix='mediaman')
        if form.is_valid():
            media_item = form.save()
            return render_to_response('mediaman/list-item.html', {
                'media_item': media_item
            }, context_instance=RequestContext(request))
    else:
        form = MetadataForm(instance=media_item, prefix='mediaman')
    return render_to_response('mediaman/edit.html', {
        'media_item': media_item,
        'form': form
    }, context_instance=RequestContext(request))