From cdda98186a1f88e6a09ba6053179cd3a90a69811 Mon Sep 17 00:00:00 2001 From: Jenia Sakirko Date: Wed, 27 Apr 2022 00:41:08 +0300 Subject: [PATCH 1/5] Adding Homepage for daycare user The Homepage is the page that a daycare owner who is already connected to the site, or one who arrives after logging in, reaches. This page shows the the full details of the daycare, and in addition shows him all the reviews written about his daycare. Signed-off-by: Erez Cohen --- .../templates/daycare/daycare-homepage.html | 132 ++++++++++++++++++ daycare/test_daycare.py | 26 ++++ daycare/views.py | 16 ++- main/templates/main/base_template.html | 2 +- main/views.py | 9 +- 5 files changed, 179 insertions(+), 6 deletions(-) create mode 100644 daycare/templates/daycare/daycare-homepage.html diff --git a/daycare/templates/daycare/daycare-homepage.html b/daycare/templates/daycare/daycare-homepage.html new file mode 100644 index 0000000..3f6a91b --- /dev/null +++ b/daycare/templates/daycare/daycare-homepage.html @@ -0,0 +1,132 @@ +{% extends "main/base_template.html" %} + +{% block stylesheets %} + + + + + +{% endblock %} + +{% block content %} +
+
+
+
+
+
Hello {{ daycare.name }}
+
This is where you can manage your daycare. +
You will be able:
+

# Manage your booking schedule

+

# Set filters of approved dogs and services you provide

+

# Read / write reviews of dog owners and their dogs

+

# Chat with dog owners

+
+
+
+
Have a look at your reviews
+ + + + + + + + + + + + {% for review in reviews %} + + + + + + + + {% endfor %} + +
#NameDateReviewRating
{{ forloop.counter }}{{ review.dogowner_id }}{{ review.creation_date }}{{ review.review }}{{ review.rating }}
+ +
+
+
+
+ + +
+
+ + +
+
{{daycare.address}}, {{daycare.city}}
+
+
Capacity: {{daycare.capacity}} +
+
+ Price: {{daycare.price_per_day}} +
+
+
About
+

{{daycare.description}}

+
+
+
+
+
+ +
+
+ + {% endblock %} \ No newline at end of file diff --git a/daycare/test_daycare.py b/daycare/test_daycare.py index bd02243..9c23cd9 100644 --- a/daycare/test_daycare.py +++ b/daycare/test_daycare.py @@ -2,6 +2,9 @@ from .models import DayCare from django.core.exceptions import ValidationError from django.contrib.auth.models import User +from .models import Image +import random +from review.models import Review @pytest.mark.django_db() @@ -61,3 +64,26 @@ def test_daycare_user_creation_with_same_user_name(self, create_daycare_user): DayCare.create(username='testUser01', email="valid@gmail.com", password='pass123', name='daycare', description='new description', price_per_day=10, capacity=50, area='north', city='haifa', address='new address') + + def test_daycare_redirected_homepage_after_login(self, client, create_daycare_user): + client.force_login(user=create_daycare_user.user) + response = client.get('/') + assert response.status_code == 302 + assert response['Location'] == '/homepage/' + + def test_relevant_daycare_homepage_with_static_data(self, client, create_daycare_user): + dayCare = random.choice([daycare for daycare in DayCare.objects.all() if 'static' in daycare.user.username]) + client.force_login(user=dayCare.user) + + response = client.get('/homepage/') + + daycare_shown_in_homepage = response.context['daycare'] + assert daycare_shown_in_homepage == dayCare + + images_shown_in_homepage = set(response.context['images']) + daycare_images = set(Image.get_images_by_daycare_id(daycare_id=dayCare.id)) + assert images_shown_in_homepage == daycare_images + + reviews_shown_in_homepage = set(response.context['reviews']) + daycare_reviews = set(Review.get_review_by_daycare_id(daycare_id=dayCare.id)) + assert reviews_shown_in_homepage == daycare_reviews diff --git a/daycare/views.py b/daycare/views.py index fd0e044..1e79271 100644 --- a/daycare/views.py +++ b/daycare/views.py @@ -1,3 +1,15 @@ -# from django.shortcuts import render +from django.shortcuts import render +from django.contrib.auth.decorators import login_required +from .models import Image +from review.models import Review -# Create your views here. + +@login_required(login_url='login') +def daycare_home(request): + context = { + 'daycare': request.user.daycare, + 'reviews': Review.get_review_by_daycare_id(request.user.daycare.id), + 'images': Image.get_images_by_daycare_id(request.user.daycare.id) + } + + return render(request, 'daycare/daycare-homepage.html', context) diff --git a/main/templates/main/base_template.html b/main/templates/main/base_template.html index 63c7685..b045033 100644 --- a/main/templates/main/base_template.html +++ b/main/templates/main/base_template.html @@ -24,7 +24,7 @@