Commit 1078dc81 authored by Gabriel Geraldo's avatar Gabriel Geraldo

Merge branch 'assignmentsv2'

parents 50c5d084 aeb3a963
from django.db import models from django.db import models
from django.urls import reverse
class Course(models.Model): class Course(models.Model):
...@@ -7,7 +8,7 @@ class Course(models.Model): ...@@ -7,7 +8,7 @@ class Course(models.Model):
section = models.CharField(max_length=3) section = models.CharField(max_length=3)
def __str__(self): def __str__(self):
return '{}'.format(self.code) return '{} - {}'.format(self.code, self.section)
class Assignment(models.Model): class Assignment(models.Model):
...@@ -21,3 +22,6 @@ class Assignment(models.Model): ...@@ -21,3 +22,6 @@ class Assignment(models.Model):
def passing_score(self): def passing_score(self):
return (self.perfect_score * 60)//100 return (self.perfect_score * 60)//100
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 Assignment:</h1>
<form method="post">
{% csrf_token %}
{{form.as_p}}
<input type="submit" value="Save New Assignment">
</form>
<br>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %} {{ object.name }} {% endblock %}
{% block content %}
<div style="text-transform:uppercase;">
<h1>{{ object.name }}</h1>
</div>
<h2>
{{ object.course.code }} {{ object.course.title }}-{{ object.course.section }}
</h2>
<div>
Description: {{ object.description }}<br>
Perfect Score: {{ object.perfect_score }}<br>
Passing Score: {{ object.passing_score }}<br>
</div>
<br>
<a href="edit">
<button type="button"><p>Edit Assignment</p></button>
</a>
{% endblock %}
{% 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>
<br>
{% endblock %}
{% extends 'base.html' %}
{% load static %}
{% block title %}Widget's Assignments{% endblock %}
{% block content %}
<i><h1>Welcome to Widget's Assignments!</h1></i>
{% for assignments in assignments %}
<p><strong>
<a href="{{ assignments.get_absolute_url }}">
<li>
{{ assignments.name }}
</li>
</a>
</strong></p>
{% endfor %}
<br><br>
<a href="add">
<button type="button"><p>New Assignment</p></button>
</a>
<br><br><br>
{# the links to other html files #}
<div class = links>
<a href="../dashboard/">Dashboard</a><br>
<a href="../announcements/">Announcements</a><br>
<a href="../forum/">Forum</a><br>
<a href="../calendar/">Calendar</a><br>
</div>
{% endblock %}
from django.urls import path from django.urls import path
from .views import index from .views import *
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('', index, name='index'),
path('<int:pk>/details', AssignmentsDetailView.as_view(), name='assignment-details'),
path('<int:pk>/edit', AssignmentsUpdateView.as_view(), name='assignment-edit'),
path('add', AssignmentsCreateView.as_view(), name='assignment-add'),
] ]
# This might be needed, depending on your Django version # This might be needed, depending on your Django version
app_name = "assignments" app_name = "assignments"
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from django.views.generic import ListView, DetailView, CreateView, UpdateView
from .models import Assignment, Course from .models import Assignment, Course
def index(request): def index(request):
assignments = Assignment.objects.all()
args = {'assignments':assignments}
return render(request, 'assignments/assignments.html', args)
return_string = '<body>' class AssignmentsView(ListView):
for assignment in Assignment.objects.all(): model = Assignment
template_name = 'assignments/assignments.html'
assignment_details = 'Assignment Name: {}<br>Description: {}<br>Perfect Score: {}<br> Passing Score: {}<br>Course/Section: {} {}-{}<br>'.format( class AssignmentsDetailView(DetailView):
assignment.name, model = Assignment
assignment.description, template_name = 'assignments/assignment-details.html'
assignment.perfect_score,
assignment.passing_score(),
assignment.course.code,
assignment.course.title,
assignment.course.section
)
return_string += assignment_details + '<br>' class AssignmentsUpdateView(UpdateView):
model = Assignment
fields = "__all__"
template_name = 'assignments/assignment-edit.html'
html_string = '<html>{}</html>'.format(return_string) class AssignmentsCreateView(CreateView):
model = Assignment
return HttpResponse('Widget\'s Assignments Page<br><br>' + html_string) fields = "__all__"
template_name = 'assignments/assignment-add.html'
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