Skip to content

Commit

Permalink
use a fixed success_url for experiment update actions (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbonf authored Sep 27, 2024
1 parent 9f219dd commit 345f4c8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
4 changes: 2 additions & 2 deletions experiments/templates/experiments/detail_parts/info.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ <h3 class="mb-0">
{% trans 'experiments:detail:info' %}
</h3>
<div class="btn-group btn-group-sm">
<a href="{% url 'experiments:update' experiment.pk %}?next={{ request.path }}" class="btn btn-secondary">
<a href="{% url 'experiments:update' experiment.pk %}" class="btn btn-secondary">
{% trans 'experiments:detail:edit_info' %}
</a>
<a href="{% url 'experiments:email_templates' experiment.pk %}?next={{ request.path }}" class="btn btn-secondary">
<a href="{% url 'experiments:email_templates' experiment.pk %}" class="btn btn-secondary">
{% trans 'experiments:detail:edit_emails' %}
</a>
</div>
Expand Down
16 changes: 1 addition & 15 deletions experiments/views/experiment_views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import braces.views as braces
from django.contrib import messages
from django.contrib.auth.views import RedirectURLMixin
from django.contrib.messages.views import SuccessMessageMixin
from django.db.models import Count, F, Q
from django.urls import reverse_lazy as reverse
Expand Down Expand Up @@ -57,24 +56,13 @@ def get_success_url(self):


class ExperimentUpdateView(braces.LoginRequiredMixin,
RedirectURLMixin,
SuccessMessageMixin,
generic.UpdateView):
template_name = 'experiments/edit.html'
form_class = ExperimentForm
model = Experiment
success_message = _('experiments:message:update:success')

def get_success_url(self):
url = reverse('experiments:home')
redirect_to = self.request.GET.get('next', url)

url_is_safe = url_has_allowed_host_and_scheme(
url=redirect_to,
allowed_hosts=self.get_success_url_allowed_hosts(),
require_https=self.request.is_secure(),
)
return redirect_to if url_is_safe else ''
success_url = reverse('experiments:home')


class ExperimentDetailView(braces.LoginRequiredMixin, generic.DetailView):
Expand Down Expand Up @@ -227,7 +215,6 @@ def get_queryset(self):

class ExperimentEmailTemplatesUpdateView(
braces.LoginRequiredMixin,
RedirectURLMixin,
SuccessMessageMixin,
generic.UpdateView
):
Expand All @@ -237,7 +224,6 @@ class ExperimentEmailTemplatesUpdateView(
success_message = _('experiments:message:update_emails:success')
success_url = reverse('experiments:home')


class ConfirmationEmailPreviewView(ExperimentObjectMixin, BaseEmailPreviewView):
email_class = ConfirmationEmail
experiment_kwargs_name = 'pk'
Expand Down

0 comments on commit 345f4c8

Please sign in to comment.