Commit 96e37d0e authored by Anya Habana's avatar Anya Habana

Converted index FBV to CBV

parent d02e2cd2
No preview for this file type
......@@ -3,7 +3,7 @@ from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
path('', views.IndexView.as_view(), name='index'),
path('<int:pk>/details/', views.WidgetUserDetailView.as_view(), name='details'),
path('add/', views.newuser, name='newuser'),
]
......
......@@ -2,22 +2,23 @@ from django.shortcuts import render, redirect
from django.http import HttpResponse
from django.template import loader
from django.views.generic.detail import DetailView
from django.views.generic.base import TemplateView
from .models import WidgetUser
from .forms import WidgetUserForm
def index(request):
user_list = WidgetUser.objects.order_by("last_name")
context = {
"user_list": user_list,
}
template = loader.get_template("users/index.html")
return HttpResponse(template.render(context, request))
class IndexView(TemplateView):
template_name = "users/index.html"
def get_context_data(self, **kwargs):
context = super(IndexView, self).get_context_data(**kwargs)
context['user_list'] = WidgetUser.objects.order_by("last_name")
return context
def newuser(request):
if request.method == "POST":
user_form = WidgetUserForm(request.POST)
if user_form.is_valid():
new_user = user_form.save()
user_form.save()
return redirect("homepage:index")
else:
user_form = WidgetUserForm()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment