-
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
8f1996c
commit 7bb5e24
Showing
9 changed files
with
201 additions
and
3 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
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 and user == 'daycare' %} | ||
<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 |
---|---|---|
|
@@ -52,3 +52,55 @@ def test_dog_owner_id_is_deleted_when_dog_owner_is_deleted(self, create_order): | |
def test_daycare_id_is_deleted_when_daycare_is_deleted(self, create_order): | ||
DayCare.objects.get(id=1).delete() | ||
assert Order.objects.get(id=create_order.id).daycare_id is None | ||
|
||
@pytest.mark.parametrize("dog_owner_1_id, dog_owner_2_id, delta_1, delta_2, capacity, expected_result", | ||
[(1, 2, 3, 5, 1, False), | ||
(2, 5, 4, 3, 10, True), | ||
(5, 4, 6, 7, 15, True), | ||
(4, 3, 4, 2, 1, False)]) | ||
def test_order_is_approvable_according_to_daycare_capacity(self, dog_owner_1_id, dog_owner_2_id, delta_1, delta_2, | ||
capacity, expected_result): | ||
daycare = DayCare.create("[email protected]", "CapacityUserName", "CapacityPassword", "CapacityName", | ||
"Changeable capacity", 100, capacity, "Merkaz", "Tel Aviv", "Capacity 123") | ||
dog_owner_1 = DogOwner.objects.get(id=dog_owner_1_id) | ||
dog_owner_2 = DogOwner.objects.get(id=dog_owner_2_id) | ||
|
||
order1 = Order.create(start_date=timezone.now(), end_date=timezone.now() + datetime.timedelta(days=delta_1), | ||
daycare_id=daycare, dog_owner_id=dog_owner_1, price_per_day=100) | ||
order2 = Order.create(start_date=timezone.now(), end_date=timezone.now() + datetime.timedelta(days=delta_2), | ||
daycare_id=daycare, dog_owner_id=dog_owner_2, price_per_day=100) | ||
|
||
order1.approve_order() | ||
assert order2.is_the_order_approvable() == expected_result | ||
|
||
@pytest.mark.parametrize("new_status, expected_result", [(StatusOptions.Pending, True), | ||
(StatusOptions.Canceled, False), | ||
(StatusOptions.Approved, True), | ||
(StatusOptions.OnGoing, False), | ||
(StatusOptions.Finished, False)]) | ||
def test_order_cancellation_according_to_order_status(self, create_order, new_status, expected_result): | ||
create_order.status = new_status | ||
assert create_order.is_the_order_cancelable() == expected_result | ||
|
||
@pytest.mark.parametrize("new_status, expected_result", [(StatusOptions.Pending, "Pending"), | ||
(StatusOptions.Canceled, "Canceled"), | ||
(StatusOptions.Approved, "Approved"), | ||
(StatusOptions.OnGoing, "Ongoing"), | ||
(StatusOptions.Finished, "Finished")]) | ||
def test_get_order_status_as_string(self, create_order, new_status, expected_result): | ||
create_order.status = new_status | ||
assert create_order.get_order_status() == expected_result | ||
|
||
def test_get_daycare_capacity_in_dates_range(self, create_order): | ||
original_capacity_list = Order.get_capacity_of_daycare_in_dates_range(create_order.daycare_id, | ||
create_order.start_date, | ||
create_order.end_date) | ||
create_order.approve_order() | ||
updated_capacity_list = Order.get_capacity_of_daycare_in_dates_range(create_order.daycare_id, | ||
create_order.start_date, | ||
create_order.end_date) | ||
assert len(original_capacity_list) == len(updated_capacity_list) | ||
|
||
equality_list = [updated_capacity_list[i] == original_capacity_list[i] + 1 | ||
for i in range(len(original_capacity_list))] | ||
assert equality_list.count(True) == len(equality_list) |
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; | ||
} |