Beispiel #1
0
def add_file(request, model_id=0):
    user = request.user
    model = None
    model_form = None

    if model_id:
        model = get_object_or_404(File, pk=model_id)

    if request.method == "POST":
        if 'file_id' in request.POST:
            case_id = request.POST['file_id']
            model = get_object_or_404(File, pk=case_id)

        form = FileForm(request.POST, request.FILES, instance=model)
        message = 'something wrong!'
        error = True
        if (form.is_valid()):
            error = False
            message = request.POST['name']
            form.save()
        else:
            error = True
            message = json.dumps(form.errors)
        return HttpResponse(json.dumps({'message': message, 'error': error}))
    else:
        # model_form = CaseForm(initial={'add_user': user.id, 'status':1})
        model_form = FileForm(initial={'add_user': user.id, 'case': model_id}, instance=model)

    return render_to_response(
        'cases/file_add.html',

        {'form': model_form,
         'file_id': model_id},
        context_instance=RequestContext(request))
Beispiel #2
0
def upload(request):
    # Handle file upload
    if request.method == 'POST':
        form = FileForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
        else:
            return HttpResponse(form.errors)

            # Redirect to the document list after POST
    return HttpResponseRedirect(request.GET['next'])