Added url for new assignment and modified css styling for Assignments

parent 338ad419
from django.forms import ModelForm
from .models import Assignment
class AssignmentForm(ModelForm):
class Meta:
model = Assignment
fields = ["course_code", "name", "description", "max_points"]
......@@ -5,6 +5,7 @@ from . import views
urlpatterns = [
path('', views.index, name="assignment-list"),
path('<int:pk>/details', views.detail, name="assignment-detail"),
path('add/', views.newassignment, name="add-assignment"),
]
app_name = "assignments"
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.http import HttpResponse
from .models import Assignment, Course
from .forms import AssignmentForm
# Create your views here.
def index(request):
......@@ -13,22 +14,6 @@ def index(request):
}
return render(request, "assignments/assignments_list.html", context)
# heading = 'ASSIGNMENTS:<br><br>'
# assignments = Assignment.objects.all()
# body = ''
#
# for assignment in assignments:
# courses = Course.objects.filter(course_code__exact=assignment.course_code)
# body += 'Assignment Name: {}<br>Description: {}<br>Perfect Score: {}<br>Passing Score: {}<br>'.format(
# assignment.name, assignment.description, assignment.max_points, assignment.passing_score
# )
# for course in courses:
# body += 'Course/Section: {} {} {}<br><br>'.format(
# course.course_code, course.course_title, course.section
# )
#
# return HttpResponse(heading + body)
def detail(request, pk):
assignment = Assignment.objects.get(pk=pk)
course = Course.objects.get(course_code__exact=assignment.course_code)
......@@ -37,3 +22,13 @@ def detail(request, pk):
"course": course,
}
return render(request, "assignments/assignments_detail.html", context)
def newassignment(request):
if request.method == "POST":
assignment_form = AssignmentForm(request.POST)
if assignment_form.is_valid():
new_assignment = assignment_form.save()
return redirect("assignments:add-assignment")
else:
assignment_form = AssignmentForm()
return render(request, "assignments/add_assignment.html", {"assignment_form": assignment_form})
h1 {
color: black;
font-family: 'Futura';
font-size: 48px;
text-align: left;
}
form {
color: rgb(48, 0, 159);
font-family: 'Futura';
font-size: 24px;
text-align: left;
}
button {
color: rgb(46, 5, 140);
font-family: 'Futura';
font-size: 20px;
text-align: left;
}
a {
color: black;
font-family: 'Futura';
font-size: 20px;
text-align: left;
}
h1 {
color: black;
font-family: 'Futura';
font-size: 28px;
font-size: 54px;
text-align: left;
}
li {
color: rgb(48, 0, 159);
font-family: 'Futura';
font-size: 36px;
text-align: left;
}
li b {
color: black;
font-family: 'Futura';
font-size: 18px;
font-size: 36px;
text-align: left;
}
......@@ -2,16 +2,26 @@ h1 {
color: black;
font-family: 'Futura';
font-size: 48px;
text-align: center;
text-align: left;
}
li {
color: black;
font-family: 'Futura';
font-size: 24px;
font-size: 32px;
text-align: left;
}
a:visited {
color: blue;
li li a {
color: rgb(28, 4, 82);
font-family: 'Futura';
font-size: 28px;
text-align: left;
}
a button {
color: rgb(28, 4, 82);
font-family: 'Futura';
font-size: 32px;
text-align: left;
}
{% extends 'base.html' %}
{% load static %}
{% block title %}Assignments{% endblock %}
{% block styles %}
<link rel="stylesheet" type="text/css" href="{% static 'assignments/css/add_assignment_styles.css' %}">
{% endblock %}
{% block content %}
<header>
<h1>New Assignment</h1>
</header>
<form action="{%url 'assignments:add-assignment' %}" method="POST">
{% csrf_token %}
{{ assignment_form.as_p }}
<button class="Save Assignment" type="submit">Save Assignment</button>
</form>
<a href="{% url 'assignments:assignment-list' %}">Back to Assignments Page</a>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %}Assignments{% endblock %}
{% block title %}{{ assignment.name }}{% endblock %}
{% block styles %}
<link rel="stylesheet" type="text/css" href="{% static 'assignments/css/assignments_detail_styles.css' %}">
{% endblock %}
{% block content %}
<header>
<h1>{{ assignment.name }}</h1>
</header>
<p>
<ul>
<li><b>Course & Section:</b> {{ course.course_code }} {{ course.course_title }} {{ course.section }}</li>
<li><b>Description:</b> {{ assignment.description }}</li>
......@@ -34,23 +39,5 @@
<img src="{% static 'assignments/img/Quiz 3.png' %}" alt="Quiz 3">
{% endif %}</li>
</ul>
{% if pk == 1 %}
<img src="{% static 'assignments/img/Lab 1.jpeg' %}" alt="Lab 1">
{% endif %}
{% if pk == 2 %}
<img src="{% static 'assignments/img/Lab 2.jpg' %}" alt="Lab 2">
{% endif %}
{% if pk == 3 %}
<img src="{% static 'assignments/img/Exercise 1.jpg' %}" alt="Exercise 1">
{% endif %}
{% if pk == 4 %}
<img src="{% static 'assignments/img/Exercise 2.jpg' %}" alt="Exercise 2">
{% endif %}
{% if pk == 5 %}
<img src="{% static 'assignments/img/Probset 1.jpg' %}" alt="Probset 1">
{% endif %}
{% if pk == 6 %}
<img src="{% static 'assignments/img/Quiz 3.png' %}" alt="Quiz 3">
{% endif %}
</p>
{% endblock %}
......@@ -27,4 +27,9 @@
{% endfor %}
</ul>
</p>
<a href="{% url 'assignments:add-assignment' %}">
<button class="New Assignment">New Assignment</button>
</a>
{% endblock %}
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