Commit 96ea2992 authored by Star Neptune R. Sy's avatar Star Neptune R. Sy

assignments-add is done

parent 8f7e287a
......@@ -12,9 +12,9 @@ class Course(models.Model):
class Assignment(models.Model):
assignment_name = models.CharField(unique=True, default="", max_length=50,)
description = models.TextField(default="")
perfect_score = models.IntegerField(default=0)
passing_score = models.IntegerField(default=0)
section = models.CharField(unique=True, max_length=16,)
perfect_score = models.IntegerField(default=100)
passing_score = models.IntegerField(default=80)
section = models.CharField(max_length=16,)
course = models.ForeignKey(
Course,
on_delete=models.CASCADE,
......
{% extends 'base.html' %}
{% block webTitle %} Add Assignment {% endblock %}
{% block pageTitle %} Add a new assignment {% endblock %}
{% block content %}
<form id="editBook" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" id="submitButton" value="Add assignment">
</form>
{% endblock %}
{% block otherButtons %}
{% endblock %}
\ No newline at end of file
......@@ -7,7 +7,7 @@
{% block content %}
<h2> {{object.course}} </h2>
<p> Description: {{object.description}} <br>
Perfect Score: {{object.pefect_score}} <br>
Perfect Score: {{object.perfect_score}} <br>
Passing Score: {{object.passing_score}} <br>
</p>
{% endblock %}
......
......@@ -5,10 +5,12 @@
{% block pageTitle %} Edit Assignment {% endblock %}
{% block content %}
<form id="editBook" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" id="submitButton" value="Submit">
<input type="submit" id="submitButton" value="Edit assignment">
</form>
{% endblock %}
{% block otherButtons %}
......
from django.urls import path
from .views import homeAssignmentsPage, AssignmentsDetailView
from .views import homeAssignmentsPage, AssignmentsDetailView, AssignmentsUpdateView, AssignmentsCreateView
urlpatterns = [
path('', homeAssignmentsPage, name='homePage'),
path('<int:pk>/details/', AssignmentsDetailView.as_view(), name='assignment_details')
path('add/', AssignmentsCreateView.as_view(), name='assignment_add'),
path('<int:pk>/details/', AssignmentsDetailView.as_view(), name='assignment_details'),
path('<int:pk>/edit/', AssignmentsUpdateView.as_view(), name='assignment_update'),
]
......
from django.forms.models import BaseModelForm
from django.http import HttpResponse
from django.shortcuts import render
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from django.http import HttpResponse
from django.views.generic.edit import CreateView, UpdateView
from django.urls import reverse, reverse_lazy
from .models import Assignment
def homeAssignmentsPage(request):
return render(request, 'templates/assignments.html', {"assignmentsList":Assignment.objects.all()})
return render(request, 'templates/assignments.html', {"assignmentsList":Assignment.objects.all()}) #you can pass an entire list of model instances to the html
class AssignmentsDetailView(DetailView):
model = Assignment
template_name = "templates/assignment-details.html"
pass
def index(request):
head = "<h1 style='border-bottom:4px solid lightgray;\
padding-bottom:30px;\
font-size:500%;'>\
Widget's assignment page\
</h1>\n"
body = ""
class AssignmentsUpdateView(UpdateView):
model = Assignment
fields = "__all__"
template_name = "templates/assignment-edit.html"
for subject in Assignment.objects.all():
body += "<p style='border: 2px solid gray;\
border-radius:5px;\
padding:20px 30px;'>\
<b> Assignment Name: "+subject.assignment_name+" </b> <br>\
Description: "+subject.description+" <br>\
Perfect Score: "+str(subject.perfect_score)+" <br>\
Passing Score: "+str(subject.passing_score)+" <br>\
Course/Section: "+str(subject.course)+" /"+str(subject.section)+" <br>\
</p>"
success_url = "../details"
return_string = "<html>\
<body>\
{}{}\
</body></html>".format(head, body)
return HttpResponse(return_string)
class AssignmentsCreateView(CreateView):
model = Assignment
fields = "__all__"
template_name = "templates/assignment-add.html"
def som():
pass
def get_success_url(self):
return reverse('assignments:assignment_details', kwargs={ #appName:pathName
'pk': self.object.pk,
})
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