-
Notifications
You must be signed in to change notification settings - Fork 791
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
74effaf
commit 894639f
Showing
13 changed files
with
229 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from django import forms | ||
from .models import Driver, Car | ||
import re | ||
from django.contrib.auth.forms import UserCreationForm | ||
|
||
|
||
class DriverLicenseUpdateForm(forms.ModelForm): | ||
class Meta: | ||
model = Driver | ||
fields = ('license_number',) | ||
|
||
def clean_license_number(self): | ||
license_number = self.cleaned_data.get('license_number') | ||
|
||
if len(license_number) != 8: | ||
raise forms.ValidationError("license_number must have 8 characters") | ||
|
||
if not re.match(r'^[A-Z]{3}\d{5}$', license_number): | ||
raise forms.ValidationError("license_number must begin with 3 Uppercase letters and then 5 digits") | ||
|
||
return license_number | ||
|
||
|
||
class DriverCreationForm(UserCreationForm): | ||
license_number = forms.CharField(max_length=255) | ||
|
||
class Meta: | ||
model = Driver | ||
fields = UserCreationForm.Meta.fields | ||
|
||
def clean_license_number(self): | ||
license_number = self.cleaned_data.get('license_number') | ||
|
||
if len(license_number) != 8: | ||
raise forms.ValidationError("license_number must have 8 characters") | ||
|
||
if not re.match(r'^[A-Z]{3}\d{5}$', license_number): | ||
raise forms.ValidationError("license_number must begin with 3 Uppercase letters and then 5 digits") | ||
|
||
return license_number | ||
|
||
|
||
class CarCreateForm(forms.ModelForm): | ||
drivers = forms.ModelMultipleChoiceField( | ||
queryset=Driver.objects.all(), | ||
widget=forms.CheckboxSelectMultiple, | ||
required=False | ||
) | ||
|
||
class Meta: | ||
model = Car | ||
fields = '__all__' |
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,12 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<h1>Create a New Car</h1> | ||
|
||
<form method="post"> | ||
{% csrf_token %} | ||
{{ form.as_p }} | ||
|
||
<button type="submit">Save</button> | ||
</form> | ||
{% 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,22 +1,39 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<h1> | ||
{{ car.model }} | ||
<a href="{% url 'taxi:car-delete' pk=car.id %}" class="btn btn-danger link-to-page"> | ||
Delete | ||
</a> | ||
|
||
<a href="{% url 'taxi:car-update' pk=car.id %}" class="btn btn-secondary link-to-page"> | ||
Update | ||
</a> | ||
</h1> | ||
<h1> MODEL: {{ car.model }}</h1> | ||
<p>Manufacturer: {{ car.manufacturer.name }}</p> | ||
<p>Year: {{ car.year }}</p> | ||
|
||
<a href="{% url 'taxi:car-update' pk=car.id %}" class="btn btn-secondary">Update</a> | ||
<a href="{% url 'taxi:car-delete' pk=car.id %}" class="btn btn-danger">Delete</a> | ||
|
||
<p>Manufacturer: ({{ car.manufacturer.name }}, {{ car.manufacturer.country }})</p> | ||
<h1>Drivers</h1> | ||
<hr> | ||
<ul> | ||
{% for driver in car.drivers.all %} | ||
<li>{{ driver.username }} ({{ driver.first_name }} {{ driver.last_name }})</li> | ||
{% endfor %} | ||
</ul> | ||
|
||
<h2>Drivers</h2> | ||
<ul class="drivers-list"> | ||
{% for driver in car.drivers.all %} | ||
<li class="driver-item"> | ||
<div><strong>Username:</strong> {{ driver.username }}</div> | ||
<div><strong>First Name:</strong> {{ driver.first_name }}</div> | ||
<div><strong>Last Name:</strong> {{ driver.last_name }}</div> | ||
<div><strong>License:</strong> {{ driver.license_number }}</div> | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
|
||
|
||
{% if user in car.drivers.all %} | ||
<form method="post" action="{% url 'taxi:remove-me-from-car' pk=car.id %}"> | ||
{% csrf_token %} | ||
<button type="submit" class="btn btn-danger">Delete me from this car</button> | ||
</form> | ||
{% else %} | ||
<form method="post" action="{% url 'taxi:assign-me-to-car' pk=car.id %}"> | ||
{% csrf_token %} | ||
<button type="submit" class="btn btn-success">Assign me to this car</button> | ||
</form> | ||
{% endif %} | ||
|
||
{% 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<h1>Are you sure you want to delete {{ driver.name }}?</h1> | ||
<form method="post"> | ||
{% csrf_token %} | ||
<button type="submit" class="btn btn-danger">Confirm Delete</button> | ||
</form> | ||
<a href="{% url 'taxi:driver-detail' driver.pk %}" class="btn btn-secondary">Cancel</a> | ||
{% 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<h1>Create a New DRIVER</h1> | ||
|
||
<form method="post"> | ||
{% csrf_token %} | ||
{{ form.as_p }} | ||
|
||
<button type="submit">Save</button> | ||
</form> | ||
{% 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
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,13 @@ | ||
{% extends 'base.html' %} | ||
|
||
{% block content %} | ||
<h1>Update license</h1> | ||
|
||
<form method="post"> | ||
{% csrf_token %} | ||
{{ form.as_p }} | ||
<button type="submit">Update license</button> | ||
</form> | ||
|
||
<a href="{% url 'driver-list' %}">Back to driver-list</a> | ||
{% 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
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,10 @@ | ||
{% extends 'base.html' %} | ||
|
||
{% block content %} | ||
<h2>Edit Driver Information</h2> | ||
<form method="post"> | ||
{% csrf_token %} | ||
{{ form.as_p }} | ||
<button type="submit" class="btn btn-primary">Save changes</button> | ||
</form> | ||
{% endblock %} |