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.db import models
from django.urls import reverse
# Create your models here. # Create your models here.
class Course(models.Model): class Course(models.Model):
...@@ -21,3 +22,6 @@ class Assignment(models.Model): ...@@ -21,3 +22,6 @@ class Assignment(models.Model):
def __str__(self): def __str__(self):
return self.name 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 django.urls import path
from . import views from . import views
from .views import *
urlpatterns = [ 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 django.http import HttpResponse
from .models import Assignment, Course 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):
def assignments(request): assignments = Assignment.objects.all()
homeworks = Assignment.objects.all() context = {
display = 'Widget\'s Assignments Page<br><br>' 'assignments': assignments,
for homework in homeworks: }
assignment_name = homework.name return render(request, 'assignments/assignments.html', context)
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
display += 'Assignment Name: ' + assignment_name + '<br>' class AssignmentDetailView(DetailView):
display += 'Description: ' + assignment_description + '<br>' model = Assignment
display += 'Perfect Score: ' + str(assignment_perfect_score) + '<br>' template_name = 'assignments/assignment-details.html'
display += 'Passing Score: ' + str(assignment_passing_score) + '<br>'
display += 'Course/Section: ' + course_code + ' ' + course_title + '-' + course_section + '<br><br>' class AssignmentCreateView(CreateView):
return HttpResponse(display) model = Assignment
\ No newline at end of file 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