Commit c2332113 authored by Joerell Frank Yee Lao's avatar Joerell Frank Yee Lao

Added the Assignment portion of Lab 3

parent 19b54bc5
# Generated by Django 3.2.12 on 2022-05-18 03:24
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assignments', '0006_assignment_passing_score'),
]
operations = [
migrations.AlterField(
model_name='course',
name='course_code',
field=models.CharField(max_length=10, unique=True),
),
migrations.AlterField(
model_name='course',
name='course_title',
field=models.CharField(max_length=500, unique=True),
),
]
from django.db import models from django.db import models
class Course(models.Model): class Course(models.Model):
course_code = models.CharField(max_length=10) course_code = models.CharField(max_length=10, unique=True)
course_title = models.CharField(max_length=500) course_title = models.CharField(max_length=500, unique=True)
section = models.CharField(max_length=3) section = models.CharField(max_length=3)
def __str__(self): def __str__(self):
......
h3 {
color: black;
font-weight: bold;
font-size: 30px;
}
h4 {
color: blue;
font-weight: lighter;
font-size: 20px;
}
p {
color:green;
font-weight: bold;
}
a {
color: red
}
li {
color: green;
}
img {
width: 200;
height: 200;
}
<html lang="en">
<head>
{% load static %}
<link rel="stylesheet" href="{% static "assignments/style.css" %}">
<title>{% block title %}Title{% endblock %}</title>
{% block styles %}{% endblock %}
</head>
<body>
<div id="content">
{% block content %}{% endblock %}
</div>
{% block scripts %}{% endblock %}
</body>
</html>
{% extends 'assignment_base.html' %}
{% block title %}Widget's Assignemnt{% endblock %}
{% block content %}
{% load static %}
<img src="{% static assignment_image %}" alt="Photo of assignments"/>
<h3>{{ assignment.course.course_code }} {{ assignment.course.course_title }} {{ assignment.course.section }}</h3>
<ul>
<p>Assignment Name: {{ assignment.name }}</p>
<p>Assignment Desc: {{ assignment.description }}</p>
<p>Maximum Points: {{ assignment.max_points }}</p>
<p>Passing Score: {{ assignment.passing_score }}</p>
</ul>
{% endblock %}
{% extends 'assignment_base.html' %}
{% load static %}
{% block title %}Widget's Assignments{% endblock %}
{% block content %}
<h3>Assignments Per Course</h3>
<h4>List of courses:</h4>
{% if course_list %}
<ul>
{% for i in course_list %}
<li>{{ i.course_code}} {{ i.course_title }} {{ i.section }} </li>
{% for j in assignment_list %}
{% if i.course_code == j.course.course_code %}
<li><a href="{{ j.id }}/details/">{{ j.name }}</a></li>
{% endif %}
{% endfor %}
{% endfor %}
</ul>
{% else %}
<p>No course available.</p>
{% endif %}
{% endblock %}
...@@ -2,5 +2,8 @@ from django.urls import path ...@@ -2,5 +2,8 @@ from django.urls import path
from . import views from . import views
urlpatterns = [ urlpatterns = [
path('', views.index, name='index') #assignments
path('', views.index, name='index'),
#assignments/
path('<int:assignment_id>/details/', views.detail, name="detail"),
] ]
from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from django.shortcuts import render from django.shortcuts import render
from django.views import View
from .models import Course, Assignment from .models import Course, Assignment
# Create your views here. # Create your views here.
def index(request): def index(request):
course_list = Course.objects.order_by("course_code")
assignment_list = Assignment.objects.order_by("name")
message = 'ASSIGNMENTS:<br/>' context = {
"course_list": course_list,
course = Course.objects.all() "assignment_list": assignment_list
assignment = Assignment.objects.all() }
for i in course: return render(request, "assignment_index.html", context)
for j in assignment:
if i.course_code == j.course.course_code:
j.passing_score = j.max_points*0.6
j.save()
message += f'Assignment Name: {j.name} <br/> Decription: {j.description} <br/> Perfect Score: {j.max_points} <br/> Passing Score: {int(j.passing_score)} <br/>'
message += f'Course/Section: {i.course_code} {i.course_title} {i.section} <br/>'
message += '<br/>'
return HttpResponse(message) def detail(request, assignment_id):
assignment = Assignment.objects.get(pk=assignment_id)
image = f'assignments/{assignment.id}.jpg'
context = {
"assignment": assignment,
"assignment_image": image
}
return render(request, "assignment_detail.html", context)
...@@ -28,4 +28,4 @@ li { ...@@ -28,4 +28,4 @@ li {
img { img {
width: 200; width: 200;
height: 200; height: 200;
} }
\ No newline at end of file
...@@ -11,4 +11,4 @@ ...@@ -11,4 +11,4 @@
</div> </div>
{% block scripts %}{% endblock %} {% block scripts %}{% endblock %}
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -8,4 +8,4 @@ urlpatterns = [ ...@@ -8,4 +8,4 @@ urlpatterns = [
path('posts/<int:post_id>/details/', views.postDetailsView, name='post details') path('posts/<int:post_id>/details/', views.postDetailsView, name='post details')
#note to self: id of posts are 3,4,5,6 according to shell query #note to self: id of posts are 3,4,5,6 according to shell query
] ]
\ No newline at end of file
...@@ -125,6 +125,7 @@ USE_TZ = True ...@@ -125,6 +125,7 @@ USE_TZ = True
STATIC_URL = 'static/' STATIC_URL = 'static/'
# Default primary key field type # Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
......
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