diff --git a/Hotails/settings.py b/Hotails/settings.py
index c993bec..4e1232c 100644
--- a/Hotails/settings.py
+++ b/Hotails/settings.py
@@ -67,6 +67,7 @@
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
+ 'main.context_processors.navbar_extras'
],
},
},
diff --git a/daycare/test_image.py b/daycare/test_image.py
index 742e95f..12efe7f 100644
--- a/daycare/test_image.py
+++ b/daycare/test_image.py
@@ -1,6 +1,5 @@
import pytest
-from .models import DayCare
-from .models import Image
+from .models import DayCare, Image
from django.core.exceptions import ValidationError
DEFAULT_DAYCARE_PROFILE_URL = "../../static/images/daycare-default-profile-image.jpeg"
@@ -25,9 +24,10 @@ def test_image_creation_with_invalid_image_url(self, create_daycare_user):
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 != "../../static/images/daycare-default-profile-image.jpeg"
assert daycare_profile_image is not None
- def test_daycare_has_default_profile_image_when_no_customized_picture_was_found(self, create_daycare_user):
+ 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 == "../../static/images/daycare-default-profile-image.jpeg"
+ assert daycare_profile_image is not None
diff --git a/dogowner/models.py b/dogowner/models.py
index 562fbe0..e1bb197 100644
--- a/dogowner/models.py
+++ b/dogowner/models.py
@@ -32,7 +32,6 @@ def create(email, username, password, dog_name,
first_name, last_name, phone_number,
dog_race, dog_picture_url, dog_age,
dog_weight, dog_gender):
-
ValidateDogOwner(email, username, password, dog_name,
first_name, last_name, phone_number,
dog_race, dog_picture_url, dog_age,
@@ -56,3 +55,8 @@ def create(email, username, password, dog_name,
new_dog_owner.user.save()
new_dog_owner.save()
return new_dog_owner
+
+ def get_dog_owner_profile_image_url(self):
+ if self.dog_picture_url is not None:
+ return self.dog_picture_url
+ return "../../static/images/dog-owner-default-profile-picture.jpeg"
diff --git a/dogowner/test_dog_owner.py b/dogowner/test_dog_owner.py
index 97dba7d..a057b6f 100644
--- a/dogowner/test_dog_owner.py
+++ b/dogowner/test_dog_owner.py
@@ -163,3 +163,14 @@ def test_dog_owner_user_creation_with_url_not_an_image(self):
dog_picture_url="https://www.not/an/image.com",
dog_age=10, dog_weight=6, dog_gender='M'
)
+
+ def test_dogowner_has_customized_profile_image(self, create_dog_owner_user):
+ dogowner_profile_image = create_dog_owner_user.get_dog_owner_profile_image_url()
+ assert dogowner_profile_image != "../../static/images/dog-owner-default-profile-picture.jpeg"
+ assert dogowner_profile_image is not None
+
+ def test_dogowner_has_default_profile_image(self, create_dog_owner_user):
+ create_dog_owner_user.dog_picture_url = None
+ dogowner_profile_image = create_dog_owner_user.get_dog_owner_profile_image_url()
+ assert dogowner_profile_image == "../../static/images/dog-owner-default-profile-picture.jpeg"
+ assert dogowner_profile_image is not None
diff --git a/main/context_processors.py b/main/context_processors.py
new file mode 100644
index 0000000..5517e6a
--- /dev/null
+++ b/main/context_processors.py
@@ -0,0 +1,21 @@
+from daycare.models import DayCare
+from dogowner.models import DogOwner
+
+
+def navbar_extras(request):
+ navbar_picture_url = navbar_name = None
+ if request.user.is_authenticated:
+ if DogOwner.objects.filter(user=request.user).exists():
+ dog_owner = DogOwner.objects.filter(user=request.user).first()
+ navbar_name = dog_owner.__str__()
+ navbar_picture_url = dog_owner.get_dog_owner_profile_image_url()
+ elif DayCare.objects.filter(user=request.user).exists():
+ daycare = DayCare.objects.filter(user=request.user).first()
+ navbar_name = daycare.name
+ navbar_picture_url = daycare.get_daycare_primary_image_url()
+
+ context = {
+ 'navbar_picture_url': navbar_picture_url,
+ 'navbar_name': navbar_name,
+ }
+ return context
diff --git a/main/templates/main/base_template.html b/main/templates/main/base_template.html
index b045033..a0a0b48 100644
--- a/main/templates/main/base_template.html
+++ b/main/templates/main/base_template.html
@@ -12,36 +12,43 @@
+
{% block stylesheets %}
{% endblock %}