Пример #1
0
def category_edit(request, knowledgeCategory_id, response_format='html'):
    "Knowledge category edit page"
    category = get_object_or_404(KnowledgeCategory, pk=knowledgeCategory_id)
    items = Object.filter_permitted(manager=KnowledgeItem.objects, user=request.user.get_profile(), mode='r')
    
    if not request.user.get_profile().has_permission(category, mode="w"):
        return user_denied(request, message="You don't have access to this Knowledge Category")
    
    if request.POST:
        if not 'cancel' in request.POST:
            form = KnowledgeCategoryForm(request.POST, instance=category)
            if form.is_valid():
                category = form.save()
                return HttpResponseRedirect(reverse('knowledge_category_view', args=[category.treepath]))
        else:
            return HttpResponseRedirect(reverse('knowledge_category_view', args=[category.treepath]))
    else:
        form = KnowledgeCategoryForm(instance=category)
        
    context = _get_default_context(request)
    context.update({'form': form, 
                    'category': category, 
                    'items':items})
        
    return render_to_response('knowledge/category_edit', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Пример #2
0
def category_edit(request, knowledgeCategory_id, response_format='html'):
    "Knowledge category edit page"
    category = get_object_or_404(KnowledgeCategory, pk=knowledgeCategory_id)
    items = Object.filter_permitted(manager=KnowledgeItem.objects,
                                    user=request.user.get_profile(),
                                    mode='r')

    if not request.user.get_profile().has_permission(category, mode="w"):
        return user_denied(
            request,
            message="You don't have access to this Knowledge Category")

    if request.POST:
        if not 'cancel' in request.POST:
            form = KnowledgeCategoryForm(request.POST, instance=category)
            if form.is_valid():
                category = form.save()
                return HttpResponseRedirect(
                    reverse('knowledge_category_view',
                            args=[category.treepath]))
        else:
            return HttpResponseRedirect(
                reverse('knowledge_category_view', args=[category.treepath]))
    else:
        form = KnowledgeCategoryForm(instance=category)

    context = _get_default_context(request)
    context.update({'form': form, 'category': category, 'items': items})

    return render_to_response('knowledge/category_edit',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Пример #3
0
def category_add(request, response_format='html'):
    "Add new knowledge category"

    if request.POST:
        if not 'cancel' in request.POST:
            category = KnowledgeCategory()
            form = KnowledgeCategoryForm(request.POST, instance=category)
            if form.is_valid():
                category = form.save()
                category.set_user_from_request(request)
                return HttpResponseRedirect(
                    reverse('knowledge_category_view',
                            args=[category.treepath]))
        else:
            return HttpResponseRedirect(reverse('knowledge_categories'))
    else:
        form = KnowledgeCategoryForm()

    context = _get_default_context(request)
    context.update({'form': form})

    return render_to_response('knowledge/category_add',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Пример #4
0
def category_add(request, response_format='html'):
    "Add new knowledge category"
 
    if request.POST:
        if not 'cancel' in request.POST:
            category = KnowledgeCategory()
            form = KnowledgeCategoryForm(request.POST, instance=category)
            if form.is_valid():
                category = form.save()
                category.set_user_from_request(request)
                return HttpResponseRedirect(reverse('knowledge_category_view', args=[category.treepath]))
        else:
            return HttpResponseRedirect(reverse('knowledge_categories'))
    else:   
        form = KnowledgeCategoryForm()
        
    context = _get_default_context(request)
    context.update({'form': form})
    
    return render_to_response('knowledge/category_add', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)