Commit 542b31ef authored by N1o9r4b7e9r6to's avatar N1o9r4b7e9r6to
parents b6962c2d b1718512
from django.forms import ModelForm
from .models import Assignment, Course
class AssignmentForm(ModelForm):
class Meta:
model = Assignment
fields = ["name", "description", "max_points", "course"]
...@@ -7,6 +7,9 @@ class Course(models.Model): ...@@ -7,6 +7,9 @@ class Course(models.Model):
course_title = models.CharField(max_length = 50) course_title = models.CharField(max_length = 50)
section = models.CharField(max_length = 3) section = models.CharField(max_length = 3)
def __str__(self):
return'{}/{}/{}'.format(self.course_code, self.course_title, self.section)
class Assignment(models.Model): class Assignment(models.Model):
course = models.ForeignKey(Course, on_delete = models.CASCADE, default = 1) course = models.ForeignKey(Course, on_delete = models.CASCADE, default = 1)
name = models.CharField(max_length = 10) name = models.CharField(max_length = 10)
...@@ -15,5 +18,9 @@ class Assignment(models.Model): ...@@ -15,5 +18,9 @@ class Assignment(models.Model):
passing_score = models.IntegerField(default = 0) passing_score = models.IntegerField(default = 0)
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
super(Assignment, self).save(*args, **kwargs)
self.passing_score = F('max_points')*0.6 self.passing_score = F('max_points')*0.6
super(Assignment, self).save(*args, **kwargs) super(Assignment, self).save(*args, **kwargs)
def __str__(self):
return'{}'.format(self.name)
...@@ -11,11 +11,12 @@ h3 { ...@@ -11,11 +11,12 @@ h3 {
p { p {
color: red; color: red;
font-weight: lighter; font-weight: bold;
font-family: "Gill Sans", sans-serif; font-family: "Gill Sans", sans-serif;
} }
body { body {
padding: 20px;
color: black; color: black;
background-color: orange; background-color: orange;
font-family: "Gill Sans", sans-serif; font-family: "Gill Sans", sans-serif;
......
{% extends "assignments/base.html" %}
{% block content %}
<form method="POST" action="{% url 'assignments:add' %}">
{% csrf_token %}
{{assignment_form.as_p}}
<button class="button" type="submit">Save Assignment</button>
<button class="button"><a href="/assignments/"">Back</a></button>
</form>
{% endblock %}
...@@ -11,5 +11,7 @@ ...@@ -11,5 +11,7 @@
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}
<center>
<button class="button"><a href="{% url 'assignments:add' %}">New Assignment</a></button>
</center>
{% endblock %} {% endblock %}
...@@ -2,8 +2,9 @@ from django.urls import path ...@@ -2,8 +2,9 @@ from django.urls import path
from . import views from . import views
urlpatterns = [ urlpatterns = [
path('', views.assignments, name='assignments'), path('', views.displayAssignments.as_view(), name='assignments'),
path("<int:assignment_id>/details/", views.details, name='details') path("<int:assignment_id>/details/", views.details, name='details'),
path("add/", views.add, name='add')
] ]
app_name = 'assignments' app_name = 'assignments'
from django.shortcuts import render from django.shortcuts import render, redirect
from . import models from . import models
from django.http import HttpResponse from .forms import AssignmentForm
from django.http import HttpResponse, Http404
from django.template import Template, Context from django.template import Template, Context
from django.template.loader import get_template from django.template.loader import get_template
from django.views import View
# Create your views here. # Create your views here.
def index(request): def index(request):
return HttpResponse("This is the Assignments page!") return HttpResponse("This is the Assignments page!")
def assignments(request): class displayAssignments(View):
template = "assignments/assignments.html"
def get(self, request):
all_assignments = models.Assignment.objects.order_by("name") all_assignments = models.Assignment.objects.order_by("name")
all_courses = models.Course.objects.order_by("course_code") all_courses = models.Course.objects.order_by("course_code")
context = { context = {
...@@ -16,7 +20,7 @@ def assignments(request): ...@@ -16,7 +20,7 @@ def assignments(request):
"all_courses": all_courses "all_courses": all_courses
} }
return render(request, "assignments/assignments.html", context) return render(request, self.template, context)
def details(request, assignment_id): def details(request, assignment_id):
assignment = models.Assignment.objects.get(pk=assignment_id) assignment = models.Assignment.objects.get(pk=assignment_id)
...@@ -25,3 +29,13 @@ def details(request, assignment_id): ...@@ -25,3 +29,13 @@ def details(request, assignment_id):
"img": "images/" + str(assignment_id) + ".jpg" "img": "images/" + str(assignment_id) + ".jpg"
} }
return render(request, "assignments/details.html", context) return render(request, "assignments/details.html", context)
def add(request):
if request.method == "POST":
assignment_form = AssignmentForm(request.POST)
if assignment_form.is_valid():
new_assignment = assignment_form.save()
return redirect("assignments:assignments")
else:
assignment_form = AssignmentForm()
return render(request, "assignments/addassignments.html", {"assignment_form": assignment_form})
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