feat: Do not show subscribe button when not yetsearched
This commit is contained in:
parent
280eb83056
commit
bae4ee3d22
@ -12,9 +12,11 @@
|
||||
<button class="btn" type="submit" value="search" name="search">
|
||||
<i class="fas fa-search"></i> {% trans 'Suchen' %}
|
||||
</button>
|
||||
{% if searched %}
|
||||
<button class="btn" type="submit" name="subscribe_to_search">
|
||||
<i class="fas fa-bell"></i> {% trans 'Suche abonnieren' %}
|
||||
</button>
|
||||
{% endif %}
|
||||
</form>
|
||||
{% if place_not_found %}
|
||||
<p class="error">{% translate "Ort nicht gefunden" %}</p>
|
||||
|
@ -171,17 +171,24 @@ def animal_detail(request, animal_id):
|
||||
|
||||
|
||||
def search(request):
|
||||
# A user just visiting the search site did not search, only upon completing the search form a user has really
|
||||
# searched. This will toggle the "subscribe" button
|
||||
searched = False
|
||||
search = Search()
|
||||
search.search_from_request(request)
|
||||
if request.method == 'POST':
|
||||
searched = True
|
||||
if "subscribe_to_search" in request.POST:
|
||||
# Make sure user is logged in
|
||||
if not request.user.is_authenticated:
|
||||
return redirect(f"{settings.LOGIN_URL}?next={request.path}")
|
||||
search.subscribe(request.user)
|
||||
|
||||
context = {"adoption_notices": search.get_adoption_notices(), "search_form": search.search_form,
|
||||
"place_not_found": search.place_not_found}
|
||||
context = {"adoption_notices": search.get_adoption_notices(),
|
||||
"search_form": search.search_form,
|
||||
"place_not_found": search.place_not_found,
|
||||
"user_is_subscribed_to_search": search.is_subscribed(request.user),
|
||||
"searched": searched}
|
||||
return render(request, 'fellchensammlung/search.html', context=context)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user