added page and form for creating new assignments

parent 46dbf336
from django.forms import ModelForm, Textarea
from django.utils.translation import gettext_lazy as _
from .models import Assignment
class AssignmentForm(ModelForm):
class Meta:
model = Assignment
fields = ['name', 'description', 'max_points', 'course', 'assignment_imageUrl']
widgets = {
'name': Textarea(attrs={'cols': 60, 'rows': 1}),
'description': Textarea(attrs={'cols': 60, 'rows': 10}),
}
labels = {
'assignment_imageUrl': _('Image'),
}
......@@ -3,23 +3,30 @@
{% block content %}
<h1>New Assignment</h1>
<hr>
<form action="./" method="post">
{% csrf_token %}
<label for="name">Name:</label><br>
<input type="text" name="name" id="name" style="width:400px"><br>
<label for="description">Description:</label><br>
<textarea name="description" id="description" style="width:400px; height:200px;"></textarea><br>
<label for="max_points">Max Points:</label><br>
<input type="number" name="max_points" id="max_points"><br>
<label for="course">Course:</label><br>
<select name="course" id="course">
{% for course in course_list %}
<option value="{{course}}">{{course.course_title}}</option>
{% endfor %}
</select><br>
<label for="Image">Image:</label><br>
<input type="text" name="assignment_imageUrl" id="assignment_imageUrl"><br><br>
<input type="submit" value="Submit">
<form method="POST" action= "{% url 'assignments:assignment-add' %}">
{% csrf_token %}
<div class="fieldWrapper">
<label for="id_name">Name:</label><br>
{{assignment_form.name}}
</div>
<div class="fieldWrapper">
<label for="id_description">Description:</label><br>
{{assignment_form.description}}
</div>
<div class="fieldWrapper">
<label for="id_max_points">Max Points:</label><br>
{{assignment_form.max_points}}
</div>
<div class="fieldWrapper">
<label for="id_course">Course:</label><br>
{{assignment_form.course}}
</div>
<div class="fieldWrapper">
<label for="id_description">Image:</label><br>
{{assignment_form.assignment_imageUrl}}
</div>
<br>
<button class="button" type="submit">Create Assignment</button>
</form>
<h5><a href ="{% url 'assignments/index'%}">Back to Assignments</h5>
<h5><a href ="{% url 'assignments:index'%}">Back to Assignments</h5>
{% endblock %}
......@@ -9,7 +9,7 @@
<ul>
{% for assignment in assignments %}
{% if assignment.course.course_code == course.course_code %}
<li><a href ="{% url 'assignment-detail' assignment.id%}">{{assignment.name}}</a></li>
<li><a href ="{% url 'assignments:assignment-detail' assignment.id%}">{{assignment.name}}</a></li>
{% endif %}
{% endfor %}
</ul>
......@@ -19,6 +19,6 @@
{% else %}
<p>No courses currently enrolled.</p>
{% endif %}
{%comment%}<h5><a href ="{% url 'assignment-add'%}">Create New Assignment</h5>{%endcomment%}
<h5><a href ="{% url 'assignments:assignment-add'%}">Create New Assignment</h5>
{% endblock %}
from django.urls import path
from .views import HomePageView, AssignmentDetailView
from . import views
app_name = "assignments"
urlpatterns = [
path('', HomePageView.as_view(), name='assignments/index'),
path('assignment/<int:pk>/details/', AssignmentDetailView.as_view(), name='assignment-detail')
path('', HomePageView.as_view(), name='index'),
path('assignment/<int:pk>/details/', AssignmentDetailView.as_view(), name='assignment-detail'),
path('add/', views.assignmentAdd, name='assignment-add')
]
from django.http import HttpResponse
from . models import Assignment, Course
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.views import View
from django.views.generic.detail import DetailView
from .forms import AssignmentForm
# Create your views here.
class HomePageView(View):
......@@ -17,3 +18,14 @@ class HomePageView(View):
class AssignmentDetailView(DetailView):
model = Assignment
def assignmentAdd(request):
assignment_form = AssignmentForm()
if request.method == "POST":
assignment_form = AssignmentForm(request.POST)
if assignment_form.is_valid():
assignment_form.save()
return redirect("assignments:assignment-add")
else:
assignment_form = AssignmentForm()
return render(request, "assignments/assignment_add.html", {"assignment_form":assignment_form})
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