Commit b839dbb6 authored by Joerell Frank Yee Lao's avatar Joerell Frank Yee Lao

added a button to create a new assignment.

parent cd649422
from django import forms
from .models import Assignment, Course
class AssignmentForm(forms.ModelForm):
class Meta:
model = Assignment
fields = '__all__'
......@@ -4,7 +4,7 @@
{% block content %}
{% load static %}
<img src="{% static assignment_image %}" alt="Photo of assignments"/>
<img src="{% static assignment_image %}" alt="No available image :("/>
<h3>{{ assignment.course.course_code }} {{ assignment.course.course_title }} {{ assignment.course.section }}</h3>
<ul>
<p>Assignment Name: {{ assignment.name }}</p>
......
{% extends 'assignment_base.html' %}
{% load static %}
{% block title %}Widget's Assignments{% endblock %}
{% block content %}
<h3>New Assignment</h3>
<form action="" method="POST" enctype="multipart/form-data">
{% csrf_token %}
{{ AssignmentForm.as_p }}
<input type='submit' value='Save Assignment'>
</form>
<a href="../">
<input type="button" value="Back to Assignments">
</a>
{% endblock %}
......@@ -21,4 +21,7 @@
{% else %}
<p>No course available.</p>
{% endif %}
<a href="add/">
<input type="button" value="New Assignment">
</a>
{% endblock %}
......@@ -2,8 +2,10 @@ from django.urls import path
from . import views
urlpatterns = [
#assignments
path('', views.index, name='index'),
#assignments/
path('', views.index, name='index'),
#assignments/<int:assignment_id>/details/
path('<int:assignment_id>/details/', views.detail, name="detail"),
#assignments/add/
path('add/', views.add, name="add"),
]
......@@ -3,7 +3,7 @@ from django.http import HttpResponse
from django.shortcuts import render
from django.views import View
from .models import Course, Assignment
from .forms import AssignmentForm
# Create your views here.
def index(request):
......@@ -19,9 +19,21 @@ def index(request):
def detail(request, assignment_id):
assignment = Assignment.objects.get(pk=assignment_id)
assignment.passing_score = assignment.max_points * 0.6
image = f'assignments/{assignment.id}.jpg'
context = {
"assignment": assignment,
"assignment_image": image
}
return render(request, "assignment_detail.html", context)
def add(request):
assignmentForm = AssignmentForm()
if request.method == 'POST':
assignmentForm = AssignmentForm(request.POST, request.FILES)
if assignmentForm.is_valid():
assignmentForm.save()
context = {
"AssignmentForm": assignmentForm,
}
return render(request, "assignment_form.html", context)
......@@ -12,4 +12,4 @@
<a href="../../">
<input type="button" value="Back to Posts List">
</a>
{% endblock %}
\ No newline at end of file
{% endblock %}
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