Ejemplo n.º 1
0
def edit(request, id):
    library =  get_object_or_404(Library, id=id)
    parent = library.parent
    if not parent:
        if not check_owning(request.user, library) or not request.user.has_perm('participants.change_cbs'):
            return HttpResponse(u'У Вас нет прав на редактирование этой ЦБС')
    else:
        cbs = get_cbs(parent)
        if not check_owning(request.user, cbs) or not request.user.has_perm('participants.change_library'):
            return HttpResponse(u'У Вас нет прав на редактирование филиалов в этой ЦБС')

    if parent:
        LibraryForm = get_library_form(exclude_fields=('parent',))
    else:
        LibraryForm = get_library_form(exclude_fields=('parent','main'))


    if request.method == 'POST':
        library_form = LibraryForm(request.POST, prefix='library_form', instance=library)

        if library_form.is_valid():
            library = library_form.save(commit=False)
            library.types = library_form.cleaned_data['types']
            library.save()
            if parent:
                return redirect('participants:administration:list', parent=parent.id)
            else:
                return redirect('participants:administration:list')
    else:
        library_form = LibraryForm(prefix='library_form', instance=library)

    return render(request, 'participants/administration/edit_library.html', {
        'parent': parent,
        'library_form': library_form,
        })
Ejemplo n.º 2
0
def create(request, parent=None):
    if parent:
        LibraryForm = get_library_form(exclude_fields=('parent',))
    else:
        LibraryForm = get_library_form(exclude_fields=('parent','main'))

    if parent:
        if not request.user.has_perm('participants.add_library'):
            return HttpResponse(u'У Вас нет прав на создание филиалов')

        parent = get_object_or_404(Library, id=parent)

        # находим цбс для этого узла и пррверяем, не принадлежит ли пользователь к ней
        cbs = get_cbs(parent)
        if not check_owning(request.user, cbs):
            return HttpResponse(u'У Вас нет прав на создание филиалов в этой ЦБС')

    else:
        # тут происходит создание цбс, проверяем глобальное право
        if not request.user.has_perm('participants.add_cbs'):
            return HttpResponse(u'У Вас нет прав на создание ЦБС')

    if request.method == 'POST':
        library_form = LibraryForm(request.POST, prefix='library_form')

        if library_form.is_valid():
            library = library_form.save(commit=False)
            if parent:
                library.parent = parent

            library.save()
            library.types = library_form.cleaned_data['types']
            if parent:
                return redirect('participants:administration:list', parent=parent.id)
            else:
                return redirect('participants:administration:list')
    else:
        library_form = LibraryForm(prefix='library_form')

    return render(request, 'participants/administration/create_library.html', {
        'parent': parent,
        'library_form': library_form,
        })