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, })
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, })
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, })
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, })
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, })
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, })
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, })
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, })
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, })
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, })