diff --git a/daycare/models.py b/daycare/models.py index 2678d71..54aa6ea 100644 --- a/daycare/models.py +++ b/daycare/models.py @@ -40,8 +40,7 @@ def create(email, username, password, name, description, price_per_day, capacity validate_max_length(address, 50, "address") validate_price(price_per_day) - new_daycare = DayCare(user=User.objects.create_user(email=email, username=username, password=password, - ), + new_daycare = DayCare(user=User.objects.create_user(email=email, username=username, password=password), name=name, description=description, price_per_day=price_per_day, capacity=capacity, area=area, city=city, address=address) @@ -50,6 +49,12 @@ def create(email, username, password, name, description, price_per_day, capacity return new_daycare + def get_daycare_primary_image_url(self): + daycare_images = Image.get_images_by_daycare_id(daycare_id=self.id) + if daycare_images is not None and daycare_images.first() is not None: + return daycare_images.first().url + return "../../static/images/daycare-default-profile-image.jpeg" + class Image(models.Model): url = models.CharField(max_length=1000) diff --git a/daycare/test_image.py b/daycare/test_image.py index 6058999..b796b4e 100644 --- a/daycare/test_image.py +++ b/daycare/test_image.py @@ -3,6 +3,8 @@ from .models import Image from django.core.exceptions import ValidationError +DEFAULT_DAYCARE_PROFILE_URL = "../../static/images/daycare-default-profile-image.jpeg" + @pytest.mark.django_db() class TestImageModel: @@ -20,3 +22,13 @@ def test_image_creation_with_invalid_image_url(self, create_daycare_user): with pytest.raises(ValidationError, match="Invalid URL image - URL should end with \'.gif\', \'.png\', \'.jpg\' or \'.jpeg\'."): Image.create(url="NOT_VALID_URL", daycare_id=DayCare.objects.get(id=create_daycare_user.id)) + + def test_daycare_has_customized_profile_image(self, create_image1, create_image2, create_daycare_user): + daycare_profile_image = create_daycare_user.get_daycare_primary_image_url() + assert daycare_profile_image != DEFAULT_DAYCARE_PROFILE_URL + assert daycare_profile_image is not None + + def test_daycare_has_default_profile_image(self, create_daycare_user): + daycare_profile_image = create_daycare_user.get_daycare_primary_image_url() + assert daycare_profile_image == DEFAULT_DAYCARE_PROFILE_URL + assert daycare_profile_image is not None diff --git a/dogowner/templates/dogowner/dog_owner_homepage.html b/dogowner/templates/dogowner/dog_owner_homepage.html new file mode 100644 index 0000000..8434a05 --- /dev/null +++ b/dogowner/templates/dogowner/dog_owner_homepage.html @@ -0,0 +1,26 @@ +{% extends "main/base_template.html" %} +{% load static %} + +{% block stylesheets %} + +{% endblock %} + +{% block content %} +