Modify and add to the Assignments app according to Lab 3

parent 9182b7dc
h1 {
color: purple;
font-weight: bold;
font-family: "Gill Sans", sans-serif;
}
h3 {
color: indigo;
font-family: "Gill Sans", sans-serif;
}
p {
color: red;
font-weight: lighter;
font-family: "Gill Sans", sans-serif;
}
body {
color: black;
background-color: orange;
font-family: "Gill Sans", sans-serif;
}
a {
color: blue;
font-weight: bold;
font-family: "Gill Sans", sans-serif;
}
{% extends "assignments/base.html" %}
{% block content %}
<center><h1>Assignments Per Course</h1></center>
<h3>List of courses:</h3>
{% for course in all_courses %}
<li><b>{{course.course_code}}</b> <i>{{course.course_title}}</i> {{course.section}}</li>
{% for assignment in all_assignments %}
{% if assignment.course.id == course.id %}
<ul><li><a href="{% url 'assignments:details' assignment.id %}">{{assignment.name}}</a></li></ul>
{% endif %}
{% endfor %}
{% endfor %}
{% endblock %}
{% load static %}
<link rel="stylesheet" type="text/css" href="{% static 'assignments/style.css' %}"
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<style>
</style>
<body>
{% block content %}
{% endblock %}
</body>
</html>
{% extends "assignments/base.html" %}
{% block content %}
<li><b>{{assignment.course.course_code}}</b> <i>{{assignment.course.course_title}}</i> {{assignment.course.section}}</li>
<li><b><u>{{assignment.name}}</u></b></li>
<li><b>Description:</b> {{assignment.description}}</li>
<li><b>Perfect score:</b> {{assignment.max_points}}</li>
<li><b>Passing score:</b> {{assignment.passing_score}}</li>
<center>{% load static %} <img src="{% static img %}" style="width:500px;"/></center>
{% endblock %}
from django.urls import path from django.urls import path
from .views import assignments from . import views
urlpatterns = [ urlpatterns = [
path('', assignments, name='assignments') path('', views.assignments, name='assignments'),
path("<int:assignment_id>/details/", views.details, name='details')
] ]
app_name = 'assignments' app_name = 'assignments'
...@@ -9,22 +9,19 @@ def index(request): ...@@ -9,22 +9,19 @@ def index(request):
return HttpResponse("This is the Assignments page!") return HttpResponse("This is the Assignments page!")
def assignments(request): def assignments(request):
all_assignments = models.Assignment.objects.all() all_assignments = models.Assignment.objects.order_by("name")
all_courses = models.Course.objects.order_by("course_code")
context = {
"all_assignments": all_assignments,
"all_courses": all_courses
}
output = "" return render(request, "assignments/assignments.html", context)
for a in all_assignments: def details(request, assignment_id):
name = a.name assignment = models.Assignment.objects.get(pk=assignment_id)
desc = a.description context = {
pfscore = str(a.max_points) "assignment": assignment,
psscore = str(a.passing_score) "img": "images/" + str(assignment_id) + ".jpg"
ccode = a.course.course_code }
ctitle = a.course.course_title return render(request, "assignments/details.html", context)
csection = a.course.section
record = ("Assignment Name: " + name + "<br>Description: " + desc +
"<br>Perfect Score: " + pfscore + "<br>Passing Score: " + psscore +
"<br>Course/Section: " + ccode + " " + ctitle + " " + csection)
output += record + "<br><br>"
return HttpResponse('<h1>ASSIGNMENTS: </h1>' + output)
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