From d762ece35f304b2031406631fd8f20433420c4b1 Mon Sep 17 00:00:00 2001 From: Todd Dembrey <todd.dembrey@torchbox.com> Date: Wed, 16 Jan 2019 12:17:30 +0000 Subject: [PATCH] Vary the 404 based on if the user is logged in and prevent search on apply --- opentech/apply/utils/views.py | 2 ++ .../mailchimp/templates/mailchimp/newsletter_signup.html | 2 +- opentech/public/search/views.py | 6 ++++++ opentech/templates/base.html | 2 +- opentech/urls.py | 9 +-------- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/opentech/apply/utils/views.py b/opentech/apply/utils/views.py index 41a7a01de..79684bd0b 100644 --- a/opentech/apply/utils/views.py +++ b/opentech/apply/utils/views.py @@ -7,6 +7,8 @@ from django.views.generic.edit import ModelFormMixin, ProcessFormView def page_not_found(request, exception=None, template_name='apply/404.html'): + if not request.user.is_authenticated: + template_name='404.html' return defaults.page_not_found(request, exception, template_name) diff --git a/opentech/public/mailchimp/templates/mailchimp/newsletter_signup.html b/opentech/public/mailchimp/templates/mailchimp/newsletter_signup.html index 1bd9984c7..d45a2dfd5 100644 --- a/opentech/public/mailchimp/templates/mailchimp/newsletter_signup.html +++ b/opentech/public/mailchimp/templates/mailchimp/newsletter_signup.html @@ -1,5 +1,5 @@ <h4>Get the latest internet freedom news</h4> -<form class="form" action="{% url "newsletter:subscribe" %}" method="post"> +<form class="form" action="{{ PUBLIC_SITE.root_url }}{% url "newsletter:subscribe" %}" method="post"> <div> {% for field in newsletter_form %} <label for="{{ field.id_for_label }}"{% if field.field.required %} required{% endif %}> diff --git a/opentech/public/search/views.py b/opentech/public/search/views.py index 63031455f..a3aa058ae 100644 --- a/opentech/public/search/views.py +++ b/opentech/public/search/views.py @@ -1,11 +1,17 @@ from django.conf import settings from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator +from django.http import Http404 from django.shortcuts import render from wagtail.core.models import Page from wagtail.search.models import Query +from opentech.public.home.models import HomePage + def search(request): + if request.site != HomePage.objects.first().get_site(): + raise Http404 + search_query = request.GET.get('query', None) page = request.GET.get('page', 1) diff --git a/opentech/templates/base.html b/opentech/templates/base.html index 94e1cd306..0844af725 100644 --- a/opentech/templates/base.html +++ b/opentech/templates/base.html @@ -129,7 +129,7 @@ </div> <div class="header__search"> - <form action="{% url 'search' %}" method="get" role="search" class="form form--header-search-desktop"> + <form action="{{ PUBLIC_SITE.root_url }}{% url 'search' %}" method="get" role="search" class="form form--header-search-desktop"> <button class="button" type="submit" aria-label="Search"> <svg class="icon icon--magnifying-glass icon--search"><use xlink:href="#magnifying-glass"></use></svg> </button> diff --git a/opentech/urls.py b/opentech/urls.py index de6766aa9..e68457576 100644 --- a/opentech/urls.py +++ b/opentech/urls.py @@ -34,6 +34,7 @@ urlpatterns = [ path('documents/', include(wagtaildocs_urls)), path('sitemap.xml', sitemap), path('', include((user_urls, 'users_public'))), + path('', include(public_urls)), path('', include('social_django.urls', namespace='social')), path('tinymce/', include('tinymce.urls')), path('select2/', include('django_select2.urls')), @@ -75,11 +76,3 @@ if settings.DEBUG and settings.DEBUGTOOLBAR: base_urlpatterns = [*urlpatterns] - - -# Add in URLs only available to the public site -# Place before the wagtail urls without mutating the object -urlpatterns.insert( - -1, - *apply_cache_control(path('', include(public_urls))) -) -- GitLab