Commit 9d7663a6 authored by Jonathan Talbot's avatar Jonathan Talbot

final project

parent f9ddc191
from django.forms import ModelForm
from .models import Assignment
class AssignmentForm(ModelForm):
class Meta:
model = Assignment
fields = ['name', 'description', 'max_points', 'course']
\ No newline at end of file
......@@ -8,6 +8,7 @@
</head>
<body>
<h1>Assignments Per Course</h1>
<hr>
{% for course in courses %}
<ul>
<li>{{ course.course_code }} {{ course.course_title }} {{ course.section }}
......@@ -22,6 +23,8 @@
</ul>
{% endfor %}
<hr>
<a href="{% url 'assignment-add' %}"><button>Add Assignment</button></a>
</body>
</html>
......
......@@ -12,5 +12,7 @@
<p>Max Points: {{assignment.max_points}}</p>
<p>Passing Score: {{assignment.passing_score}}</p>
<p>{{assignment.course}}</p>
<hr>
<a href="{% url 'assignment-list' %}">Back to Assignments</a>
</body>
</html>
\ No newline at end of file
<!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.0">
<title>Add Assignment</title>
</head>
<body>
<h1>Add Assignment</h1>
<hr>
<form action="{% url 'assignment-add' %}" method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Assignment">
</form>
<hr>
<a href="{% url 'assignment-list' %}">Back to Assignments</a>
</body>
</html>
\ No newline at end of file
from django.urls import path
from .views import AssignmentListView, AssignmentDetailView
from .views import AssignmentListView, AssignmentDetailView, addAssignment
urlpatterns = [
path('', AssignmentListView.as_view(), name='assignment-list'),
path('<int:pk>/details', AssignmentDetailView, name='assignment-detail'),
path('add/', addAssignment, name='assignment-add'),
]
\ No newline at end of file
from ast import Assign
from django.shortcuts import render, get_object_or_404
from django.shortcuts import render, get_object_or_404, redirect
from django.views import View
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from .models import Assignment, Course
# def assignments(request):
# assignments = Assignment.objects.all()
# courses = Course.objects.all()
# output = "ASSIGNMENTS:\n" + "\n".join(
# ['Assignment Name: {}\n Description: {}\n Perfect Score: {}\n Passing Score: {}\n Course/Section: {}'
# .format(str(assignment.name),
# str(assignment.description),
# str(assignment.max_points),
# str(assignment.passing_score),
# str(assignment.course))
# for assignment in assignments]
# )
# return HttpResponse(output, content_type = "text/plain")
from .forms import AssignmentForm
class AssignmentListView(View):
def get(self, request):
assignments = Assignment.objects.all()
assignments = Assignment.objects.order_by('course').all()
courses = Course.objects.all()
context = {
'assignments': assignments,
......@@ -36,5 +22,15 @@ def AssignmentDetailView(request, pk):
'assignment': assignment
})
# class AssignmentListView(ListView):
# model = Assignment
def addAssignment(request):
form = AssignmentForm()
if request.method == 'POST':
form = AssignmentForm(request.POST)
if form.is_valid():
new_assignment = form.save() # Creates new assignment
return redirect('assignment-detail', pk=new_assignment.pk) # Redirects to detailed view of new assignment
else:
form = AssignmentForm()
context = {'form':form}
return render(request,'assignments/assignments_form.html', context)
No preview for this file type
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