Commit 5b7d8393 authored by Jonathan Talbot's avatar Jonathan Talbot

Merge branch 'detorres/assignments' into 'main'

Detorres/assignments

See merge request !15
parents 9655250f 9d7663a6
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 @@ ...@@ -8,6 +8,7 @@
</head> </head>
<body> <body>
<h1>Assignments Per Course</h1> <h1>Assignments Per Course</h1>
<hr>
{% for course in courses %} {% for course in courses %}
<ul> <ul>
<li>{{ course.course_code }} {{ course.course_title }} {{ course.section }} <li>{{ course.course_code }} {{ course.course_title }} {{ course.section }}
...@@ -22,6 +23,8 @@ ...@@ -22,6 +23,8 @@
</ul> </ul>
{% endfor %} {% endfor %}
<hr>
<a href="{% url 'assignment-add' %}"><button>Add Assignment</button></a>
</body> </body>
</html> </html>
......
...@@ -12,5 +12,7 @@ ...@@ -12,5 +12,7 @@
<p>Max Points: {{assignment.max_points}}</p> <p>Max Points: {{assignment.max_points}}</p>
<p>Passing Score: {{assignment.passing_score}}</p> <p>Passing Score: {{assignment.passing_score}}</p>
<p>{{assignment.course}}</p> <p>{{assignment.course}}</p>
<hr>
<a href="{% url 'assignment-list' %}">Back to Assignments</a>
</body> </body>
</html> </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 django.urls import path
from .views import AssignmentListView, AssignmentDetailView from .views import AssignmentListView, AssignmentDetailView, addAssignment
urlpatterns = [ urlpatterns = [
path('', AssignmentListView.as_view(), name='assignment-list'), path('', AssignmentListView.as_view(), name='assignment-list'),
path('<int:pk>/details', AssignmentDetailView, name='assignment-detail'), 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 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 import View
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.list import ListView from django.views.generic.list import ListView
from .models import Assignment, Course from .models import Assignment, Course
from .forms import AssignmentForm
# 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")
class AssignmentListView(View): class AssignmentListView(View):
def get(self, request): def get(self, request):
assignments = Assignment.objects.all() assignments = Assignment.objects.order_by('course').all()
courses = Course.objects.all() courses = Course.objects.all()
context = { context = {
'assignments': assignments, 'assignments': assignments,
...@@ -36,5 +22,15 @@ def AssignmentDetailView(request, pk): ...@@ -36,5 +22,15 @@ def AssignmentDetailView(request, pk):
'assignment': assignment 'assignment': assignment
}) })
# class AssignmentListView(ListView): def addAssignment(request):
# model = Assignment 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