Added forms to assignments

parent d68c4c94
from django import forms
from django.forms import Textarea
from .models import Assignment
class AssignmentForm(forms.ModelForm):
class Meta:
model = Assignment
fields = [
'name',
'description',
'max_points',
'course',
'image',
]
widgets = {
'description': Textarea(attrs={
'placeholder': 'Type description here.',
'cols': 10,
'rows': 10})
}
lables = {
'name': 'Assignment Name',
'max_points': 'Max Points',
}
\ No newline at end of file
from django.db import models from django.db import models
from django.urls import reverse
# Create your models here. # Create your models here.
class Course(models.Model): class Course(models.Model):
...@@ -32,3 +33,6 @@ class Assignment(models.Model): ...@@ -32,3 +33,6 @@ class Assignment(models.Model):
def __str__(self): def __str__(self):
return '{} - {}'.format(self.name, self.course.course_shorthand) return '{} - {}'.format(self.name, self.course.course_shorthand)
def get_absolute_url(self):
return reverse('assignments:assignment-detail', kwargs={'pk': self.pk})
\ No newline at end of file
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
{% block app_header %}Assignments Per Course{% endblock %} {% block app_header %}Assignments Per Course{% endblock %}
{% block content %} {% block content %}
{% for c in course_list|dictsort:"course_code" %} {% for c in course_list|dictsort:"course_code" %}
<div class="course_block"> <div class="course_block">
<p class="course_section">{{ c.course_code }} {{ c.course_title }} {{ c.section }}</p> <p class="course_section">{{ c.course_code }} {{ c.course_title }} {{ c.section }}</p>
<ul class="course_assignments"> <ul class="course_assignments">
...@@ -21,5 +21,9 @@ ...@@ -21,5 +21,9 @@
{% endfor %} {% endfor %}
</ul> </ul>
</div> </div>
{% endfor %} {% endfor %}
<a class="link_button" href="{% url 'assignments:assignment-create' %}">
<input class="button" type="submit" value="New Assignments">
</a>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -20,4 +20,8 @@ ...@@ -20,4 +20,8 @@
<p class="score">Passing Score: {{ object.passing_score }}</p> <p class="score">Passing Score: {{ object.passing_score }}</p>
</div> </div>
</div> </div>
<a class="link_button" href="{% url 'assignments:index' %}">
<input class="button" type="submit" value="Back to Assignments">
</a>
{% endblock %} {% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block styles %}
<link rel="stylesheet" href="{% static 'css/assignments_stylesheet.css' %}">
{% endblock %}
{% block app_header %}New Assignment{% endblock %}
{% block content %}
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
{{ form }}
<input class="button" type="submit" value="Save Assignment">
</form>
<a class="link_button" href="{% url 'assignments:index' %}">
<input class="button" type="submit" value="Back to Assignments">
</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block styles %}
<link rel="stylesheet" href="{% static 'css/assignments_stylesheet.css' %}">
{% endblock %}
{% block app_header %}Assignments{% endblock %}
{% block content %}
{% if assignment_list %}
<div class="all_assignments">
<ul>
{% for a in assignment_list %}
<li>
<a href="{% url 'assignments:assignment-detail' pk=a.pk %}">
{{ a.name }}
</a>
</li>
</ul>
</div>
{% else %}
<p>No assignments available.</p>
{% endif %}
<a class="link_button" href="{% url 'assignments:index' %}">
<input class="button" type="submit" value="Back to Assignments">
</a>
{% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import AssignmentsPageView, AssignmentDetailView from .views import (
AssignmentsPageView,
AssignmentDetailView,
AssignmentListView,
AssignmentCreateView
)
urlpatterns = [ urlpatterns = [
path('', AssignmentsPageView.as_view(), name='index'), path('', AssignmentsPageView.as_view(), name='index'),
path('assignment/<int:pk>/details', AssignmentDetailView.as_view(), name='assignment-detail'), path('assignment/<int:pk>/details', AssignmentDetailView.as_view(), name='assignment-detail'),
path('assignment/list', AssignmentListView.as_view(), name='assignment-list'),
path('assignment/add', AssignmentCreateView.as_view(), name='assignment-create'),
] ]
app_name = "assignments" app_name = "assignments"
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render, 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.edit import CreateView
from .models import Assignment, Course from .models import Assignment, Course
from .forms import AssignmentForm
from .models import Assignment
# Create your views here. # Create your views here.
class AssignmentsPageView(View): class AssignmentsPageView(View):
model = Assignment
def get(self, request): def get(self, request):
return render(request, 'assignments/assignment.html', { return render(request, 'assignments/assignment.html', {
'course_list': Course.objects.all(), 'course_list': Course.objects.all(),
'assignment_list': Assignment.objects.all() 'assignment_list': Assignment.objects.all(),
'form': AssignmentForm()
}) })
def post(self, request):
if request.method == 'POST':
form = AssignmentForm(request.POST)
if form.is_valid():
new_assignment = form.save()
return redirect('assignment_detail', pk=new_assignment.pk)
else:
form = AssignmentForm()
return render(request, 'assignments/assignment_list.html', {'form': form})
class AssignmentListView(ListView):
model = Assignment
class AssignmentDetailView(DetailView): class AssignmentDetailView(DetailView):
model = Assignment model = Assignment
class AssignmentCreateView(CreateView):
model = Assignment
fields = [
'name',
'description',
'max_points',
'course',
'image',
]
form = AssignmentForm
\ No newline at end of file
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