Commit f382bad6 authored by Rafa Mendoza's avatar Rafa Mendoza

implementing specs

parent 3e0eca39
......@@ -6,9 +6,9 @@ from .models import Assignment, Course
class AssignmentAdmin(admin.ModelAdmin):
model = Assignment
list_display = ('assignment_name', 'description', 'course', 'perfect_score',)
search_fields = ('assignment_name', 'description', 'course', 'perfect_score',)
list_filter = ('assignment_name', 'description', 'course', 'perfect_score',)
list_display = ('name', 'description', 'course', 'perfect_score',)
search_fields = ('name', 'description', 'course', 'perfect_score',)
list_filter = ('name', 'description', 'course', 'perfect_score',)
class CourseAdmin(admin.ModelAdmin):
......
from django.db import models
from django.urls import reverse
class Course(models.Model):
code = models.CharField(max_length=10)
......@@ -14,15 +16,21 @@ class Course(models.Model):
class Assignment(models.Model):
assignment_name = models.CharField(max_length=50)
name = models.CharField(max_length=50)
description = models.TextField()
course = models.ForeignKey(Course, on_delete=models.CASCADE)
perfect_score = models.IntegerField()
def __str__(self):
return '''{}, {}, {}, {}'''.format(
self.assignment_name,
return'''{}, {}, {}, {}'''.format(
self.name,
self.description,
self.course,
self.perfect_score,
)
def passing_score(self):
return round(self.perfect_score * 0.6)
def get_absolute_url(self):
return reverse('assignments:assignment-details', kwargs={'pk': self.pk})
{% extends 'base.html' %}
{% block title %} Add Assignment {% endblock %}
{% block heading %} Add a new assignment: {% endblock %}
{% block content %}
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="SUBMIT" value="Save New Assignment">
</form>
{% endblock %}
{% 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 %}
{% extends 'base.html' %}
{% block title %} Edit Assignment {% endblock %}
{% block heading %} Edit Assignment: {% endblock %}
{% block content %}
<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 heading %} Welcome to Widget's Assignments! {% endblock %}
{% block content %}
<div class="main">
<div class="list">
<ul>
{% for assignment in assignments %}
<a href="{{ assignment.get_absolute_url }}">
<li>{{assignment.name}}</li>
</a>
{% endfor %}
</ul>
</div>
<a href="{% url 'assignments:assignment-add' %}" class="add-btn"><i class="fa fa-plus"></i> New Assignment</a>
</div>
{% endblock %}
{% block footing %}
<div class="links">
<a href="/dashboard/" class="btn-primary">Dashboard -- </a>
<a href="/announcements/" class="btn-primary"> Announcements -- </a>
<a href="/forum/" class="btn-primary"> Forum -- </a>
<a href="/widget_calendar/" class="btn-primary"> Calendar </a>
</div>
{% endblock %}
from django.urls import path
from .views import index
from .views import Assignments, AssignmentDetailView, AssignmentAddView, AssignmentEditView
urlpatterns = [
path('', index, name= 'index'),
path('', Assignments, name="assignments"),
path('<int:pk>/details/', AssignmentDetailView.as_view(), name='assignment-details'),
path('add/', AssignmentAddView.as_view(), name='assignment-add'),
path('<int:pk>/edit/', AssignmentEditView.as_view(), name='assignment-edit'),
]
app_name = "assignments"
\ No newline at end of file
app_name = 'assignments'
from django.http import HttpResponse
from django.shortcuts import render
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView
from django.views.generic.edit import UpdateView
from .models import Assignment
def index(request):
return_string = "<p>Widget's Assignment Page</p>"
for a in Assignment.objects.all():
return_string += '''Assignment Name: {} <br>Description: {}
<br>Perfect Score: {} <br>Passing Score: {}
<br>Course/Section: {} {}-{}<br><br>'''.format(
a.assignment_name,
a.description,
a.perfect_score,
int(a.perfect_score * 0.60),
a.course.code,
a.course.title,
a.course.section,
)
html_string = '<html><body>{}</body></html>'.format(return_string)
return HttpResponse(html_string)
def Assignments(request):
assignments = Assignment.objects.all()
dict_assignments = {
'assignments': assignments,
}
return render(request, 'assignments/assignments.html', dict_assignments)
class AssignmentDetailView(DetailView):
model = Assignment
template_name = 'assignments/assignment-details.html'
class AssignmentAddView(CreateView):
model = Assignment
fields = '__all__'
template_name = 'assignments/assignment-add.html'
class AssignmentEditView(UpdateView):
model = Assignment
fields = '__all__'
template_name = 'assignments/assignment-edit.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