diff --git a/SearchHistory/templates/html/search.html b/SearchHistory/templates/html/search.html index 4083377..57104cc 100644 --- a/SearchHistory/templates/html/search.html +++ b/SearchHistory/templates/html/search.html @@ -1,14 +1,15 @@ - - +{% extends 'account/profile.html' %} {% load static %} -{% block stylesheets %} - - +{% block head_content2 %} + + + + {% endblock %} -{% block content %} +{% block center-content %}
@@ -44,14 +44,13 @@

First name: {{ professional.profile_id.user_id.first_name }}

Last name: {{ professional.profile_id.user_id.last_name }}

City: {{ professional.profile_id.city }}

-
+ {% csrf_token %} -
@@ -75,4 +74,3 @@ {% endblock %} - \ No newline at end of file diff --git a/SearchHistory/test_search_page.py b/SearchHistory/test_search_page.py index 9a48171..8dcc6bd 100644 --- a/SearchHistory/test_search_page.py +++ b/SearchHistory/test_search_page.py @@ -1,4 +1,5 @@ from account.models.professional import Professional +from reservation.models import TypeOfJob from django.urls import reverse import pytest @@ -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) @@ -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') diff --git a/SearchHistory/urls.py b/SearchHistory/urls.py index 9c4b856..4c458e5 100644 --- a/SearchHistory/urls.py +++ b/SearchHistory/urls.py @@ -1,9 +1,9 @@ from django.urls import path from . import views +from account.views.profile_views import show_business_page urlpatterns = [ - path('search//', views.search, name='search history') - # path('create_search_history/', views.create_search_history, name='create_search_history') - + path('search//', views.search, name='search history'), + path('profile/professional//', show_business_page, name='show professional') ] diff --git a/SearchHistory/views.py b/SearchHistory/views.py index eb12afb..e9d0a4b 100644 --- a/SearchHistory/views.py +++ b/SearchHistory/views.py @@ -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 @@ -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) diff --git a/static/css/search.css b/static/css/search.css deleted file mode 100644 index 39f33e6..0000000 --- a/static/css/search.css +++ /dev/null @@ -1,156 +0,0 @@ -body { - background-color: #e0f2f1; - color: #263238; - } - -.container { - display: flex; - flex-direction: row; - justify-content: space-between; - margin: 20px; -} - -.filters { - flex-basis: 30%; - display: flex; - flex-direction: column; - align-items: center; -} - -.search-results { - flex-basis: 65%; -} - -.filter-box { - margin-bottom: 10px; -} - -.filter-label { - display: block; - font-weight: normal; - font-size: 15px; -} - -.head-line-label { - display: block; - font-weight: bold; - font-size: 20px; - margin-bottom: 25px; - text-align: center; -} - -.filter-input { - width: 100%; - padding: 5px; - border-radius: 5px; - border: 1px solid #ccc; - font-size: 16px; -} - -.search-box { - display: flex; - flex-direction: row; - align-items: center; - background-color: #eee; - padding: 10px; - border-radius: 5px; - margin-bottom: 20px; -} - -.search-box input[type="text"] { - flex-grow: 1; - margin-right: 10px; -} - -.search-btn { - background-color: #6976eb; - color: white; - padding: 10px; - border: none; - border-radius: 5px; - cursor: pointer; - font-size: 16px; - margin-top: 12px; -} - -.professional-box { - background-color: #fff; - padding: 10px; - border-radius: 5px; - box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); - transition: box-shadow 0.3s; - cursor: pointer; - text-align: center; -} - -.professional-box:hover { - box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); -} - -.professional-box h3 { - margin-top: 0; - font-size: 24px; -} - -.professional-box p { - margin-top: 5px; - font-size: 16px; - color: #666; -} - -.professional-grid { - display: grid; - grid-template-columns: repeat(2, 1fr); - grid-gap: 20px; -} - -.search-history-grid { - display: grid; - grid-template-columns: 1fr; - grid-gap: 10px; - align-items: center; -} - -.search-history-box { - width: 100%; - margin-bottom: 5px; - background-color: #c5c5da; - padding: 1px; - border-radius: 5px; - box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); - transition: box-shadow 0.3s; - cursor: pointer; - text-align: center; -} - -.search-history-box p { - margin-top: 2px; - font-size: 16px; - color: #666; -} - -.search-history-box h3 { - margin-top: 0; - font-size: 12px; -} - -.search-history-box:hover { - box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); -} - -.search-box { - background-color: #e6e6fa; -} - -.search-btn { - background-color: #009688; -} - -.professional-box { - background-color: #e6e6fa; - box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); -} - -.professional-box:hover { - box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); -} \ No newline at end of file diff --git a/static/css/search_page.css b/static/css/search_page.css new file mode 100644 index 0000000..0beefef --- /dev/null +++ b/static/css/search_page.css @@ -0,0 +1,126 @@ +.container { + max-width: 800px; + margin: 0 auto; + padding: 20px; + display: grid; + grid-template-columns: 1fr 3fr 1fr; + grid-gap: 20px; +} + +.filters { + grid-column: 1; +} + +.filters .head-line-label { + font-weight: bold; + margin-bottom: 10px; +} + +.filter-box { + margin-bottom: 10px; +} + +input[type="number"], +input[type="text"] { + width: 100%; + padding: 8px; + border: 1px solid #ccc; + border-radius: 4px; +} + +.search-btn { + padding: 10px 20px; + background-color: #02080f; + color: #fff; + border: none; + border-radius: 4px; + cursor: pointer; +} + +.search-results { + grid-column: 2; +} + +.search-results .head-line-label { + font-weight: bold; + margin-bottom: 10px; +} + +.professional-grid { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); + + grid-gap: 20px; +} + +.professional-box { + padding: 10px; + border: 1px solid #ccc; + border-radius: 4px; + box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); + transition: box-shadow 0.3s; + cursor: pointer; + text-align: center; +} + +.professional-box:hover { + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); +} + +.professional-box h3 { + margin-top: 0; + font-size: 24px; +} + +.professional-box p { + margin-top: 5px; + font-size: 16px; + color: #666; +} + +.search-history { + grid-column: 3; + } + +.search-history-box { + width: 100%; + margin-bottom: 5px; + padding: 1px; + border-radius: 5px; + box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); + transition: box-shadow 0.3s; + cursor: pointer; + text-align: center; +} + +.search-history-box p { + margin-top: 2px; + font-size: 16px; + color: #666; +} + +.search-history-box h3 { + margin-top: 0; + font-size: 12px; +} + +.search-history-box:hover { + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); +} + +.search-history .head-line-label { + font-weight: bold; + margin-bottom: 10px; +} + +.search-history-grid { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); + grid-gap: 20px; +} + +.search-history-box { + padding: 10px; + border: 1px solid #ccc; + border-radius: 4px; +}