feat: update and add views in assignments app

Add base and detail HTML files in template, required views, and url paths.
Edit index.html to follow format in specs.

Add static elements in app such as CSS formatting and images.
parent 9c21583b
...@@ -2,6 +2,8 @@ from pyexpat import model ...@@ -2,6 +2,8 @@ from pyexpat import model
from django.db import models from django.db import models
from django.core.validators import RegexValidator from django.core.validators import RegexValidator
# Create your models here. # Create your models here.
class Course(models.Model): class Course(models.Model):
course_code = models.CharField(max_length=10) course_code = models.CharField(max_length=10)
......
h1{
color: purple;
font-weight: bold;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
p, ul{
color: darkolivegreen;
font-size: 24px;
margin-bottom: 15px;
display: block;
text-align: justify;
font-family: Georgia, 'Times New Roman', Times, serif;
}
body{
background-color: rgb(255, 225, 182);
}
a{
color: blueviolet;
}
a:visited{
color: brown;
}
a:hover{
color: orangered;
}
img{
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
}
{% load static %}
<!DOCTYPE html>
<html lang ="en">
<head>
<link rel ="stylesheet" type="text/css" href="{% static 'assignments/style.css' %}">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE-edge">
<meta name ="viewport" content="width-device width, initial scale=1.0">
<title>Assignments</title>
</head>
<body>
{% block content %}
{% endblock %}
</body>
</html>
\ No newline at end of file
{% extends "assignments/base.html" %}
{% load static %}
{% block content %}
<h1> {{assignment.course.course_code}} {{assignment.course.course_title}} {{assignment.course.section}} </h1>
<p>
{{assignment.name}} <br>
{{assignment.description}} <br>
{{assignment.max_points}} <br>
{{assignment.passing_score}} <br>
{% if assignment.id == 1 %}
<img src = "{% static 'assignments/images/history.jpg' %}" alt = "history">
{% elif assignment.id == 2 %}
<img src = "{% static 'assignments/images/koreanlang.png' %}" alt = "korean speaking">
{% else %}
<img src = "{% static 'assignments/images/yoga.jpg' %}" alt = "yoga">
{% endif %}
</p>
{% endblock %}
\ No newline at end of file
<!DOCTYPE html> {% extends "assignments/base.html" %}
<html>
<head></head> {% block content %}
<body> <h1> Assignments Per Course </h1>
<h1> ASSIGNMENTS: </h1>
{% for assignment in assignment_entries %}
<p> <p>
Assignment Name: {{assignment.name}}<br> List of All Courses: <br>
Description: {{assignment.description}}<br> {% for course in course_list %}
Perfect Score: {{assignment.max_points}}<br> <ul>
Passing Score: {{assignment.passing_score}}<br> <li>{{course.course_code}} {{course.course_title}} {{course.section}} </li>
Course/Section: {{assignment.course.course_code}} {{assignment.course.course_title}} | {{assignment.course.section}}
</p> {% for assignment in course.assignment_set.all %}
<ul>
<li> <a href = "{% url 'assignments:detail' assignment.id %}"> {{assignment.name}} </a> </li>
</ul>
{% endfor %}
</ul>
{% endfor %} {% endfor %}
</p>
{% endblock %}
</body>
</html>
from django.urls import path from django.urls import path, include
from . import views from . import views
urlpatterns = [ urlpatterns = [
path('', views.index, name = 'index'), path('', views.index, name = 'index'),
#assignments/1/details
path("<int:assignment_id>/details/", views.detail, name='detail'),
] ]
app_name = "assignments" app_name = "assignments"
\ No newline at end of file
from django.http import HttpResponse from unicodedata import name
from django.template import loader from django.http import Http404, HttpResponse
from django.shortcuts import render, redirect
from .models import Course, Assignment from .models import Course, Assignment
# Create your views here. # Create your views here.
def index(request): def index(request):
assignments = Assignment.objects.all() course_list = Course.objects.order_by("course_code")
template = loader.get_template('assignments/index.html')
context = { context = {
'assignment_entries': assignments 'course_list': course_list
} }
return HttpResponse(template.render(context, request)) return render(request, "assignments/index.html", context)
def detail(request, assignment_id):
try:
assignment = Assignment.objects.get(pk=assignment_id)
except Assignment.DoesNotExist:
raise Http404("Assignment does not exist!")
return render(request, "assignments/detail.html", {"assignment": assignment})
\ 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