-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding user's info to the navbar #77
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
import pytest | ||
from .models import DayCare | ||
from .models import Image | ||
from django.core.exceptions import ValidationError | ||
|
||
DEFAULT_DAYCARE_PROFILE_URL = "../../static/images/daycare-default-profile-image.jpeg" | ||
from conftest import DAYCARE_FIXTURE_PROFILE_PICTURE_URL_1 | ||
from .models import DayCare, Image, DAYCARE_DEFAULT_PICTURE_URL | ||
from django.core.exceptions import ValidationError | ||
|
||
|
||
OfirMatasas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@pytest.mark.django_db() | ||
|
@@ -23,11 +22,11 @@ def test_image_creation_with_invalid_image_url(self, create_daycare_user): | |
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): | ||
def test_daycare_has_customized_profile_image(self, create_image1, create_image2, create_daycare_user: DayCare): | ||
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 | ||
assert daycare_profile_image != DAYCARE_DEFAULT_PICTURE_URL | ||
assert daycare_profile_image == DAYCARE_FIXTURE_PROFILE_PICTURE_URL_1 | ||
Comment on lines
+27
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think its enough to assert on |
||
|
||
def test_daycare_has_default_profile_image_when_no_customized_picture_was_found(self, create_daycare_user): | ||
def test_daycare_has_default_profile_image_when_no_customized_picture_was_found(self, create_daycare_user: DayCare): | ||
daycare_profile_image = create_daycare_user.get_daycare_primary_image_url() | ||
assert daycare_profile_image == DEFAULT_DAYCARE_PROFILE_URL | ||
assert daycare_profile_image == DAYCARE_DEFAULT_PICTURE_URL |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,9 @@ | |
from .validators import ValidateDogOwner, MaxLength | ||
|
||
|
||
DOG_OWNER_DEFAULT_PROFILE_PICTURE_URL = "../../static/images/dog-owner-default-profile-picture.jpeg" | ||
|
||
|
||
class Gender(models.TextChoices): | ||
Male = 'M', 'Male' | ||
Female = 'F', 'Female' | ||
|
@@ -32,7 +35,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 +58,6 @@ 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): | ||
return self.dog_picture_url if self.dog_picture_url else DOG_OWNER_DEFAULT_PROFILE_PICTURE_URL | ||
Comment on lines
+61
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why isnt this logic part of create()? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from daycare.models import DayCare | ||
from dogowner.models import DogOwner | ||
|
||
|
||
def navbar_extras(request): | ||
OfirMatasas marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is it necessary to filler out the authenticated user from the models? |
||
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() | ||
else: | ||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,36 +12,43 @@ | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" | ||
integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous"> | ||
<link rel="stylesheet" href="{% static 'css/navbar.css' %}"> | ||
{% block stylesheets %} | ||
{% endblock %} | ||
</head> | ||
<header> | ||
<nav class="navbar navbar-expand-lg navbar-light bg-dark"> | ||
<nav class="navbar navbar-expand-lg navbar-light bg-dark" style="padding: 0 10px 0 10px;"> | ||
<a class="navbar-brand" href="..\"> | ||
<img src="..\..\..\static\images\Hotails-logo-smaller.png" style="width:50px; height:50px;" class="d-inline-block align-top" loading="lazy"></a> | ||
<button class="navbar-toggler" type="button" data-target="#navbarText" | ||
aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation"> | ||
</button> | ||
<ul class="navbar-nav mr-auto"> | ||
{% if request.user.is_authenticated %} | ||
<img src="{% static 'images/Hotails-logo-smaller.png' %}" style="width:50px; height:50px;" class="d-inline-block align-top" loading="lazy"> | ||
</a> | ||
<button class="navbar-toggler" type="button" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation"></button> | ||
<ul class="navbar-nav mr-auto"> | ||
{% if request.user.is_authenticated %} | ||
<li class="nav-item"><a class="nav-link text-white" href="/profile">Profile</a></li> | ||
<li class="nav-item"><a class="nav-link text-white" href="">Orders</a></li> | ||
<li class="nav-item"><a class="nav-link text-white" href="">Search</a></li> | ||
<li class="nav-item"><a class="nav-link text-white" href="">Chats</a></li> | ||
{% endif %} | ||
<li class="nav-item"><a class="nav-link text-white" href="/about">About</a></li> | ||
</ul> | ||
<li class="nav-item"><a class="nav-link text-white" href="">Orders</a></li> | ||
<li class="nav-item"><a class="nav-link text-white" href="">Search</a></li> | ||
<li class="nav-item"><a class="nav-link text-white" href="">Chats</a></li> | ||
{% endif %} | ||
<li class="nav-item"><a class="nav-link text-white" href="/about">About</a></li> | ||
</ul> | ||
{% if request.user.is_authenticated %} | ||
<ul class="nav navbar-nav navbar-right"> | ||
<li class="nav-item"><a class="nav-link text-white" style="font-size:1.3rem" href="/logout">Logout</a></li> | ||
<li class="nav-item"><img src="{{ navbar_picture_url }}" alt="{{ name }} image" class="navbar-profile-img"></li> | ||
<li class="nav-item"> | ||
<span id="welcomeMsg">Welcome, {{ navbar_name }}!</span><a class="nav-link" id="logoutHref" href="/logout">Logout</a> | ||
</li> | ||
</ul> | ||
{% endif %} | ||
</nav> | ||
</header> | ||
|
||
<body> | ||
{% block content %} | ||
{% endblock %} | ||
<div class="row"> | ||
<div class="col-12 col-lg-12"> | ||
{% block content %} | ||
{% endblock %} | ||
</div> | ||
</div> | ||
|
||
</body> | ||
|
||
</html> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,4 +76,25 @@ def test_dog_owner_homepage_is_visible_for_dog_owner(self, client, create_dog_ow | |
client.force_login(user=create_dog_owner_user.user) | ||
response = client.get("/homepage/") | ||
assert response.status_code == 200 | ||
assert list(response.context['daycares']) == list(DayCare.objects.all()) | ||
list_of_daycares_from_response = list(response.context['daycares']) | ||
list_of_all_daycares = list(DayCare.objects.all()) | ||
assert list_of_daycares_from_response == list_of_all_daycares | ||
Comment on lines
+79
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not related to the scope of this PR, right? |
||
|
||
|
||
@pytest.mark.django_db | ||
class TestNavbarView: | ||
def test_navbar_getting_dog_owner_nickname_and_profile_picture(self, client, create_dog_owner_user): | ||
client.force_login(user=create_dog_owner_user.user) | ||
response = client.get("/homepage/") | ||
dog_owner_picture_url = create_dog_owner_user.dog_picture_url | ||
assert response.context['navbar_picture_url'] == dog_owner_picture_url | ||
Comment on lines
+89
to
+90
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would pass variables substitutions in cases like this, and assert the actual value directly instead:
Also, it would make the test look nicer if the |
||
dog_owner_name = create_dog_owner_user.__str__() | ||
assert response.context['navbar_name'] == dog_owner_name | ||
|
||
def test_navbar_getting_daycare_nickname_and_profile_picture(self, client, create_daycare_user): | ||
client.force_login(user=create_daycare_user.user) | ||
response = client.get("/homepage/") | ||
daycare_name = create_daycare_user.name | ||
assert response.context['navbar_name'] == daycare_name | ||
daycare_primary_image_url = create_daycare_user.get_daycare_primary_image_url() | ||
assert response.context['navbar_picture_url'] == daycare_primary_image_url |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
header ul li { | ||
font-size: 1.1rem; | ||
} | ||
|
||
.navbar-profile-img | ||
{ | ||
border-radius: 50%; | ||
height: 2.5rem; | ||
width: 2.5rem; | ||
} | ||
|
||
#welcomeMsg { | ||
padding-left:10px; | ||
padding-bottom:0; | ||
margin-top:5px; | ||
color:#FFF; | ||
float:left; | ||
} | ||
|
||
#logoutHref { | ||
background-color:#1e1e1e; | ||
border-radius:12px; | ||
color:#E19512; | ||
font-weight:bold; | ||
float:right; | ||
padding: 5px 10px 5px 10px; | ||
font-size:1rem; | ||
margin:1px 0 0 20px; | ||
} | ||
OfirMatasas marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this change (and similar changes) to their own commit.