Skip to content

Commit

Permalink
Done2
Browse files Browse the repository at this point in the history
  • Loading branch information
antonver committed Aug 5, 2024
1 parent 6401706 commit 51acd12
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 25 deletions.
4 changes: 1 addition & 3 deletions taxi/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
CarDetailView,
DriverListView,
DriverDetailView,
ManufacturerListView, login_view, logout_view,
ManufacturerListView
)

urlpatterns = [
Expand All @@ -22,8 +22,6 @@
path(
"drivers/<int:pk>/", DriverDetailView.as_view(), name="driver-detail"
),
path("accounts/login/", login_view, name="login"),
path("accounts/logout/", logout_view, name="logout"),
]

app_name = "taxi"
20 changes: 0 additions & 20 deletions taxi/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,3 @@ class DriverListView(LoginRequiredMixin, generic.ListView):
class DriverDetailView(LoginRequiredMixin, generic.DetailView):
model = Driver
queryset = Driver.objects.prefetch_related("cars__manufacturer")


def login_view(request: HttpRequest) -> HttpResponse:
if request.method == "GET":
form = AuthenticationForm()
return render(request, "registration/login.html", {"form": form})
elif request.method == "POST":
form = AuthenticationForm(data=request.POST)
if form.is_valid():
user = form.get_user()
login(request, user)
return HttpResponseRedirect(reverse("taxi:index"))
else:
return render(request, "registration/login.html", {"form": form})


def logout_view(request) -> HttpResponse:
form = AuthenticationForm()
logout(request)
return render(request, "registration/logged_out.html", {"form": form})
7 changes: 6 additions & 1 deletion taxi_service/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, include
from debug_toolbar.toolbar import debug_toolbar_urls

urlpatterns = [
path("admin/", admin.site.urls),
path("", include("taxi.urls", namespace="taxi")),
path("accounts/", include("django.contrib.auth.urls")),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

if settings.DEBUG:
import debug_toolbar
urlpatterns = [
path('__debug__/', include(debug_toolbar.urls)),
] + urlpatterns
2 changes: 1 addition & 1 deletion templates/registration/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ <h1>Login</h1>
{% if form.errors %}
<p style="color:red">Invalid credentials</p>
{% endif %}
<form action="{% url 'taxi:login' %}" method="post">
<form action="{% url 'login' %}" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit" class="btn btn-primary">
Expand Down

0 comments on commit 51acd12

Please sign in to comment.