converted from fbv to cbv

parent f00356ce
<!DOCTYPE html>
<html lang="en">
<body>
<h1>Assignments:</h1>
{% for assignment in assignments %}
Assignment Name: {{assignment.name}} <br>
Description: {{assignment.description}} <br>
Perfect Score: {{assignment.max_points}} <br>
Passing Score: {{assignment.passing_score}} <br>
Course/Section: {{assignment.course.course_code}} | {{assignment.course.course_title}} | {{assignment.course.section}}
<br><br>
{% endfor %}
</body>
</html>
{% extends "assignments/base.html" %}
{% block content %}
<h3>{{assignment.course.course_code}} | {{assignment.course.course_title}} | {{assignment.course.section}}</h3>
<hr>
<img src= {{assignment.assignment_imageUrl}}>
<h2>{{assignment.name}}</h2>
Description: {{assignment.description}} <br>
Perfect Score: {{assignment.max_points}} <br>
Passing Score: {{assignment.passing_score}} <br>
{% endblock %}
{% extends "assignments/base.html" %}
{% block content %}
<h3>{{object.course.course_code}} | {{object.course.course_title}} | {{object.course.section}}</h3>
<hr>
<img src= {{object.assignment_imageUrl}}>
<h2>{{object.name}}</h2>
Description: {{object.description}} <br>
Perfect Score: {{object.max_points}} <br>
Passing Score: {{object.passing_score}} <br>
{% endblock %}
......@@ -7,7 +7,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="{% static 'assignments/style.css' %}">
<title></title>
<title>{% block title %}Assignments{% endblock %}</title>
</head>
<body>
{% block content %}
......
......@@ -9,7 +9,7 @@
<ul>
{% for assignment in assignments %}
{% if assignment.course.course_code == course.course_code %}
<li><a href ="{% url 'assignment' assignment.id%}">{{assignment.name}}</a></li>
<li><a href ="{% url 'assignment-detail' assignment.id%}">{{assignment.name}}</a></li>
{% endif %}
{% endfor %}
</ul>
......@@ -19,5 +19,6 @@
{% else %}
<p>No courses currently enrolled.</p>
{% endif %}
<h5><a href ="{% url 'assignment-add'%}">Create New Assignment</h5>
{% endblock %}
from django.urls import path
from . import views
from .views import HomePageView, AssignmentDetailView
urlpatterns = [
path('', views.index, name='index'),
path("<int:assignment_id>/details/", views.assignments, name='assignment')
path('', HomePageView.as_view(), name='assignments/index'),
path('assignment/<int:pk>/details/', AssignmentDetailView.as_view(), name='assignment-detail')
]
from django.http import HttpResponse
from . models import Assignment, Course
from django.shortcuts import render
from django.views import View
from django.views.generic.detail import DetailView
# Create your views here.
def index(request):
Assignments = Assignment.objects.all()
Courses = Course.objects.all()
class HomePageView(View):
def get(self, request):
assignments = Assignment.objects.all()
course_list = Course.objects.order_by("course_code")
context ={
'assignments':Assignments,
'courses':Courses,
'assignments':assignments,
'course_list':course_list
}
return render(request, "assignments/view.html", context)
return render(request, "assignments/index.html", context)
def assignments(request, assignment_id):
course_list = Course.objects.order_by("course_code")
try:
assignment = Assignment.objects.get(pk=assignment_id)
except Assignment.DoesNotExist:
raise Http404("Assignment does not exist")
return render(request, "assignments/assignment.html",{"assignment": assignment, 'course_list':course_list})
class AssignmentDetailView(DetailView):
model = Assignment
No preview for this file type
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