added the add.html file for creating new instances of the assignment...

added the add.html file for creating new instances of the assignment application. Made buttons that go back and go to other places.
parent 8781eaa5
from django.forms import ModelForm
from .models import Assignment
class AssignmentForm(ModelForm):
class Meta:
model = Assignment
fields = ["name", "description", "max_points", "course", "hwPicture"]
\ No newline at end of file
h1 {
text-align: center;
color:rgb(3, 4, 94);
color:rgb(240, 108, 196);
text-shadow:2px 2px 5px rgb(101, 15, 158);
font-family: "Brush Script MT", "Brush Script Std", cursive;
font-size: 50px;
......@@ -11,10 +11,10 @@ h2 {
font-family: "Arial Narrow", sans-serif;
}
body {
background-color: rgb(202, 240, 248);
background-color: rgb(248, 234, 202);
}
p {
color:rgb(0, 180, 216);
color:rgb(250, 155, 12);
font-size: 25px;
font-family: "New Century Schoolbook", "TeX Gyre Schola", serif;
}
......
{% extends 'assignments/base.html' %}
{% block title %}New Assignment{% endblock %}
{% block content %}
<h1>New Assignment</h1>
<form method="POST" action="{% url 'assignments:newAssignment' %}"
enctype="multipart/form-data">
{% csrf_token %}
{{ assignmentForm.as_p }}
<button class="button" type="submit">Save Assignment</button>
<button onclick="window.location.href='../';">Back to assignment page</button>
</form>
{% endblock %}
\ No newline at end of file
......@@ -13,4 +13,5 @@
{% load static %}
<br /><br /><br /><img src="{{ taskWork.hwPicture.url }}" alt="{{taskWork.name}}" style="width:50%">
</p>
<button onclick="window.location.href='../..';">Back to assignment page</button>
{% endblock %}
\ No newline at end of file
......@@ -7,14 +7,19 @@
<p>List of Courses:</p>
{% if assignmentList %}
<ul>
{% for taskWork in assignmentList %}
<li>{{ taskWork.course.course_code }}, {{ taskWork.course.course_title }}, - Section: {{ taskWork.course.section }}</li>
{% for course in courseList %}
<li>{{ course.course_code }}, {{ course.course_title }}, - Section: {{ course.section }}</li>
<ul>
<li><a href="{{ taskWork.id }}/details/">{{ taskWork.name }}</a></li>
{% for taskWork in assignmentList %}
{% if taskWork.course == course %}
<li><a href="{{ taskWork.id }}/details/">{{ taskWork.name }}</a></li>
{% endif %}
{% endfor %}
</ul>
{% endfor %}
</ul>
{% else %}
<p>No users are available</p>
<p>No assignments are available</p>
{% endif %}
<button onclick="window.location.href='add/';">New Assignment</button>
{% endblock %}
\ No newline at end of file
......@@ -5,5 +5,9 @@ from . import views
urlpatterns = [
path('', views.index, name='announcementIndex'),
# assignments/1/details
path("<int:assignment_id>/details/", views.details, name="details")
]
\ No newline at end of file
path("<int:assignment_id>/details/", views.details, name="details"),
# assignments/add
path("add/", views.newAssignment, name="newAssignment" ),
]
app_name = "assignments"
\ No newline at end of file
from django.http import HttpResponse, Http404
from django.shortcuts import render
from django.shortcuts import render, redirect
from .models import Course, Assignment
from .forms import AssignmentForm
assignmentList = Assignment.objects.order_by("course")
courseList = Course.objects.order_by("course_code")
# Create your views here.
def index(request):
#return HttpResponse(displayText)
assignmentList = Assignment.objects.order_by("course")
courseList = Course.objects.order_by("course_code")
context = {
"assignmentList": assignmentList,
"courseList": courseList,
}
return render(request, "assignments/index.html", context)
def details(request, assignment_id):
#return HttpResponse("This is assignment # %s." % assignment_id)
assignmentList = Assignment.objects.order_by("course")
try:
taskWork = Assignment.objects.get(pk=assignment_id)
except Assignment.DoesNotExist:
raise Http404("Assignment does not exist!")
for assignmentWork in assignmentList:
if assignmentWork.id == assignment_id:
taskWork = assignmentWork
break
context = {
"taskWork": taskWork,
"assignment_id": assignment_id
}
return render(request, "assignments/details.html", context)
\ No newline at end of file
return render(request, "assignments/details.html", context)
def newAssignment(request):
if request.method == "POST":
assignmentForm = AssignmentForm(request.POST, request.FILES)
if assignmentForm.is_valid():
new_assignment = assignmentForm.save()
return redirect("assignments:newAssignment")
else:
assignmentForm = AssignmentForm()
return render(request, "assignments/add.html", {"assignmentForm": assignmentForm})
\ 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