コード例 #1
0
ファイル: groups.py プロジェクト: Anlim/wagtail
def create(request):
    group = Group()
    if request.POST:
        form = GroupForm(request.POST, instance=group)
        permission_panels = [
            cls(request.POST, instance=group)
            for cls in get_permission_panel_classes()
        ]
        if form.is_valid() and all(panel.is_valid() for panel in permission_panels):
            form.save()

            for panel in permission_panels:
                panel.save()

            messages.success(request, _("Group '{0}' created.").format(group), buttons=[
                messages.button(reverse('wagtailusers_groups:edit', args=(group.id,)), _('Edit'))
            ])
            return redirect('wagtailusers_groups:index')
        else:
            messages.error(request, _("The group could not be created due to errors."))
    else:
        form = GroupForm(instance=group)
        permission_panels = [
            cls(instance=group)
            for cls in get_permission_panel_classes()
        ]

    return render(request, 'wagtailusers/groups/create.html', {
        'form': form,
        'permission_panels': permission_panels,
    })
コード例 #2
0
ファイル: groups.py プロジェクト: DimiC/wagtail
def edit(request, group_id):
    group = get_object_or_404(Group, id=group_id)
    if request.method == 'POST':
        form = GroupForm(request.POST, instance=group)
        permission_panels = [
            cls(request.POST, instance=group)
            for cls in get_permission_panel_classes()
        ]
        if form.is_valid() and all(panel.is_valid() for panel in permission_panels):
            form.save()

            for panel in permission_panels:
                panel.save()

            messages.success(request, _("Group '{0}' updated.").format(group), buttons=[
                messages.button(reverse('wagtailusers_groups:edit', args=(group.id,)), _('Edit'))
            ])
            return redirect('wagtailusers_groups:index')
        else:
            messages.error(request, _("The group could not be saved due to errors."))
    else:
        form = GroupForm(instance=group)
        permission_panels = [
            cls(instance=group)
            for cls in get_permission_panel_classes()
        ]

    return render(request, 'wagtailusers/groups/edit.html', {
        'group': group,
        'form': form,
        'permission_panels': permission_panels,
    })
コード例 #3
0
def create(request):
    GroupPagePermissionFormSet = inlineformset_factory(
        Group,
        GroupPagePermission,
        formset=BaseGroupPagePermissionFormSet,
        extra=0)
    if request.POST:
        form = GroupForm(request.POST)
        formset = GroupPagePermissionFormSet(request.POST)
        if form.is_valid() and formset.is_valid():
            group = form.save()
            formset.instance = group
            formset.save()
            messages.success(request,
                             _("Group '{0}' created.").format(group),
                             buttons=[
                                 messages.button(
                                     reverse('wagtailusers_groups_edit',
                                             args=(group.id, )), _('Edit'))
                             ])
            return redirect('wagtailusers_groups_index')
        else:
            messages.error(request,
                           _("The group could not be created due to errors."))
    else:
        form = GroupForm()
        formset = GroupPagePermissionFormSet()

    return render(request, 'wagtailusers/groups/create.html', {
        'form': form,
        'formset': formset,
    })
コード例 #4
0
def edit(request, group_id):
    group = get_object_or_404(Group, id=group_id)
    GroupPagePermissionFormSet = inlineformset_factory(
        Group,
        GroupPagePermission,
        formset=BaseGroupPagePermissionFormSet,
        extra=0)
    if request.POST:
        form = GroupForm(request.POST, instance=group)
        formset = GroupPagePermissionFormSet(request.POST, instance=group)
        if form.is_valid() and formset.is_valid():
            group = form.save()
            formset.save()
            messages.success(request,
                             _("Group '{0}' updated.").format(group),
                             buttons=[
                                 messages.button(
                                     reverse('wagtailusers_groups_edit',
                                             args=(group.id, )), _('Edit'))
                             ])
            return redirect('wagtailusers_groups_index')
        else:
            messages.error(request,
                           _("The group could not be saved due to errors."))
    else:
        form = GroupForm(instance=group)
        formset = GroupPagePermissionFormSet(instance=group)

    return render(request, 'wagtailusers/groups/edit.html', {
        'group': group,
        'form': form,
        'formset': formset,
    })
コード例 #5
0
ファイル: groups.py プロジェクト: Gavryush/wagtail
def create(request):
    GroupPagePermissionFormSet = inlineformset_factory(
        Group,
        GroupPagePermission,
        formset=BaseGroupPagePermissionFormSet,
        extra=0
    )
    if request.POST:
        form = GroupForm(request.POST)
        formset = GroupPagePermissionFormSet(request.POST)
        if form.is_valid() and formset.is_valid():
            group = form.save()
            formset.instance = group
            formset.save()
            messages.success(request, _("Group '{0}' created.").format(group))
            return redirect('wagtailusers_groups_index')
        else:
            messages.error(request, _("The group could not be created due to errors."))
    else:
        form = GroupForm()
        formset = GroupPagePermissionFormSet()

    return render(request, 'wagtailusers/groups/create.html', {
        'form': form,
        'formset': formset,
    })
コード例 #6
0
ファイル: groups.py プロジェクト: Gavryush/wagtail
def edit(request, group_id):
    group = get_object_or_404(Group, id=group_id)
    GroupPagePermissionFormSet = inlineformset_factory(
        Group,
        GroupPagePermission,
        formset=BaseGroupPagePermissionFormSet,
        extra=0
    )
    if request.POST:
        form = GroupForm(request.POST, instance=group)
        formset = GroupPagePermissionFormSet(request.POST, instance=group)
        if form.is_valid() and formset.is_valid():
            group = form.save()
            formset.save()
            messages.success(request, _("Group '{0}' updated.").format(group))
            return redirect('wagtailusers_groups_index')
        else:
            messages.error(request, _("The group could not be saved due to errors."))
    else:
        form = GroupForm(instance=group)
        formset = GroupPagePermissionFormSet(instance=group)

    return render(request, 'wagtailusers/groups/edit.html', {
        'group': group,
        'form': form,
        'formset': formset,
    })
コード例 #7
0
def edit(request, group_id):
    group = get_object_or_404(Group, id=group_id)
    if request.method == 'POST':
        form = GroupForm(request.POST, instance=group)
        permission_panels = [
            cls(request.POST, instance=group)
            for cls in get_permission_panel_classes()
        ]
        if form.is_valid() and all(panel.is_valid()
                                   for panel in permission_panels):
            form.save()

            for panel in permission_panels:
                panel.save()

            messages.success(request,
                             _("Group '{0}' updated.").format(group),
                             buttons=[
                                 messages.button(
                                     reverse('wagtailusers_groups:edit',
                                             args=(group.id, )), _('Edit'))
                             ])
            return redirect('wagtailusers_groups:index')
        else:
            messages.error(request,
                           _("The group could not be saved due to errors."))
    else:
        form = GroupForm(instance=group)
        permission_panels = [
            cls(instance=group) for cls in get_permission_panel_classes()
        ]

    return render(request, 'wagtailusers/groups/edit.html', {
        'group': group,
        'form': form,
        'permission_panels': permission_panels,
    })
コード例 #8
0
def create(request):
    group = Group()
    if request.POST:
        form = GroupForm(request.POST, instance=group)
        permission_panels = [
            cls(request.POST, instance=group)
            for cls in get_permission_panel_classes()
        ]
        if form.is_valid() and all(panel.is_valid()
                                   for panel in permission_panels):
            form.save()

            for panel in permission_panels:
                panel.save()

            messages.success(request,
                             _("Group '{0}' created.").format(group),
                             buttons=[
                                 messages.button(
                                     reverse('wagtailusers_groups:edit',
                                             args=(group.id, )), _('Edit'))
                             ])
            return redirect('wagtailusers_groups:index')
        else:
            messages.error(request,
                           _("The group could not be created due to errors."))
    else:
        form = GroupForm(instance=group)
        permission_panels = [
            cls(instance=group) for cls in get_permission_panel_classes()
        ]

    return render(request, 'wagtailusers/groups/create.html', {
        'form': form,
        'permission_panels': permission_panels,
    })
コード例 #9
0
ファイル: groups.py プロジェクト: AustinBurns/wagtail
def create(request):
    if request.POST:
        form = GroupForm(request.POST)
        formset = GroupPagePermissionFormSet(request.POST)
        if form.is_valid() and formset.is_valid():
            group = form.save()
            formset.instance = group
            formset.save()
            messages.success(request, _("Group '{0}' created.").format(group), buttons=[
                messages.button(reverse('wagtailusers_groups_edit', args=(group.id,)), _('Edit'))
            ])
            return redirect('wagtailusers_groups_index')
        else:
            messages.error(request, _("The group could not be created due to errors."))
    else:
        form = GroupForm()
        formset = GroupPagePermissionFormSet()

    return render(request, 'wagtailusers/groups/create.html', {
        'form': form,
        'formset': formset,
    })
コード例 #10
0
ファイル: groups.py プロジェクト: AustinBurns/wagtail
def edit(request, group_id):
    group = get_object_or_404(Group, id=group_id)
    if request.POST:
        form = GroupForm(request.POST, instance=group)
        formset = GroupPagePermissionFormSet(request.POST, instance=group)
        if form.is_valid() and formset.is_valid():
            group = form.save()
            formset.save()
            messages.success(request, _("Group '{0}' updated.").format(group), buttons=[
                messages.button(reverse('wagtailusers_groups_edit', args=(group.id,)), _('Edit'))
            ])
            return redirect('wagtailusers_groups_index')
        else:
            messages.error(request, _("The group could not be saved due to errors."))
    else:
        form = GroupForm(instance=group)
        formset = GroupPagePermissionFormSet(instance=group)

    return render(request, 'wagtailusers/groups/edit.html', {
        'group': group,
        'form': form,
        'formset': formset,
    })