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 { h1 {
text-align: center; text-align: center;
color:rgb(3, 4, 94); color:rgb(240, 108, 196);
text-shadow:2px 2px 5px rgb(101, 15, 158); text-shadow:2px 2px 5px rgb(101, 15, 158);
font-family: "Brush Script MT", "Brush Script Std", cursive; font-family: "Brush Script MT", "Brush Script Std", cursive;
font-size: 50px; font-size: 50px;
...@@ -11,10 +11,10 @@ h2 { ...@@ -11,10 +11,10 @@ h2 {
font-family: "Arial Narrow", sans-serif; font-family: "Arial Narrow", sans-serif;
} }
body { body {
background-color: rgb(202, 240, 248); background-color: rgb(248, 234, 202);
} }
p { p {
color:rgb(0, 180, 216); color:rgb(250, 155, 12);
font-size: 25px; font-size: 25px;
font-family: "New Century Schoolbook", "TeX Gyre Schola", serif; 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 @@ ...@@ -13,4 +13,5 @@
{% load static %} {% load static %}
<br /><br /><br /><img src="{{ taskWork.hwPicture.url }}" alt="{{taskWork.name}}" style="width:50%"> <br /><br /><br /><img src="{{ taskWork.hwPicture.url }}" alt="{{taskWork.name}}" style="width:50%">
</p> </p>
<button onclick="window.location.href='../..';">Back to assignment page</button>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -7,14 +7,19 @@ ...@@ -7,14 +7,19 @@
<p>List of Courses:</p> <p>List of Courses:</p>
{% if assignmentList %} {% if assignmentList %}
<ul> <ul>
{% for taskWork in assignmentList %} {% for course in courseList %}
<li>{{ taskWork.course.course_code }}, {{ taskWork.course.course_title }}, - Section: {{ taskWork.course.section }}</li> <li>{{ course.course_code }}, {{ course.course_title }}, - Section: {{ course.section }}</li>
<ul> <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> </ul>
{% endfor %} {% endfor %}
</ul> </ul>
{% else %} {% else %}
<p>No users are available</p> <p>No assignments are available</p>
{% endif %} {% endif %}
<button onclick="window.location.href='add/';">New Assignment</button>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -5,5 +5,9 @@ from . import views ...@@ -5,5 +5,9 @@ from . import views
urlpatterns = [ urlpatterns = [
path('', views.index, name='announcementIndex'), path('', views.index, name='announcementIndex'),
# assignments/1/details # assignments/1/details
path("<int:assignment_id>/details/", views.details, name="details") path("<int:assignment_id>/details/", views.details, name="details"),
] # assignments/add
\ No newline at end of file path("add/", views.newAssignment, name="newAssignment" ),
]
app_name = "assignments"
\ No newline at end of file
from django.http import HttpResponse, Http404 from django.http import HttpResponse, Http404
from django.shortcuts import render from django.shortcuts import render, redirect
from .models import Course, Assignment from .models import Course, Assignment
from .forms import AssignmentForm
assignmentList = Assignment.objects.order_by("course") assignmentList = Assignment.objects.order_by("course")
courseList = Course.objects.order_by("course_code")
# Create your views here. # Create your views here.
def index(request): def index(request):
#return HttpResponse(displayText) #return HttpResponse(displayText)
assignmentList = Assignment.objects.order_by("course")
courseList = Course.objects.order_by("course_code")
context = { context = {
"assignmentList": assignmentList, "assignmentList": assignmentList,
"courseList": courseList,
} }
return render(request, "assignments/index.html", context) return render(request, "assignments/index.html", context)
def details(request, assignment_id): def details(request, assignment_id):
#return HttpResponse("This is assignment # %s." % assignment_id) #return HttpResponse("This is assignment # %s." % assignment_id)
assignmentList = Assignment.objects.order_by("course")
try: try:
taskWork = Assignment.objects.get(pk=assignment_id) taskWork = Assignment.objects.get(pk=assignment_id)
except Assignment.DoesNotExist: except Assignment.DoesNotExist:
raise Http404("Assignment does not exist!") raise Http404("Assignment does not exist!")
for assignmentWork in assignmentList: for assignmentWork in assignmentList:
if assignmentWork.id == assignment_id: if assignmentWork.id == assignment_id:
taskWork = assignmentWork taskWork = assignmentWork
break break
context = { context = {
"taskWork": taskWork, "taskWork": taskWork,
"assignment_id": assignment_id "assignment_id": assignment_id
} }
return render(request, "assignments/details.html", context) return render(request, "assignments/details.html", context)
\ No newline at end of file
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