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 @@ ...@@ -4,7 +4,7 @@
{% block content %} {% block content %}
{% load static %} {% 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> <h3>{{ assignment.course.course_code }} {{ assignment.course.course_title }} {{ assignment.course.section }}</h3>
<ul> <ul>
<p>Assignment Name: {{ assignment.name }}</p> <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 @@ ...@@ -21,4 +21,7 @@
{% else %} {% else %}
<p>No course available.</p> <p>No course available.</p>
{% endif %} {% endif %}
<a href="add/">
<input type="button" value="New Assignment">
</a>
{% endblock %} {% endblock %}
...@@ -2,8 +2,10 @@ from django.urls import path ...@@ -2,8 +2,10 @@ from django.urls import path
from . import views from . import views
urlpatterns = [ urlpatterns = [
#assignments
path('', views.index, name='index'),
#assignments/ #assignments/
path('', views.index, name='index'),
#assignments/<int:assignment_id>/details/
path('<int:assignment_id>/details/', views.detail, name="detail"), 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 ...@@ -3,7 +3,7 @@ from django.http import HttpResponse
from django.shortcuts import render from django.shortcuts import render
from django.views import View from django.views import View
from .models import Course, Assignment from .models import Course, Assignment
from .forms import AssignmentForm
# Create your views here. # Create your views here.
def index(request): def index(request):
...@@ -19,9 +19,21 @@ def index(request): ...@@ -19,9 +19,21 @@ def index(request):
def detail(request, assignment_id): def detail(request, assignment_id):
assignment = Assignment.objects.get(pk=assignment_id) assignment = Assignment.objects.get(pk=assignment_id)
assignment.passing_score = assignment.max_points * 0.6
image = f'assignments/{assignment.id}.jpg' image = f'assignments/{assignment.id}.jpg'
context = { context = {
"assignment": assignment, "assignment": assignment,
"assignment_image": image "assignment_image": image
} }
return render(request, "assignment_detail.html", context) 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)
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