Commit 5118a75d authored by Jeremy Factor's avatar Jeremy Factor

created add html and added forms.py

parent 9bbe0198
from django.apps import AppConfig
class AssignmentsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'assignments'
from django.forms import ModelForm
from .models import Assignment
from .models import Course
class AssignmentForm(ModelForm):
class Meta:
model = Assignment
fields = ["name", "description", "max_points"]
class CourseForm(ModelForm):
class Meta:
model = Course
fields = ["course_code", "course_title", "section"]
class ImageForm(ModelForm):
class Meta:
model = Assignment
fields = ["image"]
\ No newline at end of file
......@@ -6,6 +6,14 @@ class Assignment(models.Model):
description = models.CharField(max_length = 500)
max_points = models.IntegerField(default = 0)
passing_score = models.IntegerField(default = 0)
def multiply(self, *args, **kwargs):
try:
self.passing_score = self.max_points * 0.60
except TypeError:
pass
super(Assignment, self).multiply(*args, **kwargs)
image = models.FileField(upload_to='static/assignments/', blank=True, null=True)
def __str__(self):
......
{% extends "assignments/base.html" %}
{% block content %}
<h1> New Assignment </h1>
<form method="POST" action="{% url 'assignments:add' %}" enctype="multipart/form-data">
{% csrf_token %}
{{ assignment_form.as_p }}
{{ course_form.as_p }}
{{ image_form.as_p }}
<button class="button" type="submit">Save Assignment</button>
</form>
<form action="/assignments/">
<button class="button" type="submit">Back to Assignment list</button>
</form>
{% endblock %}
\ No newline at end of file
......@@ -24,4 +24,8 @@
<p>No assignments are available.</p>
{% endif %}
<form action="add/">
<button class="button" type="submit">New Assignment</button>
</form>
{% endblock %}
\ No newline at end of file
......@@ -2,11 +2,16 @@ from django.urls import path
from django.conf.urls.static import static
from django.conf import settings
from . import views
from .views import IndexView
app_name = "assignments"
urlpatterns = [
path('', views.index, name='index'),
path('', IndexView.as_view(), name='index'),
#assignments/1/details/
path("<int:assignment_id>/details/", views.details, name="details"),
#assignments/add/
path("add/", views.add, name="add"),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
from urllib import response
from django.http import HttpResponse, Http404
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.views import View
from assignments.models import Assignment
from assignments.models import Course
from .forms import AssignmentForm
from .forms import CourseForm
from .forms import ImageForm
# Create your views here.
def index(request):
class IndexView(View):
def get(self, request):
assignment_list = Assignment.objects.order_by("name")
course_list1 = Course.objects.order_by("course_code")
context = {
"assignment_list": assignment_list,
"course_list1": course_list1
}
return render(request, "assignments/index.html", context)
"""def index(request):
assignment_list = Assignment.objects.order_by("name")
course_list1 = Course.objects.order_by("course_code")
......@@ -16,7 +32,7 @@ def index(request):
"assignment_list": assignment_list,
"course_list1": course_list1
}
return render(request, "assignments/index.html", context)
return render(request, "assignments/index.html", context)"""
def details(request, assignment_id):
......@@ -30,6 +46,20 @@ def details(request, assignment_id):
return render(request, "assignments/details.html", {"assignments":assignments, 'course_list2':course_list2})
def add(request):
if request.method == "POST":
assignment_form = AssignmentForm(request.POST, request.FILES)
if assignment_form.is_valid():
assignment_form.save()
course_form.save()
image_form.save()
return redirect("assignments:add")
else:
assignment_form = AssignmentForm()
course_form = CourseForm()
image_form =ImageForm()
return render(request, "assignments/add.html", {"assignment_form": assignment_form, "image_form": image_form, "course_form": course_form})
"""assignment_objects = Assignment.objects.all()
course_objects = Course.objects.all()
response = "ASSIGNMENTS:<br>"
......
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