Beispiel #1
0
def edit_document(request, pk):
    """ Edit a document """
    document = Document.objects.get(pk=pk)
    eform = EditDocumentForm(instance=document)
    rform = ReferenceForm(instance=document.reference)
    if request.method == 'POST':
        rform = ReferenceForm(request.POST, instance=document.reference)
        eform = EditDocumentForm(request.POST, instance=document)
        #this avoids ignoring the evaluation of the form to show the errors
        rf_is_valid = rform.is_valid()
        ef_is_valid = eform.is_valid()
        if rf_is_valid and ef_is_valid:
            rform.save()
            eform.instance.reference = rform.instance
            eform.save()
            return HttpResponseRedirect(reverse('documents.views.list_documents'))

    return render_to_response('edit_document.html', {
        'document': document,
        'rform': rform,
        'eform': eform,
    }, context_instance=RequestContext(request))
Beispiel #2
0
def add_document(request):
    """ Add a document """
    dform = DocumentForm(user=request.user)
    rform = ReferenceForm()
    if request.method == 'POST':
        rform = ReferenceForm(request.POST)
        dform = DocumentForm(request.POST, request.FILES, user=request.user)
        #this avoids ignoring the evaluation of the form to show the errors
        rf_is_valid = rform.is_valid()
        df_is_valid = dform.is_valid()
        if rf_is_valid and df_is_valid:
            rform.save()
            dform.instance.reference = rform.instance
            dform.save()
            file = dform.cleaned_data['file']
            dform.instance.set_file(file=file, filename=file.name)
            assign_perm('documents.access_document', request.user, dform.instance)
            return HttpResponseRedirect(reverse('documents.views.list_documents'))

    return render_to_response('add_document.html', {
        'dform': dform,
        'rform': rform,
    }, context_instance=RequestContext(request))