Commit fe028b47 authored by Gabriel Limbaga's avatar Gabriel Limbaga

Implemented forms for assignments

parent cd4ff487
from django.db import models
from django.urls import reverse
class Course(models.Model):
code = models.CharField(max_length=10)
......@@ -23,3 +23,6 @@ class Assignment(models.Model):
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse('assignments:assignment-details', kwargs={'pk': self.pk})
{% extends 'base.html' %}
{% load static %}
{% block title %} Add Assignment {% endblock %}
{% block content %}
<h1> Add a new Assignment: </h1>
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="Submit" value="Save New Assignment">
</form>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %} {{object.name}} {% endblock %}
{% block content %}
<h1>{{object.name}}</h1>
<h2>{{object.course.code}} {{object.course.title}} - {{ object.course.section }}<br>
Description: {{object.description}}<br>
Perfect Score: {{object.perfect_score}}<br>
Passing Score: {{object.passing_score}}<br>
</h2>
<a href="/assignments/{{object.id}}/edit"><button>Edit Assignment</button></a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %} Edit Assignment {% endblock %}
{% block content %}
<h1> Edit Assignment: </h1>
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="Submit" value="Save Changes to Assignment">
</form>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %} Widget's Assignments{% endblock %}
{% block content%}
<h1>Welcome to Widget's Assignments</h1>
<ul>
{% for assignment in assignments %}
<li>
<a href = "{{ assignment.get_absolute_url }}">
{{assignment}}
</a>
</li>
{% endfor %}
</ul>
<form action="./add">
<button type="Submit">New Assignment</button>
</form>
<br>
<a href = "../dashboard/">Dashboard</a><br>
<a href = "../forum/">Forum</a><br>
<a href = "../assignments/">Assignments</a><br>
<a href = "../calendar/">Calendar</a><br>
{% endblock %}
from django.urls import path
from . import views
from .views import *
urlpatterns = [
path("", views.assignments, name="assignments"),
path('<int:pk>/details/', AssignmentDetailView.as_view(), name = 'assignment-details'),
path('add/', AssignmentCreateView.as_view(), name = 'assignment-add'),
path('<int:pk>/edit/', AssignmentUpdateView.as_view(), name = 'assignment-edit')
]
app_name= "assignments"
\ No newline at end of file
from django.http import HttpResponse
from .models import Assignment, Course
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from django.views.generic.edit import CreateView, UpdateView
from django.shortcuts import render
from django.template import loader
def assignments(request):
assignments = Assignment.objects.all()
context = {'assignments': assignments,}
response = "Widget's Assignments Page <br><br>"
return render(request, 'assignments/assignments.html', context)
for assignment in assignments:
name = "Asssignment Name: " + assignment.name + "<br>"
desc = "Description: " + assignment.description + "<br>"
perfect = "Perfect Score: " + str(assignment.perfect_score) + "<br>"
passing = "Passing Score: " + str(assignment.passing_score) + "<br>"
courseSection = (
"Course/Section: "
+ assignment.course.code
+ " "
+ assignment.course.title
+ "-"
+ assignment.course.section
)
class AssignmentDetailView(DetailView):
model = Assignment
template_name = 'assignments/assignment-details.html'
response += name + desc + perfect + passing + courseSection + "<br><br>"
class AssignmentCreateView(CreateView):
model = Assignment
fields = '__all__'
template_name = 'assignments/assignment-add.html'
return HttpResponse(response)
class AssignmentUpdateView(UpdateView):
model = Assignment
fields = '__all__'
template_name = 'assignments/assignment-edit.html'
<!DOCTYPE html>
<html lang="en">
<head>
<title>{% block title %}My amazing site{% endblock %}</title>
{% block styles %}{% endblock %}
</head>
<body>
{% block content %}{% endblock %}
{% block scripts %}{% endblock %}
</body>
</html>
\ No newline at end of file
......@@ -9,7 +9,7 @@ https://docs.djangoproject.com/en/3.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""
import os
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
......@@ -59,7 +59,7 @@ ROOT_URLCONF = "widget_casanatics.urls"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"DIRS": [os.path.join(BASE_DIR, 'templates')],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
......
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