Refactor search functionality: remove obsolete JavaScript and HTML templates; enhance error handling and response rendering for park search results

This commit is contained in:
pacnpal
2025-02-13 10:29:57 -05:00
parent c197051b25
commit bba707fa98
7 changed files with 164 additions and 173 deletions

View File

@@ -1,72 +0,0 @@
<div class="divide-y">
{% if error %}
<div class="p-8 text-center">
<div class="inline-flex items-center px-4 py-2 rounded-md bg-red-50 text-red-700">
<svg class="w-5 h-5 mr-2" fill="currentColor" viewBox="0 0 20 20">
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd"/>
</svg>
{{ error }}
</div>
</div>
{% else %}
{% for park in object_list %}
<div class="p-4 flex items-start space-x-4">
{% if park.photos.exists %}
<img src="{{ park.photos.first.image.url }}"
alt="{{ park.name }}"
class="w-24 h-24 object-cover rounded-lg">
{% endif %}
<div class="flex-1">
<h3 class="text-lg font-semibold">
<a href="{{ park.get_absolute_url }}">{{ park.name }}</a>
</h3>
<div class="mt-1 text-sm text-gray-500">
{% with location=park.location.first %}
{% if location %}
{{ location.city }}{% if location.state %}, {{ location.state }}{% endif %}{% if location.country %}, {{ location.country }}{% endif %}
{% else %}
Location unknown
{% endif %}
{% endwith %}
</div>
<div class="mt-2 flex flex-wrap gap-2">
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium {{ park.get_status_color }}">
{{ park.get_status_display }}
</span>
{% if park.opening_date %}
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-gray-100 text-gray-800">
Opened {{ park.opening_date|date:"Y" }}
</span>
{% endif %}
{% if park.total_rides %}
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800">
{{ park.total_rides }} rides
</span>
{% endif %}
{% if park.total_coasters %}
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-purple-100 text-purple-800">
{{ park.total_coasters }} coasters
</span>
{% endif %}
{% if park.average_rating %}
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-800">
{{ park.average_rating }} ★
</span>
{% endif %}
</div>
</div>
</div>
{% empty %}
<div class="p-8 text-center text-gray-500">
No parks found matching your criteria
</div>
{% endfor %}
{% endif %}
</div>