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 @@ ...@@ -7,7 +7,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="{% static 'assignments/style.css' %}"> <link rel="stylesheet" type="text/css" href="{% static 'assignments/style.css' %}">
<title></title> <title>{% block title %}Assignments{% endblock %}</title>
</head> </head>
<body> <body>
{% block content %} {% block content %}
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<ul> <ul>
{% for assignment in assignments %} {% for assignment in assignments %}
{% if assignment.course.course_code == course.course_code %} {% 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 %} {% endif %}
{% endfor %} {% endfor %}
</ul> </ul>
...@@ -19,5 +19,6 @@ ...@@ -19,5 +19,6 @@
{% else %} {% else %}
<p>No courses currently enrolled.</p> <p>No courses currently enrolled.</p>
{% endif %} {% endif %}
<h5><a href ="{% url 'assignment-add'%}">Create New Assignment</h5>
{% endblock %} {% endblock %}
from django.urls import path from django.urls import path
from . import views from .views import HomePageView, AssignmentDetailView
urlpatterns = [ urlpatterns = [
path('', views.index, name='index'), path('', HomePageView.as_view(), name='assignments/index'),
path("<int:assignment_id>/details/", views.assignments, name='assignment') path('assignment/<int:pk>/details/', AssignmentDetailView.as_view(), name='assignment-detail')
] ]
from django.http import HttpResponse from django.http import HttpResponse
from . models import Assignment, Course from . models import Assignment, Course
from django.shortcuts import render from django.shortcuts import render
from django.views import View
from django.views.generic.detail import DetailView
# Create your views here. # Create your views here.
def index(request): class HomePageView(View):
Assignments = Assignment.objects.all() def get(self, request):
Courses = Course.objects.all() assignments = Assignment.objects.all()
course_list = Course.objects.order_by("course_code") course_list = Course.objects.order_by("course_code")
context ={ context ={
'assignments':Assignments, 'assignments':assignments,
'courses':Courses, 'course_list':course_list
'course_list':course_list }
} return render(request, "assignments/index.html", context)
return render(request, "assignments/view.html", context)
def assignments(request, assignment_id): class AssignmentDetailView(DetailView):
course_list = Course.objects.order_by("course_code") model = Assignment
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})
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