Commit 3f6e2545 authored by John Raymon C Yu's avatar John Raymon C Yu

Yu edited assignments

parent dcfbdfaa
from django import forms
from django.db import models
from django.forms import ModelForm
from assignments.models import Assignment
from assignments.models import Course
class IndexCardForm(forms.Form):
name = forms.CharField(label='Full Name', max_length=100)
section = forms.CharField(label='CSCI40 Section', max_length=5)
age = forms.IntegerField(label='Current Age')
\ No newline at end of file
class AssignmentForm(forms.Form):
assignment_name = forms.CharField(label='Assignment Name', max_length=100)
assignment_description = forms.CharField(label='Description', max_length=1000)
assignment_max_points = forms.IntegerField(label='Max Points')
assignment_course = forms.ModelChoiceField(label='Course', queryset=Course.objects.all())
\ No newline at end of file
{% load static %}
<p>
<h2>New Assignment</h2>
<form action="{% url 'assignment:addassignment' %}" method="POST">
{% csrf_token %}
{{form}}
<input type="hidden" name="next" value="{{ request.path }}">
<button type="submit">Save Assignment</button>
</form>
<button><a class="btn btn-secondary" href="{% url 'assignment:ShowCoursesView' %}">
Back
</a></button>
</p>
\ No newline at end of file
......@@ -14,4 +14,7 @@
{% else %}
<p>No courses registered.</p>
{% endif %}
<button><a class="btn btn-secondary" href="{% url 'assignment:AddAssignment' %}">
New Assignment
</a></button>
</p>
\ No newline at end of file
......@@ -2,9 +2,13 @@ from django.urls import path
from . import views
from django.conf import settings
from django.conf.urls.static import static
from .views import ShowCoursesView, add_assignment
from .views import AddAssignmentView
app_name = "assignment"
urlpatterns = [
path('', views.show_courses_page, name='ShowCoursesPage'),
path("assignment/<int:assignment_id>/details/", views.show_assignment_details, name='ShowAssignmentDetails')
path('', ShowCoursesView.as_view(), name='ShowCoursesView'),
path('<int:assignment_id>/details/', views.show_assignment_details, name='ShowAssignmentDetails'),
path('add/', AddAssignmentView.as_view(), name='AddAssignment'),
path('add/NewAssignment', views.add_assignment, name='addassignment')
]
\ No newline at end of file
from .models import Assignment, Course
from django.shortcuts import render
from django.http import Http404
from django.http import Http404, HttpResponse, HttpResponseRedirect
from django.views.generic import ListView,DetailView
from django.views import View
from .forms import AssignmentForm
# Create your views here.
course = Course.objects.order_by("course_code")
def show_courses_page(request):
course = Course.objects.order_by("course_code")
class ShowCoursesView(View):
def get(self, request):
context = {
"course": course,
"assignments": Assignment.objects.all()
}
return render(request, 'assignment_Courses_Ordered.html', context)
"""def show_courses_ordered(request):
context = {
"course": course,
"assignments": Assignment.objects.all()
}
return render(request, 'assignment_Courses_Ordered.html', context)"""
def show_assignment_details(request, assignment_id):
try:
assignment = Assignment.objects.get(pk=assignment_id)
assignment = Assignment.objects.get(assignment_id=assignment_id)
except Assignment.DoesNotExist:
raise Http404("Assignment does not exist!")
......@@ -24,3 +35,24 @@ def show_assignment_details(request, assignment_id):
}
return render(request, "assignment_Assignment_Details.html", context)
class AddAssignmentView(View):
def get(self, request):
context = {
"form": AssignmentForm()
}
return render(request, 'assignment_Add_Assignment.html', context)
def add_assignment(request):
if request.method == "POST":
add_assignment_id = Assignment.objects.all().count() + 1
add_assignment_name = request.POST.get("assignment_name")
add_assignment_description = request.POST.get("assignment_description")
add_assignment_max_points = int(request.POST.get("assignment_max_points"))
add_assignment_passing_score = int(int(add_assignment_max_points)*60/100)
course_num = int(request.POST.get("assignment_course"))
add_assignment_course = Course.objects.get(pk=course_num)
assignment = Assignment.objects.create(assignment_id=add_assignment_id, assignment_name=add_assignment_name, assignment_description=add_assignment_description, assignment_max_points=add_assignment_max_points, assignment_passing_score=add_assignment_passing_score, assignment_course = add_assignment_course)
next = request.POST.get('next','/')
return HttpResponseRedirect(next)
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