Commit 1cc16eb5 authored by Joan Denise Nocos's avatar Joan Denise Nocos

feat: added index and details templates to assignments app

parent 75ba0626
{% extends "base.html" %}
{% block page-title %}Assignment {{ assignment_id }} Details{% endblock %}
{% block content %}
<h1>{{ course.course_code }} {{ course.course_title }} {{ course.section }}</h1>
<p>{{ assignment.name }}</p>
<p>{{ assignment.description }}</p>
<p>{{ assignment.max_points }}</p>
<p>{{ assignment.passing_score }}</p>
<p>Image Placeholder</p>
{% endblock %}
\ No newline at end of file
{% extends "base.html" %}
{% block page-title %}Assignments{% endblock %}
{% block content %}
<h1>Assignments Per Course</h1>
<h2>List of Courses:</h2>
{% if course_list %}
<ul>
{% for course in course_list %}
<p>{{ course.course_code }} {{ course.course_title }} {{ course.section }}</p>
<ul>
{% for assignment in assignment_list %}
{% if assignment.course == course.id %}
<li><a href="{% url 'assignments:details' assignment.id %}">{{ assignment.name }}</a></li>
{% endif %}
{% endfor %}
</ul>
{% endfor %}
</ul>
{% else %}
<p>No course available.</p>
{% endif %}
{% endblock %}
...@@ -2,6 +2,7 @@ from django.urls import path ...@@ -2,6 +2,7 @@ from django.urls import path
from . import views from . import views
app_name = "assignments"
urlpatterns = [ urlpatterns = [
# assignments/ # assignments/
path('', views.index, name='index'), path('', views.index, name='index'),
......
from django.http import HttpResponse from django.http import HttpResponse, Http404
from django.shortcuts import render
from assignments.models import Assignment, Course from assignments.models import Assignment, Course
# Create your views here. # Create your views here.
def index(request): def index(request):
assignments_view = "ASSIGNMENTS: <br>" course_list = Course.objects.order_by("course_code")
schoolwork = Assignment.objects.all() assignment_list = Assignment.objects.all()
for assignment in schoolwork: context = {
score = assignment.max_points "course_list" : course_list,
assignment.passing_score = (score*60) // 100 "assignment_list" : assignment_list,
assignments_view += "Assignment Name: {}<br>Description: {}<br>Perfect Score: {}<br>Passing Score: {}<br>Course/Section: {} {} {}<br><br>".\ }
format(assignment.name, return render(request, "assignments/index.html", context)
assignment.description,
assignment.max_points,
assignment.passing_score,
assignment.course.course_code,
assignment.course.course_title,
assignment.course.section)
return HttpResponse(assignments_view)
def details(request, assignment_id): def details(request, assignment_id):
response = "Assignment ID: %s." try:
return HttpResponse(response % assignment_id) assignment = Article.objects.get(pk=assignment_id)
\ No newline at end of file except Assignment.DoesNotExist:
raise Http404("Assignment does not exist!")
context = {
"assignment" : assignment,
"course" : assignment.course,
}
return render(request, "assignments/details.html", context)
\ No newline at end of file
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