Commit 2e0f4a51 authored by Joan Denise Nocos's avatar Joan Denise Nocos

fix: resolved merge conflicts

parents ab067941 9b64c645
# Generated by Django 3.2.12 on 2022-05-18 07:45
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assignments', '0004_auto_20220406_0329'),
]
operations = [
migrations.AddField(
model_name='assignment',
name='image',
field=models.FileField(null=True, upload_to='static/'),
),
]
# Generated by Django 3.2.12 on 2022-05-19 01:53
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('assignments', '0005_assignment_image'),
]
operations = [
migrations.AlterField(
model_name='assignment',
name='image',
field=models.FileField(null=True, upload_to='static/assignments/'),
),
]
from django.db import models from django.db import models
import os
# Create your models here. # Create your models here.
class Course(models.Model): class Course(models.Model):
...@@ -12,8 +13,11 @@ class Assignment(models.Model): ...@@ -12,8 +13,11 @@ class Assignment(models.Model):
description = models.CharField(max_length=500) description = models.CharField(max_length=500)
max_points = models.IntegerField(default=0) max_points = models.IntegerField(default=0)
passing_score = models.IntegerField(default=0) passing_score = models.IntegerField(default=0)
image = models.FileField(upload_to='static/assignments/', null=True)
def _str_(self): def _str_(self):
return self.name return self.name
def file(self):
\ No newline at end of file value = os.path.basename(self.image.name)
return value
\ No newline at end of file
h1 {
position: sticky;
text-align: center;
color: purple;
font-size: 55px;
font-family: Georgia;
}
h2 {
color: purple;
font-size: 30px;
font-family: Georgia;
}
h3 {
color: black;
font-weight: bold;
font-family: Courier New;
font-size:25px;
}
p{
color: black;
font-family: Helvetica;
font-size:20px;
}
body {
background-color: white;
}
a{
color: blue;
font-family: Courier New;
font-size: 20px;
font-weight: bold;
}
a:link {
text-decoration: underline;
}
\ No newline at end of file
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" type="text/css"
href="{% static 'assignments/style.css' %}">
<title>{% block page-title %}{% endblock %}</title>
</head>
<body>
{% block content %}
{% endblock %}
</body>
</html>
{% extends "assignments/base.html" %}
{% block page-title %}Assignment {{ assignment_id }} Details{% endblock %}
{% block content %}
<h1>{{ course.course_code }} {{ course.course_title }} {{ course.section }}</h1>
<h3>{{ assignment.name }}</h3>
<p>Description: {{ assignment.description }}</p>
<p>Perfect Score: {{ assignment.max_points }}</p>
<p>Passing Score: {{ assignment.passing_score }}</p>
<img src="/static/assignments/{{ assignment.file }}" width="250" height="250">
{% endblock %}
\ No newline at end of file
{% extends "assignments/base.html" %}
{% block page-title %}Assignments Per Course{% endblock %}
{% block content %}
<h1>Assignments Per Course</h1>
<h2>List of courses:</h2>
{% if course_list %}
<ul>
{% for course in course_list %}
<li><h3>{{ course.course_code }} {{ course.course_title }} {{ course.section }}</h3></li>
<ul>
{% for assignment in assignment_list %}
{% if assignment.course == course %}
<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 %}
\ No newline at end of file
...@@ -2,6 +2,10 @@ from django.urls import path ...@@ -2,6 +2,10 @@ from django.urls import path
from . import views from . import views
app_name = "assignments"
urlpatterns = [ urlpatterns = [
path('', views.index, name='index') # assignments/
path('', views.index, name='index'),
# assignments/<assignment_id>/details/
path('<int:assignment_id>/details/', views.details, name='details'),
] ]
\ No newline at end of file
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 = {
"course_list" : course_list,
"assignment_list" : assignment_list,
}
return render(request, "assignments/index.html", context)
def details(request, assignment_id):
try:
assignment = Assignment.objects.get(pk=assignment_id)
except Assignment.DoesNotExist:
raise Http404("Assignment does not exist.")
score = assignment.max_points score = assignment.max_points
assignment.passing_score = (score*60) // 100 assignment.passing_score = (score*60) // 100
assignments_view += "Assignment Name: {}<br>Description: {}<br>Perfect Score: {}<br>Passing Score: {}<br>Course/Section: {} {} {}<br><br>".\
format(assignment.name,
assignment.description,
assignment.max_points,
assignment.passing_score,
assignment.course.course_code,
assignment.course.course_title,
assignment.course.section)
return HttpResponse(assignments_view) context = {
\ No newline at end of file "assignment" : assignment,
"course" : assignment.course,
}
return render(request, "assignments/details.html", context)
# Code from previous labs:
#
# def index(request):
# assignments_view = "ASSIGNMENTS: <br>"
# schoolwork = Assignment.objects.all()
# for assignment in schoolwork:
# score = assignment.max_points
# assignment.passing_score = (score*60) // 100
# assignments_view += "Assignment Name: {}<br>Description: {}<br>Perfect Score: {}<br>Passing Score: {}<br>Course/Section: {} {} {}<br><br>".\
# format(assignment.name,
# assignment.description,
# assignment.max_points,
# assignment.passing_score,
# assignment.course.course_code,
# assignment.course.course_title,
# assignment.course.section)
#
# return HttpResponse(assignments_view)
\ 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