Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions SearchHistory/templates/html/search.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<!DOCTYPE html>
<html>
{% extends 'account/profile.html' %}
{% load static %}

{% block stylesheets %}
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="{% static 'css/search.css' %}">
{% block head_content2 %}
<!--Add stylesheets dynamically-->
<link rel="stylesheet" type="text/css" href="{% static 'css/search_page.css' %}">
<link href=https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/css/bootstrap.min.css rel="stylesheet"
integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
<script src=https://kit.fontawesome.com/297bbe7878.js crossorigin="anonymous"></script>
{% endblock %}

{% block content %}
{% block center-content %}
<div class="container">
<div class="filters">
<label class="head-line-label" for="filters">Please search professional by one or more from the following
Expand All @@ -30,7 +31,6 @@
<div class="filter-box">
<input type="text" name="city" class="city" placeholder="City" />
</div>
<input type="hidden" name="opened" value="{{0}}">
<button class="search-btn" type="submit">Search</button>
</form>
</div>
Expand All @@ -44,14 +44,13 @@
<p>First name: {{ professional.profile_id.user_id.first_name }}</p>
<p>Last name: {{ professional.profile_id.user_id.last_name }}</p>
<p>City: {{ professional.profile_id.city }}</p>
<form method="post">
<form method="post" action="{% url 'show professional' professional_id=professional.professional_id %}">
{% csrf_token %}
<input type="hidden" name="search_results_professional_id" value="{{ professional.professional_id }}">
<input type="hidden" name="profession" value="{{ professional.profession }}">
<input type="hidden" name="first_name" value="{{ professional.profile_id.user_id.first_name }}">
<input type="hidden" name="last_name" value="{{ professional.profile_id.user_id.last_name }}">
<input type="hidden" name="city" value="{{ professional.profile_id.city }}">
<input type="hidden" name="opened" value="{{1}}">
<button class="search-btn" type="submit">Open</button>
</form>
</div>
Expand All @@ -75,4 +74,3 @@
</div>
</div>
{% endblock %}
</html>
26 changes: 24 additions & 2 deletions SearchHistory/test_search_page.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from account.models.professional import Professional
from reservation.models import TypeOfJob
from django.urls import reverse
import pytest

Expand Down Expand Up @@ -27,8 +28,7 @@ def test_search_by_professional_id(client, make_professional):
professional = make_professional()
url = reverse('search history', args=[CLIENT_ID])
data = {
'professional_id': professional.professional_id,
'opened': '0',
'professional_id': professional.professional_id
}
response = client.post(url, data)

Expand All @@ -42,3 +42,25 @@ def test_search_by_professional_id(client, make_professional):
assert professionals[0].profile_id.user_id.first_name == professional.profile_id.user_id.first_name
assert professionals[0].profile_id.user_id.last_name == professional.profile_id.user_id.last_name
assert professionals[0].profile_id.city == professional.profile_id.city


@pytest.mark.django_db
def test_redirection_to_professional_page(client, make_professional):
professional = make_professional()
typeOfjobs_by_pro = TypeOfJob.get_typeofjobs_by_professional(professional_id=professional.professional_id)
client.force_login(professional.profile_id.user_id)
url = reverse('show professional', kwargs={'professional_id': professional.professional_id})
data = {
'professional': professional, 'typeOfjobs_by_pro': typeOfjobs_by_pro
}

response = client.post(url, data)

assert response.status_code == 200
assert 'account/business_page.html' in [template.name for template in response.templates]
returned_professional = response.context.get("professional")
assert returned_professional == professional
assert f"{professional.get_profession_display()}" in response.content.decode('utf-8')
assert f"{professional.description}" in response.content.decode('utf-8')
assert f"{professional.profile_id.user_id.first_name}" in response.content.decode('utf-8')
assert f"{professional.profile_id.user_id.last_name}" in response.content.decode('utf-8')
6 changes: 3 additions & 3 deletions SearchHistory/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from django.urls import path
from . import views
from account.views.profile_views import show_business_page


urlpatterns = [
path('search/<int:user_id>/', views.search, name='search history')
# path('create_search_history/', views.create_search_history, name='create_search_history')

path('search/<int:user_id>/', views.search, name='search history'),
path('profile/professional/<int:professional_id>/', show_business_page, name='show professional')
]
44 changes: 15 additions & 29 deletions SearchHistory/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.shortcuts import render
from account.models.professional import Professional
from account.models.client import Client
from django.db.models import Q
from SearchHistory.models import SearchHistory

Expand All @@ -19,36 +18,23 @@ def search(request, user_id):
return render(request, 'html/search.html', context=context)

elif request.method == 'POST':
if request.POST.get("opened", "") == '0':

professionals = Professional.objects.all()

professional_id = request.POST.get("professional_id", "")
profession = request.POST.get("profession", "")
first_name = request.POST.get("first_name", "")
last_name = request.POST.get("last_name", "")
city = request.POST.get("city", "")

professionals = professionals.filter(
Q(professional_id=professional_id) if professional_id else Q(),
Q(profession=profession) if profession else Q(),
Q(profile_id__user_id__first_name=first_name) if first_name else Q(),
Q(profile_id__user_id__last_name=last_name) if last_name else Q(),
Q(profile_id__city=city) if city else Q()
)

if not professionals.exists():
professionals = []

professionals = Professional.objects.all()
professional_id = request.POST.get("professional_id", "")
profession = request.POST.get("profession", "")
first_name = request.POST.get("first_name", "")
last_name = request.POST.get("last_name", "")
city = request.POST.get("city", "")
professionals = professionals.filter(
Q(professional_id=professional_id) if professional_id else Q(),
Q(profession=profession) if profession else Q(),
Q(profile_id__user_id__first_name=first_name) if first_name else Q(),
Q(profile_id__user_id__last_name=last_name) if last_name else Q(),
Q(profile_id__city=city) if city else Q()
)
if not professionals.exists():
professionals = []
context = {
'professionals': professionals,
'last_searches': last_searches,
}

if request.POST.get("opened", "") == '1':
professional_id = request.POST.get("search_results_professional_id", "")
professional = Professional.filter_by_professional_id(professional_id)
client = Client.filter_by_client_id(user_id)
SearchHistory.create_new_search_history(client[0], professional[0])

return render(request, 'html/search.html', context=context)
156 changes: 0 additions & 156 deletions static/css/search.css

This file was deleted.

Loading