Commit fdc7e519 authored by Katrina Bernice Tan's avatar Katrina Bernice Tan

Added POST functionality to Assignments

parent 4f7f5afc
from django import forms
from .models import Assignment
class AssignmentForm(forms.ModelForm):
class Meta:
model = Assignment
fields = '__all__'
...@@ -76,4 +76,9 @@ a:hover{ ...@@ -76,4 +76,9 @@ a:hover{
#details h4{ #details h4{
font-size: 20px; font-size: 20px;
font-weight: 500; font-weight: 500;
}
#button a{
font-weight: 900px;
padding: 5em;
} }
\ No newline at end of file
...@@ -10,7 +10,10 @@ ...@@ -10,7 +10,10 @@
</div> </div>
<div id = "details"> <div id = "details">
<a href = "/assignments"> > Back to home </a>
<br>
<img src="{%static 'images/jokebear.png'%}"> <img src="{%static 'images/jokebear.png'%}">
<h5> Assignment Name: </h5> <h5> Assignment Name: </h5>
<h3>{{object.name}} </h3> <h3>{{object.name}} </h3>
<h4> <b>Assignment Description:</b> {{object.description}} </h4> <h4> <b>Assignment Description:</b> {{object.description}} </h4>
......
{% extends 'base.html' %}
{% load static %}
{% block styles %}
<link rel = "stylesheet" href="{% static 'css/index.css' %}">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@200;500;900&display=swap" rel="stylesheet">
{% endblock styles %}
{% block title %} Assignments {% endblock title%}
{% block content %}
<div id = "header">
<h1> Create a new assignment </h1>
</div>
<div id = "courses" style="margin: 5em;">
<a href = "/assignments"> > Back to home </a>
<form action="{% url 'Assignments:assignment-list' %}" method = "POST" style = "padding-top: 5em;">
{% csrf_token %}
{{form}}
<input type = "submit" value = "Create New Subject">
</form>
</div>
{%endblock content%}
\ No newline at end of file
...@@ -17,5 +17,9 @@ ...@@ -17,5 +17,9 @@
<h1> List of courses: </h1> <h1> List of courses: </h1>
</div> </div>
{% include "Assignments/assignment_list.html" with assignments=assignment course=course %} {% include "Assignments/assignment_list.html" with assignments=assignment course=course %}
<div id = "button">
<a href = "/assignments/add" id = "assignment-button" style = "font-weight: 900px"> > New Assignment </a>
</div>
{%endblock content%} {%endblock content%}
\ No newline at end of file
from django.shortcuts import render from ast import Assign
from django.shortcuts import render, redirect
from django.http import HttpResponse from django.http import HttpResponse
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
class MainView(View): class MainView(View):
def get(self, request): def get(self, request):
...@@ -13,10 +15,43 @@ class MainView(View): ...@@ -13,10 +15,43 @@ class MainView(View):
return render(request, 'assignments.html',{ return render(request, 'assignments.html',{
'course': course, 'course': course,
'assignment': assignment, 'assignment': assignment,
'form': AssignmentForm(),
}) })
class AssignmentListView(ListView): class AssignmentListView(ListView):
model = Assignment model = Assignment
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['form'] = AssignmentForm()
return context
def post(self, request, *args, **kwargs):
form = AssignmentForm(request.POST)
if form.is_valid():
name = form.cleaned_data.get('name')
description = form.cleaned_data.get('description')
max_points = form.cleaned_data.get('max_points')
course = form.cleaned_data.get('course')
a = Assignment(
name = name,
description=description,
max_points = max_points,
course = course,
)
a.save()
return redirect('/assignments')
return self.get(request, *args, **kwargs)
class AssignmentDetailView(DetailView): class AssignmentDetailView(DetailView):
model = Assignment model = Assignment
class AssignmentPostView(View):
def get(self,request):
return render(request, 'assignment_post.html',{
'form': AssignmentForm(),
})
...@@ -19,7 +19,7 @@ from django.contrib import admin ...@@ -19,7 +19,7 @@ from django.contrib import admin
from django.urls import path, include from django.urls import path, include
import Announcements.views as Announcements_views import Announcements.views as Announcements_views
import Forum.views as Forum_views import Forum.views as Forum_views
from Assignments.views import AssignmentDetailView from Assignments.views import AssignmentDetailView, AssignmentPostView
from Homepage.views import UserPageView from Homepage.views import UserPageView
urlpatterns = [ urlpatterns = [
...@@ -33,6 +33,7 @@ urlpatterns = [ ...@@ -33,6 +33,7 @@ urlpatterns = [
path('announcements/<int:announcement_id>/details', Announcements_views.details, name='announcement_details'), path('announcements/<int:announcement_id>/details', Announcements_views.details, name='announcement_details'),
path('assignments/', include('Assignments.urls', namespace="Assignments")), path('assignments/', include('Assignments.urls', namespace="Assignments")),
path('assignment/<int:pk>/details', AssignmentDetailView.as_view(), name ='assignment-detail'), path('assignment/<int:pk>/details', AssignmentDetailView.as_view(), name ='assignment-detail'),
path('assignments/add/', AssignmentPostView.as_view(), name = 'assignement-post'),
] ]
......
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