def edit(request, redirect_id): theredirect = get_object_or_404(models.Redirect, id=redirect_id) if not permission_policy.user_has_permission_for_instance(request.user, "change", theredirect): return permission_denied(request) if request.POST: form = RedirectForm(request.POST, request.FILES, instance=theredirect) if form.is_valid(): form.save() messages.success( request, _("Redirect '{0}' updated.").format(theredirect.title), buttons=[messages.button(reverse("wagtailredirects:edit", args=(theredirect.id,)), _("Edit"))], ) return redirect("wagtailredirects:index") else: messages.error(request, _("The redirect could not be saved due to errors.")) else: form = RedirectForm(instance=theredirect) return render( request, "wagtailredirects/edit.html", { "redirect": theredirect, "form": form, "user_can_delete": permission_policy.user_has_permission(request.user, "delete"), }, )
def edit(request, redirect_id): theredirect = get_object_or_404(models.Redirect, id=redirect_id) if not permission_policy.user_has_permission_for_instance( request.user, 'change', theredirect): return permission_denied(request) if request.method == 'POST': form = RedirectForm(request.POST, request.FILES, instance=theredirect) if form.is_valid(): form.save() messages.success( request, _("Redirect '{0}' updated.").format(theredirect.title), buttons=[ messages.button( reverse('wagtailredirects:edit', args=(theredirect.id, )), _('Edit')) ]) return redirect('wagtailredirects:index') else: messages.error(request, _("The redirect could not be saved due to errors.")) else: form = RedirectForm(instance=theredirect) return render( request, "wagtailredirects/edit.html", { 'redirect': theredirect, 'form': form, 'user_can_delete': permission_policy.user_has_permission(request.user, 'delete'), })
def edit(request, redirect_id): theredirect = get_object_or_404(models.Redirect, id=redirect_id) if not permission_policy.user_has_permission_for_instance( request.user, 'change', theredirect ): return permission_denied(request) if request.method == 'POST': form = RedirectForm(request.POST, request.FILES, instance=theredirect) if form.is_valid(): form.save() messages.success(request, _("Redirect '{0}' updated.").format(theredirect.title), buttons=[ messages.button(reverse('wagtailredirects:edit', args=(theredirect.id,)), _('Edit')) ]) return redirect('wagtailredirects:index') else: messages.error(request, _("The redirect could not be saved due to errors.")) else: form = RedirectForm(instance=theredirect) return render(request, "wagtailredirects/edit.html", { 'redirect': theredirect, 'form': form, 'user_can_delete': permission_policy.user_has_permission(request.user, 'delete'), })
def add(request): if request.POST: form = RedirectForm(request.POST, request.FILES) if form.is_valid(): theredirect = form.save() messages.success(request, _("Redirect '{0}' added.").format(theredirect.title), buttons=[ messages.button(reverse('wagtailredirects:edit', args=(theredirect.id,)), _('Edit')) ]) return redirect('wagtailredirects:index') else: messages.error(request, _("The redirect could not be created due to errors.")) else: form = RedirectForm() return render(request, "wagtailredirects/add.html", { 'form': form, })
def add(request): if request.POST: form = RedirectForm(request.POST, request.FILES) if form.is_valid(): theredirect = form.save() messages.success(request, _("Redirect '{0}' added.").format(theredirect.title), buttons=[ messages.button(reverse('wagtailredirects:edit', args=(theredirect.id,)), _('Edit')) ]) return redirect('wagtailredirects:index') else: messages.error(request, _("The redirect could not be created due to errors.")) else: form = RedirectForm() return render(request, "wagtailredirects/add.html", { 'form': form, })
def edit(request, redirect_id): theredirect = get_object_or_404(models.Redirect, id=redirect_id) if request.POST: form = RedirectForm(request.POST, request.FILES, instance=theredirect) if form.is_valid(): form.save() messages.success(request, _("Redirect '{0}' updated.").format(theredirect.title), buttons=[ messages.button(reverse('wagtailredirects:edit', args=(theredirect.id,)), _('Edit')) ]) return redirect('wagtailredirects:index') else: messages.error(request, _("The redirect could not be saved due to errors.")) else: form = RedirectForm(instance=theredirect) return render(request, "wagtailredirects/edit.html", { 'redirect': theredirect, 'form': form, })
def edit(request, redirect_id): theredirect = get_object_or_404(models.Redirect, id=redirect_id) if request.POST: form = RedirectForm(request.POST, request.FILES, instance=theredirect) if form.is_valid(): form.save() messages.success(request, _("Redirect '{0}' updated.").format(theredirect.title), buttons=[ messages.button(reverse('wagtailredirects:edit', args=(theredirect.id,)), _('Edit')) ]) return redirect('wagtailredirects:index') else: messages.error(request, _("The redirect could not be saved due to errors.")) else: form = RedirectForm(instance=theredirect) return render(request, "wagtailredirects/edit.html", { 'redirect': theredirect, 'form': form, })