Skip to content

Commit

Permalink
Fix domain being None in opensearch results
Browse files Browse the repository at this point in the history
The domain came from HTTP_HOST which in our nginx configuration is not
set, furthermore other code already uses Site to obtain the domain.

Closes: #541
  • Loading branch information
jelly committed Jan 18, 2025
1 parent 5da7fa8 commit 89caded
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def test_sort(client, package):
def test_packages(client, package):
response = client.get('/opensearch/packages/')
assert response.status_code == 200
assert 'template="example.com/opensearch/packages/"' in response.content.decode()


def test_packages_suggest(client, package):
Expand Down
5 changes: 3 additions & 2 deletions packages/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.contrib import messages
from django.contrib.auth.decorators import permission_required
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.core.cache import cache
from django.db.models import Q
from django.http import HttpResponse, HttpResponseBadRequest
Expand All @@ -21,10 +22,10 @@
@require_safe
@cache_control(public=True, max_age=86400)
def opensearch(request):
domain = "%s://%s" % (request.scheme, request.META.get('HTTP_HOST'))
current_site = Site.objects.get_current()

return render(request, 'packages/opensearch.xml',
{'domain': domain},
{'domain': current_site.domain},
content_type='application/opensearchdescription+xml')


Expand Down
5 changes: 3 additions & 2 deletions public/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from operator import attrgetter

from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.db.models import Count, Q
from django.http import HttpResponse
from django.shortcuts import get_object_or_404, render
Expand All @@ -25,12 +26,12 @@ def updates():
else:
def updates():
return get_recent_updates()
domain = "%s://%s" % (request.scheme, request.META.get('HTTP_HOST'))
current_site = Site.objects.get_current()
context = {
'news_updates': News.objects.order_by('-postdate', '-id')[:15],
'pkg_updates': updates,
'staff_groups': StaffGroup.objects.all(),
'domain': domain,
'domain': current_site.domain,
}
return render(request, 'public/index.html', context)

Expand Down

0 comments on commit 89caded

Please sign in to comment.