Commit eea7aedf authored by Joan Denise Nocos's avatar Joan Denise Nocos

feat: converted index view from function-based (FBV) to class-based (CBV)

parent c2f3028e
from django.urls import path
from . import views
from .views import IndexView
app_name = "assignments"
urlpatterns = [
# assignments/
path('', views.index, name='index'),
path('', IndexView.as_view(), name='index'),
# assignments/<assignment_id>/details/
path('<int:assignment_id>/details/', views.details, name='details'),
# assignments/add/
......
from django.http import HttpResponse, Http404
from django.shortcuts import render
from django.views import View
from assignments.models import Assignment, Course
from assignments.forms import AssignmentForm
# Create your views here.
def index(request):
course_list = Course.objects.order_by("course_code")
assignment_list = Assignment.objects.all()
context = {
"course_list" : course_list,
"assignment_list" : assignment_list,
}
return render(request, "assignments/index.html", context)
class IndexView(View):
def get(self, request):
course_list = Course.objects.order_by("course_code")
assignment_list = Assignment.objects.all()
context = {
"course_list" : course_list,
"assignment_list" : assignment_list,
}
return render(request, "assignments/index.html", context)
def details(request, assignment_id):
try:
......@@ -37,8 +39,21 @@ def newassignment(request):
else:
assignment_form = AssignmentForm()
return render(request, "assignments/newassignment.html", {"assignment_form":assignment_form})
# Code from previous labs:
# Code from Lab 3:
#
# def index(request):
# course_list = Course.objects.order_by("course_code")
# assignment_list = Assignment.objects.all()
# context = {
# "course_list" : course_list,
# "assignment_list" : assignment_list,
# }
# return render(request, "assignments/index.html", context)
# Code from Midterm Project and earlier labs:
#
# def index(request):
# assignments_view = "ASSIGNMENTS: <br>"
......
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