Commit 9dc25d9d authored by Deokhyun Lee's avatar Deokhyun Lee

Add page for assignments is now correctly implemented

parent dea1426b
from django import forms
from .models import Assignment
class AddAssignmentForm(forms.ModelForm):
class Meta:
model = Assignment
exclude = ['passing_score']
{% extends 'base.html'%}
{% block title %}
Add Assignment
{% endblock %}
{% block content %}
<h2>Add a new assignment:</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Save New Assignment</button>
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html'%}
{% block title %}
Edit Assignment
{% endblock %}
{% block content %}
<h2>Edit Assignment:</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Save Changes to Assignment</button>
</form>
{% endblock %}
\ No newline at end of file
......@@ -16,7 +16,7 @@
<p>No Available Assignments.</p>
{% endif %}
<ul>
<li><button type="button" onclick="window.location.href='/books/add'">New Assignments</button></li>
<li><button type="button" onclick="window.location.href='/assignments/add'">New Assignments</button></li>
<li><a href="/dashboard">Dashboard</a></li>
<li><a href="/announcements">Announcements</a></li>
<li><a href="/forum">Forum</a></li>
......
......@@ -4,5 +4,6 @@ from . import views
# url for assignments
urlpatterns = [
path('', views.assignments_view, name='assignment'),
path('<int:pk>/details', views.AssignmentDetailView.as_view(), name='assignment_detail'),
path('<int:pk>/details', views.AssignmentDetailView.as_view(), name='assignment_details'),
path('add', views.AssignmentAddListView.as_view(), name="assignment_add" ),
]
\ No newline at end of file
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.views.generic import DetailView, CreateView, UpdateView
from .models import Assignment
from django.views.generic import DetailView
from .forms import AddAssignmentForm
# assignment view for FBV implementation.
def assignments_view(request):
......@@ -12,3 +14,35 @@ class AssignmentDetailView(DetailView):
model = Assignment
template_name = 'assignment-details.html'
context_object_name = 'assignment'
# assignment for adding CBV implementation.
class AssignmentAddListView(CreateView):
model = Assignment
form_class = AddAssignmentForm
template_name = "assignment-add.html"
def post(self, request):
form = AddAssignmentForm(request.POST)
if form.is_valid():
# onSave is called, the form will have essential data and this includes pk as well.
new_assignment = form.save()
# pass the pk and redirect.
return redirect('assignment_details', pk = new_assignment.pk)
else:
return render(request, 'book_details.html', {'form': form})
# assignment for edditing CBV implementation.
class BookEditView(UpdateView):
model = Assignment()
form_class = AddAssignmentForm
template_name = 'assignment-edit.html'
def post(self, request, pk):
form = AddAssignmentForm(request.POST)
if form.is_valid():
# onSave is called, the form will have essential data and this includes pk as well.
update_assignment = form.save()
# pass the pk and redirect.
return redirect('assignment_details', pk = update_assignment.pk)
else:
return render(request, 'book_details.html', {'form': form})
\ 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