Beispiel #1
0
def folder_edit(request, knowledgeType_id, response_format='html'):
    "Knowledge folder edit page"
    
    folder = get_object_or_404(KnowledgeFolder, pk=knowledgeType_id)
    items = Object.filter_by_request(request, manager=KnowledgeItem.objects.filter(folder=folder)) 
    
    if not request.user.get_profile().has_permission(folder, mode="w"):
        return user_denied(request, message="You don't have access to this Knowledge Type")
    
    if request.POST:
        if not 'cancel' in request.POST:
            form = KnowledgeFolderForm(request.user.get_profile(), None, request.POST, instance=folder)
            if form.is_valid():
                folder = form.save()
                return HttpResponseRedirect(reverse('knowledge_folder_view', args=[folder.treepath]))
        else:
            return HttpResponseRedirect(reverse('knowledge_folder_view', args=[folder.treepath]))
    else:
        form = KnowledgeFolderForm(request.user.get_profile(), None, instance=folder)       

    context = _get_default_context(request)
    context.update({'items': items,
                    'folder': folder,
                    'form': form})
        
    return render_to_response('knowledge/folder_edit', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Beispiel #2
0
def folder_add(request, response_format='html'):
    "New folder form"

    if request.POST:
        if not 'cancel' in request.POST:
            folder = KnowledgeFolder()
            form = KnowledgeFolderForm(request.user.get_profile(), None, request.POST, instance=folder)
            if form.is_valid():
                folder = form.save()
                folder.set_user_from_request(request)
                return HttpResponseRedirect(reverse('knowledge_folder_view', args=[folder.treepath]))
        else:
            return HttpResponseRedirect(reverse('knowledge'))
    else:   
        form = KnowledgeFolderForm(request.user.get_profile(), None)
        
    context = _get_default_context(request)
    context.update({'form': form})
    
    return render_to_response('knowledge/folder_add', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Beispiel #3
0
def folder_add_folder(request, folderPath, response_format='html'):
    "Add new knowledge folder to preselected folder"
    
    try:
        folder = KnowledgeFolder.by_path(folderPath)
        knowledgeType_id = folder.id
    except KnowledgeFolder.DoesNotExist:
        raise Http404
    
    parent = None
    if knowledgeType_id:
        parent = get_object_or_404(KnowledgeFolder, pk=knowledgeType_id)
        if not request.user.get_profile().has_permission(parent, mode='x'):
            parent = None
            
    if request.POST:
        if not 'cancel' in request.POST:
            folder = KnowledgeFolder()
            form = KnowledgeFolderForm(request.user.get_profile(), knowledgeType_id, 
                                       request.POST, instance=folder)
            if form.is_valid():
                folder = form.save()
                folder.set_user_from_request(request)
                return HttpResponseRedirect(reverse('knowledge_folder_view', args=[folder.treepath]))
        else:
            return HttpResponseRedirect(reverse('knowledge'))
    else:   
        form = KnowledgeFolderForm(request.user.get_profile(), knowledgeType_id)
        
    context = _get_default_context(request)
    context.update({'form': form,
                    'parent':parent})
        
    return render_to_response('knowledge/folder_add_folder', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)