Skip to content

Commit

Permalink
update view, template, tests and urls
Browse files Browse the repository at this point in the history
  • Loading branch information
MazOneTwoOne committed Apr 17, 2024
1 parent 0e5b15b commit 82207d9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 34 deletions.
6 changes: 3 additions & 3 deletions fala/apps/adviser/tests/test_search_view_function.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.test import SimpleTestCase, Client, LiveServerTestCase, override_settings
from django.test import SimpleTestCase, Client, override_settings
from django.urls import reverse


Expand All @@ -14,11 +14,11 @@ def test_postcode_search(self):

def test_invalid_postcode_generates_error(self):
response = self.client.get(self.url, {"postcode": "ZZZ"})
self.assertEqual({"postcode": ["Postcode not found"]}, response.context_data["form"].errors)
self.assertContains(response, "Postcode not found")


@override_settings(FEATURE_FLAG_NO_MAP=True)
class NewSearchViewTemplate(LiveServerTestCase):
class NewSearchViewTemplate(SimpleTestCase):
client = Client()

def test_template_link_and_css(self):
Expand Down
48 changes: 22 additions & 26 deletions fala/apps/adviser/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,32 @@
from django.conf import settings
from django.urls import resolve, reverse
from django.views.generic import TemplateView
from django.template import loader
from django.http import HttpResponse

from .forms import AdviserSearchForm


class AdviserView(TemplateView):
# https://docs.djangoproject.com/en/5.0/topics/class-based-views/#usage-in-your-urlconf - this is how `template_name`
if settings.FEATURE_FLAG_NO_MAP:
template_name = "adviser/search.html"
else:
template_name = "adviser/search_old.html"

def get(self, request, *args, **kwargs):
context = self.get_context_data(**kwargs)
form = AdviserSearchForm(data=request.GET or None)
view_name = resolve(request.path_info).url_name
current_url = reverse(view_name)

context.update(
{
"form": form,
"data": form.search(),
"current_url": current_url,
"GOOGLE_MAPS_API_KEY": settings.GOOGLE_MAPS_API_KEY,
"LAALAA_API_HOST": settings.LAALAA_API_HOST,
"CHECK_LEGAL_AID_URL": settings.CHECK_LEGAL_AID_URL,
}
)
class AccessibilityView(TemplateView):
template_name = "adviser/accessibility-statement.html"

return self.render_to_response(context)

def fala_search(request):
form = AdviserSearchForm(data=request.GET or None)
data = form.search()

class AccessibilityView(TemplateView):
template_name = "adviser/accessibility-statement.html"
if settings.FEATURE_FLAG_NO_MAP:
template = loader.get_template("adviser/search.html")
else:
template = loader.get_template("adviser/search_old.html")

view_name = resolve(request.path_info).url_name
current_url = reverse(view_name)
context = {
"form": form,
"data": data,
"current_url": current_url,
"GOOGLE_MAPS_API_KEY": settings.GOOGLE_MAPS_API_KEY,
"CHECK_LEGAL_AID_URL": settings.CHECK_LEGAL_AID_URL,
}
return HttpResponse(template.render(context, request))
3 changes: 0 additions & 3 deletions fala/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,6 @@ def root(*x):

CHECK_LEGAL_AID_URL = "https://www.gov.uk/check-legal-aid"

# We need a default database in order to run a LiveServerTestCase test.
DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3"}}

# .local.py overrides all the common settings.
try:
from .local import * # noqa: F401,F403
Expand Down
4 changes: 2 additions & 2 deletions fala/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from django.conf import settings
from django.conf.urls.static import static
from django.urls import re_path
from fala.apps.adviser.views import AdviserView, AccessibilityView
from fala.apps.adviser.views import AccessibilityView, fala_search
from django.views.static import serve

urlpatterns = [
re_path(r"^accessibility-statement$", AccessibilityView.as_view(), name="accessibility_statement"),
re_path(r"^$", AdviserView.as_view(), name="adviser"),
re_path(r"^$", fala_search, name="adviser"),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

if settings.DEBUG_STATIC:
Expand Down

0 comments on commit 82207d9

Please sign in to comment.