Commit 01f330f3 authored by Caryn Lopez-Go's avatar Caryn Lopez-Go Committed by Ysabella Panghulan

added templates and made edits to models, urls, and views.

parent a483a340
from django.db import models
from django.urls import reverse
# Create your models here.
class Course(models.Model):
......@@ -21,3 +22,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})
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}Add Assignment{% endblock %}
{% block header %}Add a new assignment:{% endblock %}
{% block content %}
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="SUBMIT" value="Save New Assignment">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}{{ assignment.name }}{% endblock %}
{% block heading %}{{ assignment.name }}{% endblock %}
{% block content %}
<p>
{{ assignment.course.code }} {{ assignment.course.title }} - {{ assignment.course.section }}<br>
Description: {{ assignment.description }}<br>
Perfert Score: {{ assignment.perfect_score }}<br>
Passing Score: {{ assignment.passing_score }}
</p>
<a href="{% url 'assignments:assignment-edit' assignment.id %}">
<button>Edit Assignment</button>
</a><br>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}Edit Assignment{% endblock %}
{% block header %}Edit Assignment:{% endblock %}
{% block content %}
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="SUBMIT" value="Save Changes to Assignment">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}Widget's Assignments{% endblock %}
{% block heading %}Welcome to Widget's Assignments{% endblock %}
{% block content %}
<ul>
{% for assignment in assignments %}
<li>
<a href="{ assignment.get_absolute_url }"></a>
</li>
{% endfor %}
<a href="{% url 'assignments:assignment-add' %}">
<button>New Assignment</button>
</a><br>
</ul>
<a href="{% url 'dashboard:dashboard' %}">Dashboard</a><br>
<a href="{% url 'announcements:announcements' %}">Announcements</a><br>
<a href="{% url 'forum:forum' %}">Forum</a><br>
<a href="{% url 'calendar:calendar' %}">Calendar</a>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}Widget's Assignments{% endblock %}
{% block heading %}Welcome to Widget's Assignments{% endblock %}
{% block content %}
<ul>
{% for assignment in assignments %}
<li>
<a href="{ assignment.get_absolute_url }"></a>
</li>
{% endfor %}
<a href="{% url 'add-assignment' assignment.id %}">
<button>{{ assignment.title }}</button>
</a><br>
</ul>
<a href="{% url 'dashboard:dashboard' %}">Dashboard</a><br>
<a href="{% url 'announcements:announcements' %}">Announcements</a><br>
<a href="{% url 'forum:forum' %}">Forum</a><br>
<a href="{% url 'calendar:calendar' %}">Calendar</a>
{% endblock %}
\ No newline at end of file
from django.urls import path
from . import views
from .views import *
urlpatterns = [
path('', views.assignments, name = "assignments"),
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
# Create your views here.
def assignments(request):
homeworks = Assignment.objects.all()
display = 'Widget\'s Assignments Page<br><br>'
for homework in homeworks:
assignment_name = homework.name
assignment_description = homework.description
assignment_perfect_score = homework.perfect_score
assignment_passing_score = homework.passing_score
course_code = homework.course.code
course_title = homework.course.title
course_section = homework.course.section
def Assignments(request):
assignments = Assignment.objects.all()
context = {
'assignments': assignments,
}
return render(request, 'assignments/assignments.html', context)
display += 'Assignment Name: ' + assignment_name + '<br>'
display += 'Description: ' + assignment_description + '<br>'
display += 'Perfect Score: ' + str(assignment_perfect_score) + '<br>'
display += 'Passing Score: ' + str(assignment_passing_score) + '<br>'
display += 'Course/Section: ' + course_code + ' ' + course_title + '-' + course_section + '<br><br>'
return HttpResponse(display)
\ No newline at end of file
class AssignmentDetailView(DetailView):
model = Assignment
template_name = 'assignments/assignment-details.html'
class AssignmentCreateView(CreateView):
model = Assignment
fields = '__all__'
template_name = 'assignments/assignment-add.html'
class AssignmentUpdateView(UpdateView):
model = Assignment
fields = '__all__'
template_name = 'assignments/assignment-edit.html'
\ No newline at end of file
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