-
Notifications
You must be signed in to change notification settings - Fork 834
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
Solution #873
base: master
Are you sure you want to change the base?
Solution #873
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,5 +1,6 @@ | ||
from django.contrib.auth.decorators import login_required | ||
from django.shortcuts import render | ||
from django.urls import reverse_lazy | ||
from django.views import generic | ||
from django.contrib.auth.mixins import LoginRequiredMixin | ||
|
||
|
@@ -34,6 +35,26 @@ class ManufacturerListView(LoginRequiredMixin, generic.ListView): | |
paginate_by = 5 | ||
|
||
|
||
class ManufacturerCreateView(LoginRequiredMixin, generic.CreateView): | ||
model = Manufacturer | ||
fields = ["name", "country"] | ||
success_url = reverse_lazy("taxi:manufacturer-list") | ||
template_name = "taxi/manufacturer_list_form.html" | ||
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. The template name 'taxi/manufacturer_list_form.html' used in 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. The template name |
||
|
||
|
||
class ManufacturerUpdateView(LoginRequiredMixin, generic.UpdateView): | ||
model = Manufacturer | ||
fields = ["name", "country"] | ||
success_url = reverse_lazy("taxi:manufacturer-list") | ||
template_name = "taxi/manufacturer_list_form.html" | ||
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. The template name 'taxi/manufacturer_list_form.html' used in 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. The template name |
||
|
||
|
||
class ManufacturerDeleteView(LoginRequiredMixin, generic.DeleteView): | ||
model = Manufacturer | ||
template_name = "taxi/manufacturer_confirm_delete.html" | ||
success_url = reverse_lazy("taxi:manufacturer-list") | ||
|
||
|
||
class CarListView(LoginRequiredMixin, generic.ListView): | ||
model = Car | ||
paginate_by = 5 | ||
|
@@ -44,6 +65,26 @@ class CarDetailView(LoginRequiredMixin, generic.DetailView): | |
model = Car | ||
|
||
|
||
class CarCreateView(LoginRequiredMixin, generic.CreateView): | ||
model = Car | ||
fields = ["model", "manufacturer", "drivers"] | ||
success_url = reverse_lazy("taxi:car-list") | ||
template_name = "taxi/car_list_form.html" | ||
|
||
|
||
class CarUpdateView(LoginRequiredMixin, generic.UpdateView): | ||
model = Car | ||
fields = ["model", "manufacturer", "drivers"] | ||
success_url = reverse_lazy("taxi:car-list") | ||
template_name = "taxi/car_list_form.html" | ||
|
||
|
||
class CarDeleteView(LoginRequiredMixin, generic.DeleteView): | ||
model = Car | ||
template_name = "taxi/car_confirm_delete.html" | ||
success_url = reverse_lazy("taxi:car-list") | ||
|
||
|
||
class DriverListView(LoginRequiredMixin, generic.ListView): | ||
model = Driver | ||
paginate_by = 5 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{% extends "base.html" %} | ||
{% block content %} | ||
<h1>Confirm deletion</h1> | ||
<p>Are you sure you want to delete {{ car }}?</p> | ||
<form action="" method="post"> | ||
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. The 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. The |
||
{% csrf_token %} | ||
<input type="submit" value="Yes, delete" class="btn btn-danger"> | ||
<a class="btn btn-primary" href="{% url 'taxi:car-detail' pk=car.id %}" role="button">Cancel</a> | ||
</form> | ||
{% endblock %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,28 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<h1>Car list</h1> | ||
<h1>Car List</h1> | ||
{% if car_list %} | ||
<ul> | ||
{% for car in car_list %} | ||
<li> | ||
<a href="{% url "taxi:car-detail" pk=car.id %} ">{{ car.id }}</a> | ||
{{ car.model }} ({{ car.manufacturer.name }}) | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th>ID</th> | ||
<th>Model</th> | ||
<th>Manufacturer</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for car in car_list %} | ||
<tr> | ||
<td>{{ car.id }}</td> | ||
<td><a href="{% url 'taxi:car-detail' pk=car.id %}">{{ car.model }}</a></td> | ||
<td>{{ car.manufacturer.name }}</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
{% else %} | ||
<p>There are no cars in taxi</p> | ||
<p>There are no cars in the taxi system.</p> | ||
{% endif %} | ||
<a href="{% url 'taxi:car-create' %}" class="btn btn-primary">Car creation page</a> | ||
{% endblock %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{% extends "base.html" %} | ||
{% load crispy_forms_filters %} | ||
{% block content %} | ||
<h1>{{ object|yesno:"Update,Create" }} Car</h1> | ||
<form action="" method="post" novalidate> | ||
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. The |
||
{% csrf_token %} | ||
{{ form|crispy }} | ||
<input type="submit" class="btn btn-success" value="Save"> | ||
</form> | ||
{% endblock %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{% extends "base.html" %} | ||
{% block content %} | ||
<h1>Confirm deletion</h1> | ||
<p>Are you sure you want to delete {{ manufacturer }}?</p> | ||
<form action="" method="post"> | ||
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. The 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. The |
||
{% csrf_token %} | ||
<input type="submit" value="Yes, delete" class="btn btn-danger"> | ||
</form> | ||
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. Consider adding a 'Cancel' button to improve user experience by providing an option to abort the deletion process. This can be done by adding a link back to the manufacturer detail or list page. |
||
{% endblock %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,44 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<h1>Manufacturer List | ||
</h1> | ||
<h1>Manufacturer List</h1> | ||
|
||
{% if manufacturer_list %} | ||
<table class="table"> | ||
<tr> | ||
<th>ID</th> | ||
<th>Name</th> | ||
<th>Country</th> | ||
</tr> | ||
|
||
{% for manufacturer in manufacturer_list %} | ||
<thead> | ||
<tr> | ||
<th>ID</th> | ||
<th>Name</th> | ||
<th>Country</th> | ||
<th>Update</th> | ||
<th>Delete</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for manufacturer in manufacturer_list %} | ||
<tr> | ||
<td>{{ manufacturer.id }}</td> | ||
<td>{{ manufacturer.name }}</td> | ||
<td>{{ manufacturer.country }}</td> | ||
<td> | ||
{{ manufacturer.id }} | ||
</td> | ||
<td> | ||
{{ manufacturer.name }} | ||
<a href="{% url 'taxi:manufacturer-update' pk=manufacturer.id %}" class="btn btn-warning btn-sm"> | ||
Update | ||
</a> | ||
</td> | ||
<td> | ||
{{ manufacturer.country }} | ||
<a href="{% url 'taxi:manufacturer-delete' pk=manufacturer.id %}" class="btn btn-danger btn-sm"> | ||
Delete | ||
</a> | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
|
||
{% else %} | ||
<p>There are no manufacturers in the service.</p> | ||
<p>There are no manufacturers in the service.</p> | ||
{% endif %} | ||
|
||
<a href="{% url 'taxi:manufacturer-create' %}" class="btn btn-primary"> | ||
Manufacturer creation page | ||
</a> | ||
{% endblock %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{% extends "base.html" %} | ||
{% load crispy_forms_filters %} | ||
{% block content %} | ||
<h1>{{ object|yesno:"Update,Create" }} Manufacturer</h1> | ||
<form action="" method="post" novalidate> | ||
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. The |
||
{% csrf_token %} | ||
{{ form|crispy }} | ||
<input type="submit" class="btn btn-success" value="Save"> | ||
</form> | ||
{% endblock %} |
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.
The URL pattern for updating a manufacturer is missing a trailing slash. It should be 'manufacturers/int:pk/update/' to ensure consistency in URL handling.