示例#1
0
def cli_manage_slide(request):
    """
    Accepts POSTS from authenticated clients, and allows those clients to either
    create or modify existing slides.
    """
    if request.method == 'POST':
        f = CLICCreateSlideForm(request.POST, request.FILES)
        if f.is_valid():
            tf = tarfile.open(fileobj=request.FILES['bundle'])
            id = f.cleaned_data['id']
            create = f.cleaned_data['mode'] == 'create'
            if create and not id:
                s = Slide(user=request.user,
                          title='cli uploaded %s' % (tf.__hash__()))
            elif not create and id:
                s = Slide.objects.get(id=id)
                if not s.allowed(request.user):
                    return HttpResponse('Not allowed to modify slide')
            else:
                return HttpResponse('invalid: %s' % str(f.data))
            s.populate_from_bundle(request.FILES['bundle'], tf)
            return HttpResponse('Slide %s %sd'
                                % (s.id, f.cleaned_data['mode']))
    return HttpResponseNotAllowed(['POST'])