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): ...@@ -12,9 +12,9 @@ class Course(models.Model):
class Assignment(models.Model): class Assignment(models.Model):
assignment_name = models.CharField(unique=True, default="", max_length=50,) assignment_name = models.CharField(unique=True, default="", max_length=50,)
description = models.TextField(default="") description = models.TextField(default="")
perfect_score = models.IntegerField(default=0) perfect_score = models.IntegerField(default=100)
passing_score = models.IntegerField(default=0) passing_score = models.IntegerField(default=80)
section = models.CharField(unique=True, max_length=16,) section = models.CharField(max_length=16,)
course = models.ForeignKey( course = models.ForeignKey(
Course, Course,
on_delete=models.CASCADE, 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 @@ ...@@ -7,7 +7,7 @@
{% block content %} {% block content %}
<h2> {{object.course}} </h2> <h2> {{object.course}} </h2>
<p> Description: {{object.description}} <br> <p> Description: {{object.description}} <br>
Perfect Score: {{object.pefect_score}} <br> Perfect Score: {{object.perfect_score}} <br>
Passing Score: {{object.passing_score}} <br> Passing Score: {{object.passing_score}} <br>
</p> </p>
{% endblock %} {% endblock %}
......
...@@ -5,10 +5,12 @@ ...@@ -5,10 +5,12 @@
{% block pageTitle %} Edit Assignment {% endblock %} {% block pageTitle %} Edit Assignment {% endblock %}
{% block content %} {% block content %}
<form id="editBook" method="post">
{% csrf_token %} {% csrf_token %}
{{ form.as_p }} {{ form.as_p }}
<input type="submit" id="submitButton" value="Submit"> <input type="submit" id="submitButton" value="Edit assignment">
</form>
{% endblock %} {% endblock %}
{% block otherButtons %} {% block otherButtons %}
......
from django.urls import path from django.urls import path
from .views import homeAssignmentsPage, AssignmentsDetailView from .views import homeAssignmentsPage, AssignmentsDetailView, AssignmentsUpdateView, AssignmentsCreateView
urlpatterns = [ urlpatterns = [
path('', homeAssignmentsPage, name='homePage'), 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.shortcuts import render
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.list import ListView 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 from .models import Assignment
def homeAssignmentsPage(request): 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): class AssignmentsDetailView(DetailView):
model = Assignment model = Assignment
template_name = "templates/assignment-details.html" template_name = "templates/assignment-details.html"
pass
def index(request):
head = "<h1 style='border-bottom:4px solid lightgray;\ class AssignmentsUpdateView(UpdateView):
padding-bottom:30px;\ model = Assignment
font-size:500%;'>\ fields = "__all__"
Widget's assignment page\ template_name = "templates/assignment-edit.html"
</h1>\n"
body = ""
for subject in Assignment.objects.all(): success_url = "../details"
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>"
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(): def get_success_url(self):
pass 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