-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creating orders.html, presenting orders history
A page on Hotails, where the user can watch the history of all of his orders, cancel the orders which havn't started yet, and approve orders as a daycare. Signed-off-by: Ofir Matasas <[email protected]>
- Loading branch information
1 parent
3a78ab0
commit d36c343
Showing
8 changed files
with
141 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
import pytest | ||
|
||
from daycare.models import DayCare | ||
from dogowner.models import DogOwner | ||
|
||
|
||
@pytest.fixture | ||
def create_dog_owner_user(): | ||
return DogOwner.create(email='[email protected]', | ||
username='dogOwnerUser01', | ||
password='password123', | ||
dog_name='dog name', | ||
first_name='test', | ||
last_name='user', | ||
phone_number=1234567890, | ||
dog_race='dog race', | ||
dog_picture_url='https://www.google.com/user1.jpg', | ||
dog_age=4, | ||
dog_weight=2, | ||
dog_gender='M' | ||
) | ||
return DogOwner.create(email='[email protected]', username='dogOwnerUser01', password='password123', | ||
dog_name='dog name', first_name='test', last_name='user', phone_number=1234567890, | ||
dog_race='dog race', dog_picture_url='https://www.google.com/user1.jpg', dog_age=4, | ||
dog_weight=2, dog_gender='M') | ||
|
||
|
||
@pytest.fixture | ||
def create_daycare_user(): | ||
return DayCare.create(email="[email protected]", username="testuser01", password="pass", | ||
name="Puppies", description="This is the first daycare test", | ||
price_per_day=10, | ||
capacity=50, area="Merkaz", city="Tel-Aviv", address="The best street 5") | ||
|
||
|
||
@pytest.mark.django_db | ||
|
@@ -87,3 +88,21 @@ def test_unlogged_user_access_to_homepage(self, client): | |
response = client.get("/homepage/") | ||
assert response.status_code == 302 | ||
assert response['Location'] == '/login/?next=/homepage/' | ||
|
||
|
||
@pytest.mark.django_db | ||
class TestOrdersView: | ||
def test_unlogged_user_access_to_orders(self, client): | ||
response = client.get("/orders/") | ||
assert response.status_code == 302 | ||
assert response['Location'] == '/login/?next=/orders/' | ||
|
||
def test_orders_page_is_visible_for_dog_owner_user(self, client, create_dog_owner_user): | ||
client.force_login(user=create_dog_owner_user.user) | ||
response = client.get("/orders/") | ||
assert response.status_code == 200 | ||
|
||
def test_orders_page_is_visible_for_daycare_user(self, client, create_daycare_user): | ||
client.force_login(user=create_daycare_user.user) | ||
response = client.get("/orders/") | ||
assert response.status_code == 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{% extends "main/base_template.html" %} | ||
{% load static %} | ||
|
||
{% block stylesheets %} | ||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"> | ||
<link rel="stylesheet" type="text/css" href="{% static 'css/orders.css' %}"> | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<div class="container"> | ||
<div class="row"> | ||
<div class="col-12"> | ||
<table class="table table-bordered"> | ||
<thead> | ||
<tr> | ||
<th scope="col">Name</th> | ||
<th scope="col">Book Date</th> | ||
<th scope="col">Start Date</th> | ||
<th scope="col">End Date</th> | ||
<th scope="col">Status</th> | ||
<th scope="col">Actions</th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
{% for order in orders %} | ||
<tr> | ||
<th scope="row"> | ||
{% if user == 'daycare' %} | ||
{{order.dog_owner_id.name }} | ||
{% else %} | ||
{{order.daycare_id.name }} | ||
{% endif %} | ||
</th> | ||
<td>{{order.book_date}}</td> | ||
<td>{{order.start_date}}</td> | ||
<td>{{order.end_date}}</td> | ||
<td>{{order.get_order_status}}</td> | ||
<td> | ||
{% if order.is_the_order_approvable %} | ||
<button type="button" class="btn btn-success">Approve</button> | ||
{% endif %} | ||
{% if order.is_the_order_cancelable %} | ||
<button type="button" class="btn btn-danger">Cancel</button> | ||
{% endif %} | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
# from django.shortcuts import render | ||
from django.contrib.auth.decorators import login_required | ||
from django.shortcuts import render | ||
|
||
# Create your views here. | ||
from dogowner.models import DogOwner | ||
from orders.models import Order | ||
|
||
|
||
@login_required() | ||
def orders(request): | ||
if DogOwner.objects.filter(user=request.user).exists(): | ||
user = 'dog_owner' | ||
else: | ||
user = 'daycare' | ||
|
||
context = { | ||
'orders': Order.objects.all(), | ||
'user': user, | ||
} | ||
return render(request, 'orders/orders.html', context) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
td, th | ||
{ | ||
text-align: center; | ||
} | ||
|
||
.container { | ||
padding: 2rem 0; | ||
} |